comfy-pr 0.2.24 → 0.2.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/README.md +247 -225
  2. package/index.ts +6 -0
  3. package/next-env.d.ts +5 -5
  4. package/package.json +52 -25
  5. package/src/Authors.ts +42 -48
  6. package/src/CMNodes.ts +60 -60
  7. package/src/CNRepos.ts +78 -74
  8. package/src/CRNodes.ts +27 -27
  9. package/src/CRPulls.ts +4 -4
  10. package/src/EmailTasks.ts +101 -0
  11. package/src/FORK_OWNER.ts +5 -5
  12. package/src/FORK_PREFIX.ts +5 -5
  13. package/src/FollowRules.ts +25 -25
  14. package/src/GIT_USEREMAIL.ts +5 -5
  15. package/src/GIT_USERNAME.ts +9 -9
  16. package/src/GithubIssueComments.ts +3 -3
  17. package/src/PushedBranch.ts +3 -3
  18. package/src/Totals.ts +24 -9
  19. package/src/TrackingPRs.ts +12 -12
  20. package/src/WorkerInstances.ts +89 -89
  21. package/src/addCommentAction.ts +73 -65
  22. package/src/analyzePullsStatus.ts +219 -170
  23. package/src/analyzeTotals.test.ts +5 -5
  24. package/src/analyzeTotals.ts +118 -118
  25. package/src/bypassRepos.spec.ts +10 -0
  26. package/src/bypassRepos.ts +8 -0
  27. package/src/checkComfyActivated.ts +39 -39
  28. package/src/checkPRsFailures.ts +18 -0
  29. package/src/cli.ts +40 -40
  30. package/src/clone_modify_push_Branches.ts +21 -21
  31. package/src/createComfyRegistryPRsFromCandidates.ts +55 -55
  32. package/src/createComfyRegistryPullRequests.ts +32 -22
  33. package/src/createGithubForkForRepo.ts +54 -37
  34. package/src/createGithubPullRequest.ts +157 -94
  35. package/src/createIssueComment.ts +34 -29
  36. package/src/fetchCMNodes.ts +22 -22
  37. package/src/fetchComfyRegistryNodes.ts +11 -11
  38. package/src/fetchCurrentGeoInfo.ts +6 -6
  39. package/src/fetchRelatedPullWithComments.ts +15 -15
  40. package/src/fetchRepoDescriptionMap.ts +15 -15
  41. package/src/followRuleSchema.ts +79 -76
  42. package/src/getActivatedShell.ts +18 -18
  43. package/src/getBranchWorkingDir.ts +16 -16
  44. package/src/getRepoWorkingDir.ts +5 -5
  45. package/src/ghUser.ts +9 -6
  46. package/src/index.ts +26 -22
  47. package/src/initializeFollowRules.ts +26 -26
  48. package/src/makePublishBranch.ts +58 -58
  49. package/src/makeTomlBranch.ts +53 -53
  50. package/src/makeUpdateTomlLicenseBranch.ts +245 -0
  51. package/src/matchRelatedPulls.ts +47 -60
  52. package/src/muteInstances.ts +16 -16
  53. package/src/parseIssueUrl.ts +6 -6
  54. package/src/parseOwnerRepo.ts +33 -33
  55. package/src/parsePullUrl.ts +6 -6
  56. package/src/parsePullsState.ts +6 -6
  57. package/src/parseTitleBodyOfMarkdown.ts +8 -8
  58. package/src/postSlackMessage.ts +21 -21
  59. package/src/preload.ts +30 -30
  60. package/src/pullStatusFollowSchema.ts +12 -12
  61. package/src/readTemplateTitle.ts +11 -11
  62. package/src/sendEmailAction.ts +56 -0
  63. package/src/sendGmail.ts +105 -0
  64. package/src/showFollowRuleSet.ts +12 -12
  65. package/src/summaryLastPullComment.ts +8 -8
  66. package/src/tomlFillDescription.ts +17 -17
  67. package/src/updateAuthors.ts +7 -7
  68. package/src/updateAuthorsForGithub.ts +54 -50
  69. package/src/updateAuthorsFromCNRepo.ts +30 -30
  70. package/src/updateCMNodesDuplicationWarnings.ts +56 -56
  71. package/src/updateCMRepos.ts +27 -27
  72. package/src/updateCNRepos.ts +58 -58
  73. package/src/updateCNReposCRPullsComments.ts +40 -40
  74. package/src/updateCNReposInfo.ts +58 -57
  75. package/src/updateCNReposPRCandidate.ts +85 -85
  76. package/src/updateCNReposPulls.ts +31 -28
  77. package/src/updateCNReposPullsDashboard.ts +49 -49
  78. package/src/updateCNReposRelatedPulls.ts +25 -25
  79. package/src/updateCRNodes.ts +50 -50
  80. package/src/updateCRRepos.ts +26 -26
  81. package/src/updateComfyTotals.ts +43 -43
  82. package/src/updateFollowRuleSet.ts +136 -127
  83. package/src/updateOutdatedPullsTemplates.ts +165 -160
  84. package/src/updateSlackMessages.ts +43 -43
  85. package/tailwind.config.ts +75 -20
@@ -1,94 +1,157 @@
1
- import DIE from "@snomiao/die";
2
- import yaml from "yaml";
3
- import { gh } from "./gh";
4
- import type { GithubPull } from "./gh/GithubPull";
5
- import { parseUrlRepoOwner } from "./parseOwnerRepo";
6
-
7
- export async function createGithubPullRequest({
8
- title,
9
- body,
10
- branch,
11
- srcUrl,
12
- dstUrl,
13
- }: {
14
- title: string;
15
- body: string;
16
- branch: string;
17
- srcUrl: string;
18
- dstUrl: string;
19
- }) {
20
- const dst = parseUrlRepoOwner(dstUrl);
21
- const src = parseUrlRepoOwner(srcUrl);
22
- const repo = (await gh.repos.get({ ...dst })).data;
23
-
24
- // TODO: seems has bugs on head_repo
25
- const existedList = (
26
- await gh.pulls.list({
27
- // source repo
28
- state: "all",
29
- head_repo: src.owner + "/" + src.repo,
30
- head: src.owner + ":" + branch,
31
- // pr will merge into
32
- owner: dst.owner,
33
- repo: dst.repo,
34
- base: repo.default_branch,
35
- })
36
- ).data;
37
- if (existedList.length) {
38
- const msg = {
39
- PR_Existed: existedList.map((e) => ({ url: e.html_url, title: e.title })),
40
- };
41
- console.log(yaml.stringify(msg));
42
- return existedList[0];
43
- }
44
- if (!process.env.GH_TOKEN_COMFY_PR) {
45
- DIE("Missing env.GH_TOKEN_COMFY_PR");
46
- }
47
- const pr_result = await gh.pulls
48
- .create({
49
- // pr info
50
- title,
51
- body,
52
- // source repo
53
- head_repo: src.owner + "/" + src.repo,
54
- head: src.owner + ":" + branch,
55
- // pr will merge into
56
- owner: dst.owner,
57
- repo: dst.repo,
58
- base: repo.default_branch,
59
- maintainer_can_modify: true,
60
- // draft: true,
61
- })
62
- .then((e) => e.data)
63
- .catch(async (e) => {
64
- if (e.message.match("A pull request already exists for")) {
65
- console.log("PR Existed ", e);
66
- // WARN: will search all prs
67
- const existedList = (
68
- await gh.pulls.list({
69
- // source repo
70
- state: "open",
71
- head_repo: src.owner + "/" + src.repo,
72
- // head: src.owner + ":" + branch,
73
- // pr will merge into
74
- owner: dst.owner,
75
- repo: dst.repo,
76
- base: repo.default_branch,
77
- })
78
- ).data;
79
- if (existedList.length) {
80
- const msg = {
81
- PR_Existed: existedList.map((e) => ({
82
- url: e.html_url,
83
- title: e.title,
84
- })),
85
- };
86
- console.log(yaml.stringify(msg));
87
- return existedList[0];
88
- }
89
- }
90
- throw e;
91
- });
92
- console.log("PR OK", pr_result.html_url);
93
- return pr_result as GithubPull;
94
- }
1
+ import DIE, { catchArgs } from "@snomiao/die";
2
+ import "git-diff";
3
+ import { Octokit } from "octokit";
4
+ import { pickAll } from "rambda";
5
+ import sflow from "sflow";
6
+ import { isRepoBypassed } from "./bypassRepos";
7
+ import { gh } from "./gh";
8
+ import type { GithubPull } from "./gh/GithubPull";
9
+ import { parseUrlRepoOwner } from "./parseOwnerRepo";
10
+ if (import.meta.main) {
11
+ const srcUrl = "https://github.com/ComfyNodePRs/PR-ComfyUI-DareMerge-7bcbf6a9";
12
+ const dstUrl = "https://github.com/54rt1n/ComfyUI-DareMerge";
13
+ const src = parseUrlRepoOwner(srcUrl);
14
+ const dst = parseUrlRepoOwner(dstUrl);
15
+ const branch = "licence-update";
16
+ const repo = (await gh.repos.get({ ...dst })).data;
17
+ const head_repo = `${src.owner}/${src.repo}`;
18
+ // const head = `${src.owner}:${branch}`;
19
+ const head = `${src.owner}:licence-update`;
20
+ console.log("headrepo " + head_repo);
21
+ console.log("head " + head);
22
+ await sflow(
23
+ (
24
+ await gh.pulls.list({
25
+ // source repo
26
+ state: "all",
27
+ // head_repo: head_repo,
28
+
29
+ head: head,
30
+ // pr will merge into
31
+ owner: dst.owner,
32
+ repo: dst.repo,
33
+ base: repo.default_branch,
34
+ })
35
+ ).data,
36
+ )
37
+ // .filter(e => head === e.head.label )
38
+ .map((e) => ({
39
+ url: e.html_url,
40
+ hEAD: head.trim() === e.head.label.trim(),
41
+ heaD: head,
42
+ head: e.head.label,
43
+ head_repo: e.head.repo.full_name,
44
+ }))
45
+ .toLog();
46
+ console.log("all done");
47
+ }
48
+ export async function createGithubPullRequest({
49
+ title,
50
+ body,
51
+ branch,
52
+ srcUrl,
53
+ dstUrl,
54
+ updateIfNotMatched = true,
55
+ }: {
56
+ title: string;
57
+ body: string;
58
+ branch: string;
59
+ srcUrl: string; // forked branch
60
+ dstUrl: string; // upstream
61
+ updateIfNotMatched?: boolean;
62
+ }) {
63
+ if (isRepoBypassed(dstUrl)) DIE("dst repo is requested to be bypassed");
64
+
65
+ const dst = parseUrlRepoOwner(dstUrl);
66
+ const src = parseUrlRepoOwner(srcUrl);
67
+ const repo = (await gh.repos.get({ ...dst })).data;
68
+
69
+ // TODO: seems has bugs on head_repo
70
+ const existedList = (
71
+ await gh.pulls.list({
72
+ // source repo
73
+ state: "all",
74
+ head_repo: `${src.owner}/${src.repo}`,
75
+ head: `${src.owner}:${branch}`,
76
+ // pr will merge into
77
+ owner: dst.owner,
78
+ repo: dst.repo,
79
+ base: repo.default_branch,
80
+ })
81
+ ).data;
82
+ if (existedList.length > 1)
83
+ DIE(
84
+ new Error(`expect only 1 pr, but got ${existedList.length}`, {
85
+ cause: { existed: existedList.map((e) => ({ url: e.html_url, title: e.title })) },
86
+ }),
87
+ );
88
+
89
+ const pr_result =
90
+ existedList[0] ??
91
+ (await ghPR()
92
+ .pulls.create({
93
+ // pr info
94
+ title,
95
+ body,
96
+ // source repo
97
+ head_repo: src.owner + "/" + src.repo,
98
+ head: src.owner + ":" + branch,
99
+ // pr will merge into
100
+ owner: dst.owner,
101
+ repo: dst.repo,
102
+ base: repo.default_branch,
103
+ maintainer_can_modify: true,
104
+ // draft: true,
105
+ })
106
+ .then((e) => e.data)
107
+
108
+ // handle existed error
109
+ .catch(async (e) => {
110
+ if (!e.message.match("A pull request already exists for")) throw e;
111
+ console.error("PR Existed\n", e);
112
+ // WARN: will search all prs
113
+ const existedList = (
114
+ await gh.pulls.list({
115
+ // source repo
116
+ state: "open",
117
+ head_repo: `${src.owner}/${src.repo}`,
118
+ head: `${src.owner}:${branch}`,
119
+ // pr will merge into
120
+ owner: dst.owner,
121
+ repo: dst.repo,
122
+ base: repo.default_branch,
123
+ })
124
+ ).data; // .filter(existed => existed.title === title);
125
+
126
+ if (existedList.length !== 1)
127
+ DIE(
128
+ new Error("expect only 1 pr, but got " + existedList.length, {
129
+ cause: { existed: existedList.map((e) => ({ url: e.html_url, title: e.title })) },
130
+ }),
131
+ );
132
+
133
+ return existedList[0];
134
+ }));
135
+
136
+ console.log("PR OK", pr_result.html_url);
137
+ const mismatch = pr_result.title !== title || pr_result.body !== body;
138
+ if (mismatch) {
139
+ if (!updateIfNotMatched)
140
+ DIE(
141
+ new Error("pr content mismatch", {
142
+ cause: { mismatch, expected: { title, body }, actual: pickAll(["title", "body"], pr_result) },
143
+ }),
144
+ );
145
+ const { owner, repo } = parseUrlRepoOwner(dstUrl); // upstream repo
146
+ const updated = (await catchArgs(ghPR().pulls.update)({ pull_number: pr_result.number, body, title, owner, repo }))
147
+ .data!;
148
+ const updatedPRStillMismatch = updated.title !== title || updated.body !== body;
149
+ if (updatedPRStillMismatch) DIE(new Error("updatedPRStillMismatch", { cause: arguments }));
150
+ console.warn(`PR content updated ${owner}/${repo} / \n<< ${pr_result.title}\n>> ${updated.title}`);
151
+ }
152
+ return pr_result as GithubPull;
153
+ }
154
+
155
+ function ghPR() {
156
+ return new Octokit({ auth: process.env.GH_TOKEN_COMFY_PR || DIE(new Error("Missing env.GH_TOKEN_COMFY_PR")) }).rest;
157
+ }
@@ -1,29 +1,34 @@
1
- import DIE from "@snomiao/die";
2
- import { gh } from "./gh";
3
- import { ghUser } from "./ghUser";
4
- import { parseIssueUrl } from "./parseIssueUrl";
5
-
6
- if (import.meta.main) {
7
- const url = "https://github.com/snomiao/ComfyNode-Registry-test/pull/1";
8
- const body = "Hello World @snomiao";
9
- const result = await createIssueComment(url, body, ghUser.login);
10
- console.log(result.comment.html_url);
11
- console.log(result.comments.map((e) => e.html_url));
12
- }
13
-
14
- export async function createIssueComment(issueUrl: string, body: string, by: string) {
15
- const comments = (
16
- await gh.issues.listComments({
17
- ...parseIssueUrl(issueUrl),
18
- })
19
- ).data;
20
- const result = await (async function () {
21
- const commentExisted = comments.find((e) => e.body === body);
22
- if (commentExisted) return { comment: commentExisted, comments };
23
- if (by !== ghUser.login) DIE("Fails to creating issue: user not match");
24
- const comment = (await gh.issues.createComment({ ...parseIssueUrl(issueUrl), body })).data;
25
- console.log("comment created: " + comment.html_url);
26
- return { comment, comments: [...comments, comment] };
27
- })();
28
- return result;
29
- }
1
+ import DIE from "@snomiao/die";
2
+ import { gh } from "./gh";
3
+ import { ghUser } from "./ghUser";
4
+ import { parseIssueUrl } from "./parseIssueUrl";
5
+
6
+ if (import.meta.main) {
7
+ // const url = "https://github.com/snomiao/ComfyNode-Registry-test/pull/1";
8
+ // const body = "Hello World @snomiao";
9
+ // const result = await createIssueComment(url, body, ghUser.login);
10
+ // console.log(result.comment.html_url);
11
+ // console.log(result.comments.map((e) => e.html_url));
12
+ const url = "https://github.com/snomiao/ComfyNode-Registry-test/pull/28";
13
+ const body = "Hello World @robinjhuang";
14
+ const result = await createIssueComment(url, body, ghUser.login);
15
+ console.log(result.comment.html_url);
16
+ console.log(result.comments.map((e) => e.html_url));
17
+ }
18
+
19
+ export async function createIssueComment(issueUrl: string, body: string, by: string) {
20
+ const comments = (
21
+ await gh.issues.listComments({
22
+ ...parseIssueUrl(issueUrl),
23
+ })
24
+ ).data;
25
+ const result = await (async function () {
26
+ const commentExisted = comments.find((e) => e.body === body);
27
+ if (commentExisted) return { comment: commentExisted, comments };
28
+ if (by !== ghUser.login) DIE("Fails to creating issue: user not match");
29
+ const comment = (await gh.issues.createComment({ ...parseIssueUrl(issueUrl), body })).data;
30
+ console.log("+ IssueComment " + comment.html_url);
31
+ return { comment, comments: [...comments, comment] };
32
+ })();
33
+ return result;
34
+ }
@@ -1,22 +1,22 @@
1
- import { fetchJson } from "./utils/fetchJson";
2
-
3
- if (import.meta.main) {
4
- console.log(await fetchCMNodes());
5
- }
6
- export async function fetchCMNodes() {
7
- const customNodeListSource =
8
- process.env.CUSTOM_LIST_SOURCE ||
9
- "https://raw.githubusercontent.com/ltdrdata/ComfyUI-Manager/main/custom-node-list.json";
10
- const nodeList = (await fetchJson(customNodeListSource)) as {
11
- custom_nodes: {
12
- author: "Dr.Lt.Data" | string;
13
- title: "ComfyUI-Manager" | string;
14
- id: "manager" | string;
15
- reference: "https://github.com/ltdrdata/ComfyUI-Manager" | string;
16
- files: ["https://github.com/ltdrdata/ComfyUI-Manager"] | string[];
17
- install_type: "git-clone" | string;
18
- description: "ComfyUI-Manager itself is also a custom node." | string;
19
- }[];
20
- };
21
- return nodeList.custom_nodes;
22
- }
1
+ import { fetchJson } from "./utils/fetchJson";
2
+
3
+ if (import.meta.main) {
4
+ console.log(await fetchCMNodes());
5
+ }
6
+ export async function fetchCMNodes() {
7
+ const customNodeListSource =
8
+ process.env.CUSTOM_LIST_SOURCE ||
9
+ "https://raw.githubusercontent.com/ltdrdata/ComfyUI-Manager/main/custom-node-list.json";
10
+ const nodeList = (await fetchJson(customNodeListSource)) as {
11
+ custom_nodes: {
12
+ author: "Dr.Lt.Data" | string;
13
+ title: "ComfyUI-Manager" | string;
14
+ id: "manager" | string;
15
+ reference: "https://github.com/ltdrdata/ComfyUI-Manager" | string;
16
+ files: ["https://github.com/ltdrdata/ComfyUI-Manager"] | string[];
17
+ install_type: "git-clone" | string;
18
+ description: "ComfyUI-Manager itself is also a custom node." | string;
19
+ }[];
20
+ };
21
+ return nodeList.custom_nodes;
22
+ }
@@ -1,11 +1,11 @@
1
- import type { mockPublishedNodes } from "../mocks/mockPublishedNodes";
2
- import DIE from "@snomiao/die";
3
- import { fetchJson } from "./utils/fetchJson";
4
-
5
- export async function fetchCRNodes() {
6
- const r = (await fetchJson<typeof mockPublishedNodes>(
7
- "https://api.comfy.org/nodes?page=1&limit=99999999"
8
- )) as typeof mockPublishedNodes;
9
- r.totalPages === 1 || DIE("FAIL TO FETCH ALL NODES");
10
- return r.nodes;
11
- }
1
+ import type { mockPublishedNodes } from "../mocks/mockPublishedNodes";
2
+ import DIE from "@snomiao/die";
3
+ import { fetchJson } from "./utils/fetchJson";
4
+
5
+ export async function fetchCRNodes() {
6
+ const r = (await fetchJson<typeof mockPublishedNodes>(
7
+ "https://api.comfy.org/nodes?page=1&limit=99999999"
8
+ )) as typeof mockPublishedNodes;
9
+ r.totalPages === 1 || DIE("FAIL TO FETCH ALL NODES");
10
+ return r.nodes;
11
+ }
@@ -1,6 +1,6 @@
1
- import { fetchJson } from "./utils/fetchJson";
2
- export async function fetchCurrentGeoInfo() {
3
- const { query, city, iat, lon, countryCode, region, regionName } = (await fetchJson("http://ip-api.com/json")) as any;
4
- const geo = { ip: query, city, iat, lon, countryCode, region, regionName };
5
- return geo;
6
- }
1
+ import { fetchJson } from "./utils/fetchJson";
2
+ export async function fetchCurrentGeoInfo() {
3
+ const { query, city, iat, lon, countryCode, region, regionName } = (await fetchJson("http://ip-api.com/json")) as any;
4
+ const geo = { ip: query, city, iat, lon, countryCode, region, regionName };
5
+ return geo;
6
+ }
@@ -1,15 +1,15 @@
1
- import pMap from "p-map";
2
- import { fetchIssueComments } from "./gh/fetchIssueComments";
3
- import { matchRelatedPulls } from "./matchRelatedPulls";
4
- import type { GithubPullParsed } from "./parsePullsState";
5
- import { summaryLastPullComment } from "./summaryLastPullComment";
6
- /** @deprecated */
7
- export async function fetchRelatedPullWithComments(repository: string, pulls: GithubPullParsed[]) {
8
- const relatedPulls = await matchRelatedPulls(pulls);
9
- const relatedPullsWithComment = await pMap(relatedPulls, async (data) => {
10
- const comments = await fetchIssueComments(repository, data.pull);
11
- const lastText = summaryLastPullComment(comments);
12
- return { ...data, comments, lastText };
13
- });
14
- return relatedPullsWithComment;
15
- }
1
+ import pMap from "p-map";
2
+ import { fetchIssueComments } from "./gh/fetchIssueComments";
3
+ import { matchRelatedPulls } from "./matchRelatedPulls";
4
+ import type { GithubPullParsed } from "./parsePullsState";
5
+ import { summaryLastPullComment } from "./summaryLastPullComment";
6
+ /** @deprecated */
7
+ export async function fetchRelatedPullWithComments(repository: string, pulls: GithubPullParsed[]) {
8
+ const relatedPulls = await matchRelatedPulls(pulls);
9
+ const relatedPullsWithComment = await pMap(relatedPulls, async (data) => {
10
+ const comments = await fetchIssueComments(repository, data.pull);
11
+ const lastText = summaryLastPullComment(comments);
12
+ return { ...data, comments, lastText };
13
+ });
14
+ return relatedPullsWithComment;
15
+ }
@@ -1,15 +1,15 @@
1
- import { fromPairs } from "rambda";
2
- import { fetchCMNodes } from "./fetchCMNodes";
3
-
4
-
5
- export async function fetchRepoDescriptionMap() {
6
- const nodeList = await fetchCMNodes();
7
- const repoDescriptionMap = fromPairs(
8
- nodeList.map((e) => [e.reference, e.description])
9
- );
10
- repoDescriptionMap["https://github.com/snomiao/ComfyNode-Registry-test"] =
11
- "ComfyNode-Registry-test-description";
12
-
13
- console.log("Fetched " + nodeList.length + " CustomNode descriptions");
14
- return repoDescriptionMap;
15
- }
1
+ import { fromPairs } from "rambda";
2
+ import { fetchCMNodes } from "./fetchCMNodes";
3
+
4
+
5
+ export async function fetchRepoDescriptionMap() {
6
+ const nodeList = await fetchCMNodes();
7
+ const repoDescriptionMap = fromPairs(
8
+ nodeList.map((e) => [e.reference, e.description])
9
+ );
10
+ repoDescriptionMap["https://github.com/snomiao/ComfyNode-Registry-test"] =
11
+ "ComfyNode-Registry-test-description";
12
+
13
+ console.log("Fetched " + nodeList.length + " CustomNode descriptions");
14
+ return repoDescriptionMap;
15
+ }
@@ -1,76 +1,79 @@
1
- import { $before, $fresh, $stale } from "@/packages/mongodb-pipeline-ts/$fresh";
2
- import { tryCatch } from "rambda";
3
- import { z } from "zod";
4
-
5
- const znot_include = z.object({ "not-include": z.string() }).transform((x) => ({ $nin: x["not-include"] }));
6
- const mString = z.string().transform((x) =>
7
- tryCatch<string, string | RegExp>(
8
- (x) => new RegExp(x) as RegExp,
9
- (x) => x as string | RegExp,
10
- )(x),
11
- );
12
- const zbefore = z
13
- .object({ $before: z.coerce.date().or(z.string()).or(z.number()) })
14
- .transform((x) => $before(x.$before));
15
- const zfresh = z.object({ $fresh: z.coerce.date().or(z.string()).or(z.number()) }).transform((x) => $fresh(x.$fresh));
16
- const mstale = z.object({ $stale: z.coerce.date().or(z.string()).or(z.number()) }).transform((x) => $stale(x.$stale));
17
- const mDate = z.date().or(zbefore).or(zfresh).or(mstale);
18
- const mAny = z.number().or(znot_include).or(mString).or(zbefore).or(zfresh);
19
- const mNumber = z
20
- .number()
21
- .or(z.object({ $gt: z.number() }))
22
- .or(z.object({ $lt: z.number() }))
23
- .or(z.object({ $eq: z.number() }))
24
- .or(z.object({ $ne: z.number() }))
25
- .or(z.object({ $gte: z.number() }))
26
- .or(z.object({ $lte: z.number() }));
27
- export const zAddCommentAction = z
28
- .object({
29
- by: z.string(),
30
- body: z.string(),
31
- })
32
- .strict();
33
- const zFollowUpRule = z.object({
34
- name: z.string(),
35
- $match: z
36
- .object({
37
- actived_at: mDate,
38
- email: mString,
39
- comments: mNumber,
40
- created_at: mDate,
41
- comments_author: mString,
42
- head: mString,
43
- lastwords: mString,
44
- on_registry: z.boolean(),
45
- nickName: mString,
46
- ownername: mString,
47
- state: z.enum(["OPEN", "CLOSED", "MERGED"]),
48
- updated_at: mDate,
49
- url: mString,
50
- })
51
- .strict()
52
- .partial(),
53
- action: z
54
- .object({
55
- "add-comment": zAddCommentAction,
56
- "send-email": z
57
- .object({
58
- provider: z.string(),
59
- from: z.string(),
60
- to: z.string(),
61
- subject: z.string(),
62
- body: z.string(),
63
- })
64
- .strict(), // WARN: not implementd
65
- "update-issue": z
66
- .object({
67
- tags: mAny,
68
- })
69
- .strict(),
70
- // close: z.any(),
71
- })
72
- .strict()
73
- .partial(),
74
- });
75
- // zPullsStatus
76
- export const zFollowUpRules = zFollowUpRule.array();
1
+ import { $before, $fresh, $stale } from "@/packages/mongodb-pipeline-ts/$fresh";
2
+ import { tryCatch } from "rambda";
3
+ import { z } from "zod";
4
+
5
+ const znot_include = z.object({ "not-include": z.string() }).transform((x) => ({ $nin: x["not-include"] }));
6
+ const mString = z.string().transform((x) =>
7
+ tryCatch<string, string | RegExp>(
8
+ (x) => new RegExp(x) as RegExp,
9
+ (x) => x as string | RegExp,
10
+ )(x),
11
+ );
12
+ const zbefore = z
13
+ .object({ $before: z.coerce.date().or(z.string()).or(z.number()) })
14
+ .transform((x) => $before(x.$before));
15
+ const zfresh = z.object({ $fresh: z.coerce.date().or(z.string()).or(z.number()) }).transform((x) => $fresh(x.$fresh));
16
+ const mstale = z.object({ $stale: z.coerce.date().or(z.string()).or(z.number()) }).transform((x) => $stale(x.$stale));
17
+ const mDate = z.date().or(zbefore).or(zfresh).or(mstale);
18
+ const mAny = z.number().or(znot_include).or(mString).or(zbefore).or(zfresh);
19
+ const mNumber = z
20
+ .number()
21
+ .or(z.object({ $gt: z.number() }))
22
+ .or(z.object({ $lt: z.number() }))
23
+ .or(z.object({ $eq: z.number() }))
24
+ .or(z.object({ $ne: z.number() }))
25
+ .or(z.object({ $gte: z.number() }))
26
+ .or(z.object({ $lte: z.number() }));
27
+ export const zAddCommentAction = z
28
+ .object({
29
+ by: z.string(),
30
+ body: z.string(),
31
+ })
32
+ .strict();
33
+ export const zSendEmailAction = z
34
+ .object({
35
+ provider: z.enum(["google"]),
36
+ name: z.string(),
37
+ from: z.string(),
38
+ to: z.string(),
39
+ subject: z.string(),
40
+ body: z.string(),
41
+ })
42
+ .strict();
43
+ const zFollowUpRule = z.object({
44
+ name: z.string(),
45
+ $match: z
46
+ .object({
47
+ actived_at: mDate,
48
+ email: mString,
49
+ comments: mNumber,
50
+ created_at: mDate,
51
+ comments_author: mString,
52
+ head: mString,
53
+ lastcomment: mString,
54
+ on_registry: z.boolean(),
55
+ nickName: mString,
56
+ ownername: mString,
57
+ state: z.enum(["OPEN", "CLOSED", "MERGED"]),
58
+ emailState: z.enum(["", "waiting", "sending", "sent", "error"]),
59
+ updated_at: mDate,
60
+ url: mString,
61
+ })
62
+ .strict()
63
+ .partial(),
64
+ action: z
65
+ .object({
66
+ "add-comment": zAddCommentAction,
67
+ "send-email": zSendEmailAction, // WARN: not implementd
68
+ "update-issue": z
69
+ .object({
70
+ tags: mAny,
71
+ })
72
+ .strict(),
73
+ // close: z.any(),
74
+ })
75
+ .strict()
76
+ .partial(),
77
+ });
78
+ // zPullsStatus
79
+ export const zFollowUpRules = zFollowUpRule.array();