comfy-pr 0.2.20 → 0.2.24

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 (78) hide show
  1. package/README.md +225 -225
  2. package/next-env.d.ts +5 -5
  3. package/package.json +10 -2
  4. package/src/Authors.ts +48 -0
  5. package/src/CMNodes.ts +60 -60
  6. package/src/CNRepos.ts +74 -72
  7. package/src/CRNodes.ts +27 -27
  8. package/src/CRPulls.ts +4 -4
  9. package/src/FORK_OWNER.ts +5 -5
  10. package/src/FORK_PREFIX.ts +5 -5
  11. package/src/FollowRules.ts +25 -25
  12. package/src/GIT_USEREMAIL.ts +5 -5
  13. package/src/GIT_USERNAME.ts +9 -9
  14. package/src/GithubIssueComments.ts +3 -3
  15. package/src/PushedBranch.ts +3 -3
  16. package/src/Totals.ts +9 -9
  17. package/src/TrackingPRs.ts +12 -12
  18. package/src/WorkerInstances.ts +89 -89
  19. package/src/addCommentAction.ts +65 -0
  20. package/src/analyzePullsStatus.ts +170 -134
  21. package/src/analyzeTotals.test.ts +5 -5
  22. package/src/analyzeTotals.ts +118 -120
  23. package/src/checkComfyActivated.ts +39 -39
  24. package/src/cli.ts +40 -40
  25. package/src/clone_modify_push_Branches.ts +21 -21
  26. package/src/createComfyRegistryPRsFromCandidates.ts +55 -55
  27. package/src/createComfyRegistryPullRequests.ts +22 -22
  28. package/src/createGithubForkForRepo.ts +37 -37
  29. package/src/createGithubPullRequest.ts +94 -94
  30. package/src/createIssueComment.ts +29 -29
  31. package/src/fetchCMNodes.ts +22 -22
  32. package/src/fetchComfyRegistryNodes.ts +11 -11
  33. package/src/fetchCurrentGeoInfo.ts +6 -6
  34. package/src/fetchRelatedPullWithComments.ts +15 -15
  35. package/src/fetchRepoDescriptionMap.ts +15 -15
  36. package/src/followRuleSchema.ts +76 -76
  37. package/src/getActivatedShell.ts +18 -18
  38. package/src/getBranchWorkingDir.ts +16 -16
  39. package/src/getRepoWorkingDir.ts +5 -5
  40. package/src/ghUser.ts +6 -6
  41. package/src/index.ts +22 -21
  42. package/src/initializeFollowRules.ts +26 -26
  43. package/src/makePublishBranch.ts +58 -58
  44. package/src/makeTomlBranch.ts +53 -53
  45. package/src/matchRelatedPulls.ts +60 -60
  46. package/src/muteInstances.ts +16 -16
  47. package/src/parseIssueUrl.ts +6 -6
  48. package/src/parseOwnerRepo.ts +33 -33
  49. package/src/parsePullUrl.ts +6 -6
  50. package/src/parsePullsState.ts +6 -6
  51. package/src/parseTitleBodyOfMarkdown.ts +8 -8
  52. package/src/postSlackMessage.ts +21 -21
  53. package/src/preload.ts +30 -30
  54. package/src/pullStatusFollowSchema.ts +12 -12
  55. package/src/readTemplateTitle.ts +11 -11
  56. package/src/showFollowRuleSet.ts +12 -0
  57. package/src/summaryLastPullComment.ts +8 -8
  58. package/src/tomlFillDescription.ts +17 -17
  59. package/src/updateAuthors.ts +7 -0
  60. package/src/updateAuthorsForGithub.ts +50 -0
  61. package/src/updateAuthorsFromCNRepo.ts +30 -0
  62. package/src/updateCMNodesDuplicationWarnings.ts +56 -56
  63. package/src/updateCMRepos.ts +27 -27
  64. package/src/updateCNRepos.ts +58 -58
  65. package/src/updateCNReposCRPullsComments.ts +40 -40
  66. package/src/updateCNReposInfo.ts +57 -57
  67. package/src/updateCNReposPRCandidate.ts +85 -85
  68. package/src/updateCNReposPulls.ts +28 -28
  69. package/src/updateCNReposPullsDashboard.ts +49 -49
  70. package/src/updateCNReposRelatedPulls.ts +25 -25
  71. package/src/updateCRNodes.ts +50 -50
  72. package/src/updateCRRepos.ts +26 -26
  73. package/src/updateComfyTotals.ts +43 -43
  74. package/src/updateFollowRuleSet.ts +127 -182
  75. package/src/updateOutdatedPullsTemplates.ts +160 -156
  76. package/src/updateSlackMessages.ts +43 -43
  77. package/tailwind.config.ts +20 -20
  78. package/CHANGELOG.md +0 -118
@@ -0,0 +1,50 @@
1
+ import { $OK, TaskDataOrNull, TaskError, TaskOK } from "@/packages/mongodb-pipeline-ts/Task";
2
+ import DIE from "@snomiao/die";
3
+ import console from "console";
4
+ import { peekYaml } from "peek-log";
5
+ import { snoflow } from "snoflow";
6
+ import { Authors, GithubUsers } from "./Authors";
7
+ import { $stale } from "./db";
8
+ import { gh } from "./gh";
9
+
10
+ export async function updateAuthorsForGithub() {
11
+ await snoflow(Authors.find({ githubMtime: $stale("7d") }))
12
+ .map((e) => e.githubId)
13
+ .filter()
14
+ .pMap(2, async (username) => {
15
+ const cached = await GithubUsers.findOne({ username, mtime: $stale("1d"), ...$OK });
16
+ if (cached) return cached;
17
+ console.log("Fetching github user " + username);
18
+ const result = await gh.users
19
+ .getByUsername({ username })
20
+ .then((e) => e.data)
21
+ .then(TaskOK)
22
+ .catch(TaskError);
23
+ return (
24
+ (await GithubUsers.findOneAndUpdate(
25
+ { username },
26
+ { $set: result },
27
+ { returnDocument: "after", upsert: true }
28
+ )) ?? DIE(`fail to udpate gh users`)
29
+ );
30
+ })
31
+ .map((e) => TaskDataOrNull(e))
32
+ .filter()
33
+ .map(({ email, avatar_url, blog, updated_at, location, company, hireable, bio, login }) => Authors.findOneAndUpdate(
34
+ { githubId: login },
35
+ {
36
+ $set: { githubMtime: new Date(), ...(email && { email }), ...(null != hireable && { hireable }) },
37
+ $addToSet: {
38
+ ...(bio && { bios: bio }),
39
+ avatars: avatar_url,
40
+ ...(location && { locations: location }),
41
+ ...(blog && { blogs: blog }),
42
+ ...(company && { companies: company }),
43
+ },
44
+ },
45
+ { upsert: true, returnDocument: "after" }
46
+ )
47
+ )
48
+ .peek(peekYaml)
49
+ .done();
50
+ }
@@ -0,0 +1,30 @@
1
+ import { $pipeline } from "@/packages/mongodb-pipeline-ts/$pipeline";
2
+ import { snoflow } from "snoflow";
3
+ import { Authors } from "./Authors";
4
+ import { CNRepos } from "./CNRepos";
5
+ import { $filaten } from "./db";
6
+
7
+ /** Update authors for gh users, collecting emails/username/hireable */
8
+ export async function updateAuthorsFromCNRepo() {
9
+ return await snoflow(
10
+ $pipeline(CNRepos)
11
+ .match($filaten({ info: { data: { owner: { login: { $exists: true } } } } }))
12
+ .group({
13
+ _id: "$info.data.owner.login",
14
+ // author: "$info.data.owner.login",
15
+ cm: { $sum: { $cond: [{ $eq: [{ $type: "$cm" }, "missing"] }, 0, 1] } },
16
+ cr: { $sum: { $cond: [{ $eq: [{ $type: "$cr" }, "missing"] }, 0, 1] } },
17
+
18
+ // TODO: get totals open/closed/merged
19
+ // pulls:{
20
+ // OPEN: {"$crPulls.data.pull.prState", "open"}
21
+ // }
22
+ All: { $sum: 1 },
23
+ })
24
+ .set({ login: "$_id" })
25
+ .project({ _id: 0 })
26
+ .aggregate()
27
+ )
28
+ .peek(({ login, ...$set }) => Authors.updateOne({ login }, { $set }, { upsert: true }))
29
+ .done();
30
+ }
@@ -1,56 +1,56 @@
1
- import { unary } from "lodash-es";
2
- import pMap from "p-map";
3
- import { dissoc, filter, groupBy, map, prop, toPairs } from "rambda";
4
- import YAML from "yaml";
5
- import { CMNodes, type CMNode } from "./CMNodes";
6
- import { notifySlack } from "./slack/notifySlack";
7
-
8
- export async function updateCMNodesDuplicationWarnings(nodes: CMNode[]) {
9
- console.log("CMNodes checking duplicates");
10
- // prettier-ignore
11
- const dups = {
12
- ID: filter((e: typeof nodes) => e.length > 1, groupBy((e) => e.id, nodes)),
13
- TITLE: filter((e: typeof nodes) => e.length > 1, groupBy((e) => e.title, nodes)),
14
- REFERENCE: filter((e: typeof nodes) => e.length > 1, groupBy((e) => e.reference, nodes)),
15
- };
16
- const dupsSummary = JSON.stringify(map((x) => map((x) => x.length, x), dups));
17
- await notifySlack(
18
- `[WARN] CMNodes duplicates: ${dupsSummary}\nSolve them in https://github.com/ltdrdata/ComfyUI-Manager/blob/main/custom-node-list.json`,
19
- );
20
-
21
- await pMap(
22
- toPairs(dups),
23
- async ([topic, nodes]) =>
24
- await pMap(
25
- toPairs(nodes),
26
- async ([key, nodesRaw]) => {
27
- const nodes = nodesRaw.map(unary(dissoc("hash")));
28
- const hashes = nodesRaw.map(prop("hash"));
29
- // check sent
30
- const someDuplicateSent = await CMNodes.findOne({
31
- hash: { $in: hashes },
32
- [`duplicated.${topic}`]: { $exists: true },
33
- });
34
- if (someDuplicateSent) return;
35
- // send slack notification
36
- const slackNotification = await notifySlack(
37
- `[ACTION NEEDED WARNING]: please resolve duplicated node in ${topic}: ${key}\n` +
38
- "```\n" +
39
- YAML.stringify(nodes) +
40
- "```" +
41
- "\n\nSolve them in https://github.com/ltdrdata/ComfyUI-Manager/blob/main/custom-node-list.json",
42
- { unique: true },
43
- );
44
- // mark duplicates
45
- await CMNodes.updateMany(
46
- { hash: { $in: hashes } },
47
- {
48
- $set: { [`duplicated.${topic}`]: { hashes, slackNotification } },
49
- },
50
- );
51
- },
52
- { concurrency: 2 },
53
- ),
54
- { concurrency: 2 },
55
- );
56
- }
1
+ import { unary } from "lodash-es";
2
+ import pMap from "p-map";
3
+ import { dissoc, filter, groupBy, map, prop, toPairs } from "rambda";
4
+ import YAML from "yaml";
5
+ import { CMNodes, type CMNode } from "./CMNodes";
6
+ import { notifySlack } from "./slack/notifySlack";
7
+
8
+ export async function updateCMNodesDuplicationWarnings(nodes: CMNode[]) {
9
+ console.log("CMNodes checking duplicates");
10
+ // prettier-ignore
11
+ const dups = {
12
+ ID: filter((e: typeof nodes) => e.length > 1, groupBy((e) => e.id, nodes)),
13
+ TITLE: filter((e: typeof nodes) => e.length > 1, groupBy((e) => e.title, nodes)),
14
+ REFERENCE: filter((e: typeof nodes) => e.length > 1, groupBy((e) => e.reference, nodes)),
15
+ };
16
+ const dupsSummary = JSON.stringify(map((x) => map((x) => x.length, x), dups));
17
+ await notifySlack(
18
+ `[WARN] CMNodes duplicates: ${dupsSummary}\nSolve them in https://github.com/ltdrdata/ComfyUI-Manager/blob/main/custom-node-list.json`,
19
+ );
20
+
21
+ await pMap(
22
+ toPairs(dups),
23
+ async ([topic, nodes]) =>
24
+ await pMap(
25
+ toPairs(nodes),
26
+ async ([key, nodesRaw]) => {
27
+ const nodes = nodesRaw.map(unary(dissoc("hash")));
28
+ const hashes = nodesRaw.map(prop("hash"));
29
+ // check sent
30
+ const someDuplicateSent = await CMNodes.findOne({
31
+ hash: { $in: hashes },
32
+ [`duplicated.${topic}`]: { $exists: true },
33
+ });
34
+ if (someDuplicateSent) return;
35
+ // send slack notification
36
+ const slackNotification = await notifySlack(
37
+ `[ACTION NEEDED WARNING]: please resolve duplicated node in ${topic}: ${key}\n` +
38
+ "```\n" +
39
+ YAML.stringify(nodes) +
40
+ "```" +
41
+ "\n\nSolve them in https://github.com/ltdrdata/ComfyUI-Manager/blob/main/custom-node-list.json",
42
+ { unique: true },
43
+ );
44
+ // mark duplicates
45
+ await CMNodes.updateMany(
46
+ { hash: { $in: hashes } },
47
+ {
48
+ $set: { [`duplicated.${topic}`]: { hashes, slackNotification } },
49
+ },
50
+ );
51
+ },
52
+ { concurrency: 2 },
53
+ ),
54
+ { concurrency: 2 },
55
+ );
56
+ }
@@ -1,27 +1,27 @@
1
- import pMap from "p-map";
2
- import { CMNodes } from "./CMNodes";
3
- import { CNRepos } from "./CNRepos";
4
- import { tLog } from "./utils/tLog";
5
- if (import.meta.main) {
6
- await tLog("Update Repos from ComfyUI Manager", updateCMRepos);
7
- console.log(await CMNodes.estimatedDocumentCount());
8
- }
9
- export async function updateCMRepos() {
10
- await CMNodes.createIndex({ repo_id: 1 });
11
- return await pMap(CMNodes.find({ repo_id: { $exists: false } }), async (cm, i) => {
12
- const { reference: repository, _id } = cm;
13
- return await CNRepos.updateOne(
14
- { repository },
15
- {
16
- $set: {
17
- cm: (await CMNodes.findOneAndUpdate(
18
- { _id },
19
- { $set: { repo_id: cm._id } },
20
- { upsert: true, returnDocument: "after" },
21
- ))!,
22
- },
23
- },
24
- { upsert: true },
25
- );
26
- });
27
- }
1
+ import pMap from "p-map";
2
+ import { CMNodes } from "./CMNodes";
3
+ import { CNRepos } from "./CNRepos";
4
+ import { tLog } from "./utils/tLog";
5
+ if (import.meta.main) {
6
+ await tLog("Update Repos from ComfyUI Manager", updateCMRepos);
7
+ console.log(await CMNodes.estimatedDocumentCount());
8
+ }
9
+ export async function updateCMRepos() {
10
+ await CMNodes.createIndex({ repo_id: 1 });
11
+ return await pMap(CMNodes.find({ repo_id: { $exists: false } }), async (cm, i) => {
12
+ const { reference: repository, _id } = cm;
13
+ return await CNRepos.updateOne(
14
+ { repository },
15
+ {
16
+ $set: {
17
+ cm: (await CMNodes.findOneAndUpdate(
18
+ { _id },
19
+ { $set: { repo_id: cm._id } },
20
+ { upsert: true, returnDocument: "after" },
21
+ ))!,
22
+ },
23
+ },
24
+ { upsert: true },
25
+ );
26
+ });
27
+ }
@@ -1,58 +1,58 @@
1
- import { updateCMNodes } from "./CMNodes";
2
- import { getWorkerInstance } from "./WorkerInstances";
3
- import { createComfyRegistryPRsFromCandidates } from "./createComfyRegistryPRsFromCandidates";
4
- import { notifySlack } from "./slack/notifySlack";
5
- import { updateCMRepos } from "./updateCMRepos";
6
- import { updateCNReposCRPullsComments } from "./updateCNReposCRPullsComments";
7
- import { updateCNReposInfo } from "./updateCNReposInfo";
8
- import { updateCNReposPRCandidate } from "./updateCNReposPRCandidate";
9
- import { updateCNReposPulls } from "./updateCNReposPulls";
10
- import { updateCNRepoPullsDashboard } from "./updateCNReposPullsDashboard";
11
- import { updateCNReposRelatedPulls } from "./updateCNReposRelatedPulls";
12
- import { updateCRNodes } from "./updateCRNodes";
13
- import { updateCRRepos } from "./updateCRRepos";
14
- import { updateComfyTotals } from "./updateComfyTotals";
15
- import { updateOutdatedPullsTemplates } from "./updateOutdatedPullsTemplates";
16
- import { tLog } from "./utils/tLog";
17
-
18
- if (import.meta.main) {
19
- await getWorkerInstance("Updating CNRepos");
20
- // await cacheHealthReport();
21
- await updateCNRepos();
22
- // updateCNReposPRTasks
23
- // await scanCNRepoThenPRs();
24
- // await pMap(candidates, (e) => updateCNRepoPRStatus(e.repository), { concurrency: 4 });
25
- // candidates
26
- }
27
-
28
- export async function updateCNRepos() {
29
- await Promise.all([
30
- tLog("Report Worker Status", async () => {
31
- const worker = await getWorkerInstance("ComfyPR Bot Running");
32
- const workerInfo = `${worker.geo.countryCode}/${worker.geo.region}/${worker.geo.city}`;
33
- const msg = `COMFY-PR BOT RUNNING ${new Date().toISOString()}\nWorker: ${workerInfo}`;
34
- return [await notifySlack(msg, { unique: true, silent: true })];
35
- }),
36
- // stage 1: get repos
37
- await tLog("Update Nodes from ComfyUI Manager", updateCMNodes),
38
- await tLog("Update Repos from ComfyUI Manager", updateCMRepos),
39
- await tLog("Update Nodes from ComfyRegistry", updateCRNodes),
40
- await tLog("Update Repos from ComfyRegistry", updateCRRepos),
41
- // stage 2: update repo info & pulls
42
- await tLog("Update CNRepos for Repo Infos", updateCNReposInfo),
43
- await tLog("Update CNRepos for Github Pulls", updateCNReposPulls),
44
- await tLog("Update Pulls Dashboard", updateCNRepoPullsDashboard),
45
- // stage 3: update related pulls and comments
46
- await tLog("Update CNRepos for Related Pulls", updateCNReposRelatedPulls),
47
- await tLog("Update Outdated Pulls Templates", updateOutdatedPullsTemplates),
48
- // stage 4: update related comments
49
- await tLog("Update CNRepos for Related Comments", updateCNReposCRPullsComments),
50
- // stage 5: mark and create PRs
51
- await tLog("Update CNRepos PR Candidates", updateCNReposPRCandidate),
52
- await tLog("Create ComfyRegistry PRs", createComfyRegistryPRsFromCandidates),
53
- // final
54
- await tLog("Update Comfy Totals", updateComfyTotals),
55
- ]);
56
-
57
- console.log("All repo updated");
58
- }
1
+ import { updateCMNodes } from "./CMNodes";
2
+ import { getWorkerInstance } from "./WorkerInstances";
3
+ import { createComfyRegistryPRsFromCandidates } from "./createComfyRegistryPRsFromCandidates";
4
+ import { notifySlack } from "./slack/notifySlack";
5
+ import { updateCMRepos } from "./updateCMRepos";
6
+ import { updateCNReposCRPullsComments } from "./updateCNReposCRPullsComments";
7
+ import { updateCNReposInfo } from "./updateCNReposInfo";
8
+ import { updateCNReposPRCandidate } from "./updateCNReposPRCandidate";
9
+ import { updateCNReposPulls } from "./updateCNReposPulls";
10
+ import { updateCNRepoPullsDashboard } from "./updateCNReposPullsDashboard";
11
+ import { updateCNReposRelatedPulls } from "./updateCNReposRelatedPulls";
12
+ import { updateCRNodes } from "./updateCRNodes";
13
+ import { updateCRRepos } from "./updateCRRepos";
14
+ import { updateComfyTotals } from "./updateComfyTotals";
15
+ import { updateOutdatedPullsTemplates } from "./updateOutdatedPullsTemplates";
16
+ import { tLog } from "./utils/tLog";
17
+
18
+ if (import.meta.main) {
19
+ await getWorkerInstance("Updating CNRepos");
20
+ // await cacheHealthReport();
21
+ await updateCNRepos();
22
+ // updateCNReposPRTasks
23
+ // await scanCNRepoThenPRs();
24
+ // await pMap(candidates, (e) => updateCNRepoPRStatus(e.repository), { concurrency: 4 });
25
+ // candidates
26
+ }
27
+
28
+ export async function updateCNRepos() {
29
+ await Promise.all([
30
+ tLog("Report Worker Status", async () => {
31
+ const worker = await getWorkerInstance("ComfyPR Bot Running");
32
+ const workerInfo = `${worker.geo.countryCode}/${worker.geo.region}/${worker.geo.city}`;
33
+ const msg = `COMFY-PR BOT RUNNING ${new Date().toISOString()}\nWorker: ${workerInfo}`;
34
+ return [await notifySlack(msg, { unique: true, silent: true })];
35
+ }),
36
+ // stage 1: get repos
37
+ await tLog("Update Nodes from ComfyUI Manager", updateCMNodes),
38
+ await tLog("Update Repos from ComfyUI Manager", updateCMRepos),
39
+ await tLog("Update Nodes from ComfyRegistry", updateCRNodes),
40
+ await tLog("Update Repos from ComfyRegistry", updateCRRepos),
41
+ // stage 2: update repo info & pulls
42
+ await tLog("Update CNRepos for Repo Infos", updateCNReposInfo),
43
+ await tLog("Update CNRepos for Github Pulls", updateCNReposPulls),
44
+ await tLog("Update Pulls Dashboard", updateCNRepoPullsDashboard),
45
+ // stage 3: update related pulls and comments
46
+ await tLog("Update CNRepos for Related Pulls", updateCNReposRelatedPulls),
47
+ await tLog("Update Outdated Pulls Templates", updateOutdatedPullsTemplates),
48
+ // stage 4: update related comments
49
+ await tLog("Update CNRepos for Related Comments", updateCNReposCRPullsComments),
50
+ // stage 5: mark and create PRs
51
+ await tLog("Update CNRepos PR Candidates", updateCNReposPRCandidate),
52
+ await tLog("Create ComfyRegistry PRs", createComfyRegistryPRsFromCandidates),
53
+ // final
54
+ await tLog("Update Comfy Totals", updateComfyTotals),
55
+ ]);
56
+
57
+ console.log("All repo updated");
58
+ }
@@ -1,40 +1,40 @@
1
- import pMap from "p-map";
2
- import { CNRepos, type CRPull } from "./CNRepos";
3
- import { $fresh, $stale } from "./db";
4
- // import { $filaten } from "./db";
5
- // import { $pipeline } from "./db/$pipeline";
6
- import { $filaten } from "@/packages/mongodb-pipeline-ts/$filaten";
7
- import { $pipeline } from "@/packages/mongodb-pipeline-ts/$pipeline";
8
- import { TaskError, TaskOK } from "../packages/mongodb-pipeline-ts/Task";
9
- import { getWorkerInstance } from "./WorkerInstances";
10
- import { fetchIssueComments } from "./gh/fetchIssueComments";
11
-
12
- if (import.meta.main) {
13
- await getWorkerInstance("updateCNReposCRPullsComments");
14
- await updateCNReposCRPullsComments();
15
- console.log("All done");
16
- }
17
-
18
- export async function updateCNReposCRPullsComments() {
19
- return await pMap(
20
- $pipeline(CNRepos)
21
- .unwind("$crPulls.data")
22
- .match($filaten({ crPulls: { mtime: $fresh("7d"), data: { comments: { mtime: $stale("1d") } } } }))
23
- .set($filaten({ "crPulls.data": { repository: "$repository" } }))
24
- .replaceRoot({ newRoot: "$crPulls.data" })
25
- .aggregate(),
26
- async (data) => {
27
- const { repository, pull } = data as unknown as { repository: string } & CRPull;
28
- const html_url = pull.html_url;
29
- const comments = await fetchIssueComments(repository, pull).then(TaskOK).catch(TaskError);
30
- return [
31
- await CNRepos.findOneAndUpdate(
32
- $filaten({ repository, crPulls: { data: { pull: { html_url } } } }),
33
- { $set: { "crPulls.data.$.comments": comments } },
34
- { upsert: true, returnDocument: "after" },
35
- ),
36
- ];
37
- },
38
- { concurrency: 2 },
39
- );
40
- }
1
+ import pMap from "p-map";
2
+ import { CNRepos, type CRPull } from "./CNRepos";
3
+ import { $fresh, $stale } from "./db";
4
+ // import { $filaten } from "./db";
5
+ // import { $pipeline } from "./db/$pipeline";
6
+ import { $filaten } from "@/packages/mongodb-pipeline-ts/$filaten";
7
+ import { $pipeline } from "@/packages/mongodb-pipeline-ts/$pipeline";
8
+ import { TaskError, TaskOK } from "../packages/mongodb-pipeline-ts/Task";
9
+ import { getWorkerInstance } from "./WorkerInstances";
10
+ import { fetchIssueComments } from "./gh/fetchIssueComments";
11
+
12
+ if (import.meta.main) {
13
+ await getWorkerInstance("updateCNReposCRPullsComments");
14
+ await updateCNReposCRPullsComments();
15
+ console.log("All done");
16
+ }
17
+
18
+ export async function updateCNReposCRPullsComments() {
19
+ return await pMap(
20
+ $pipeline(CNRepos)
21
+ .unwind("$crPulls.data")
22
+ .match($filaten({ crPulls: { mtime: $fresh("7d"), data: { comments: { mtime: $stale("1d") } } } }))
23
+ .set($filaten({ "crPulls.data": { repository: "$repository" } }))
24
+ .replaceRoot({ newRoot: "$crPulls.data" })
25
+ .aggregate(),
26
+ async (data) => {
27
+ const { repository, pull } = data as unknown as { repository: string } & CRPull;
28
+ const html_url = pull.html_url;
29
+ const comments = await fetchIssueComments(repository, pull).then(TaskOK).catch(TaskError);
30
+ return [
31
+ await CNRepos.findOneAndUpdate(
32
+ $filaten({ repository, crPulls: { data: { pull: { html_url } } } }),
33
+ { $set: { "crPulls.data.$.comments": comments } },
34
+ { upsert: true, returnDocument: "after" },
35
+ ),
36
+ ];
37
+ },
38
+ { concurrency: 2 },
39
+ );
40
+ }
@@ -1,57 +1,57 @@
1
- import pMap from "p-map";
2
- import { dissoc } from "rambda";
3
- import { match } from "ts-pattern";
4
- import { $OK, TaskError, TaskOK } from "../packages/mongodb-pipeline-ts/Task";
5
- import { CNRepos } from "./CNRepos";
6
- import { getWorkerInstance } from "./WorkerInstances";
7
- import { $filaten, $stale } from "./db";
8
- import { gh } from "./gh";
9
- import { parseUrlRepoOwner } from "./parseOwnerRepo";
10
- import { tLog } from "./utils/tLog";
11
-
12
- if (import.meta.main) {
13
- await getWorkerInstance("updateCNReposInfo");
14
- await tLog("updateCNReposInfo", updateCNReposInfo);
15
- }
16
-
17
- export async function updateCNReposInfo() {
18
- await CNRepos.createIndex($filaten({ info: { mtime: 1 } }));
19
- return await pMap(
20
- CNRepos.find($filaten({ info: { mtime: $stale("1d") } })),
21
- async (repo) => {
22
- const { repository } = repo;
23
- console.log("[INFO] Fetching meta info from " + repository);
24
- const _info = await gh.repos
25
- .get({ ...parseUrlRepoOwner(repository) })
26
- .then(({ data }) => data)
27
- .then(TaskOK)
28
- .catch(TaskError);
29
- // Handle renamed repos
30
- const { info, url } = await match(_info)
31
- .with($OK, async (info) => {
32
- const url = info.data.html_url;
33
- if (url === repository) return { info, url: repository };
34
-
35
- // console.log(info.data.use_squash_pr_title_as_default)
36
- console.log("[INFO] Migrating renamed repo: \nfrom: ", repository + "\n to: " + url);
37
- // migrate data into new CNRepo
38
- await CNRepos.updateOne(
39
- { repository: url },
40
- {
41
- $set: {
42
- ...dissoc("_id", { ...(await CNRepos.findOneAndDelete({ repository })) }),
43
- repository: url,
44
- oldUrls: { $addToSet: repository },
45
- },
46
- },
47
- { upsert: true },
48
- );
49
- return { info, url };
50
- })
51
- .otherwise((info) => ({ info, url: repository }));
52
-
53
- return await CNRepos.updateOne({ repository: url }, { $set: { info } }, { upsert: true });
54
- },
55
- { concurrency: 2 },
56
- );
57
- }
1
+ import pMap from "p-map";
2
+ import { dissoc } from "rambda";
3
+ import { match } from "ts-pattern";
4
+ import { $OK, TaskError, TaskOK } from "../packages/mongodb-pipeline-ts/Task";
5
+ import { CNRepos } from "./CNRepos";
6
+ import { getWorkerInstance } from "./WorkerInstances";
7
+ import { $filaten, $stale } from "./db";
8
+ import { gh } from "./gh";
9
+ import { parseUrlRepoOwner } from "./parseOwnerRepo";
10
+ import { tLog } from "./utils/tLog";
11
+
12
+ if (import.meta.main) {
13
+ await getWorkerInstance("updateCNReposInfo");
14
+ await tLog("updateCNReposInfo", updateCNReposInfo);
15
+ }
16
+
17
+ export async function updateCNReposInfo() {
18
+ await CNRepos.createIndex($filaten({ info: { mtime: 1 } }));
19
+ return await pMap(
20
+ CNRepos.find($filaten({ info: { mtime: $stale("1d") } })),
21
+ async (repo) => {
22
+ const { repository } = repo;
23
+ console.log("[INFO] Fetching meta info from " + repository);
24
+ const _info = await gh.repos
25
+ .get({ ...parseUrlRepoOwner(repository) })
26
+ .then(({ data }) => data)
27
+ .then(TaskOK)
28
+ .catch(TaskError);
29
+ // Handle renamed repos
30
+ const { info, url } = await match(_info)
31
+ .with($OK, async (info) => {
32
+ const url = info.data.html_url;
33
+ if (url === repository) return { info, url: repository };
34
+
35
+ // console.log(info.data.use_squash_pr_title_as_default)
36
+ console.log("[INFO] Migrating renamed repo: \nfrom: ", repository + "\n to: " + url);
37
+ // migrate data into new CNRepo
38
+ await CNRepos.updateOne(
39
+ { repository: url },
40
+ {
41
+ $set: {
42
+ ...dissoc("_id", { ...(await CNRepos.findOneAndDelete({ repository })) }),
43
+ repository: url,
44
+ oldUrls: { $addToSet: repository },
45
+ },
46
+ },
47
+ { upsert: true },
48
+ );
49
+ return { info, url };
50
+ })
51
+ .otherwise((info) => ({ info, url: repository }));
52
+
53
+ return await CNRepos.updateOne({ repository: url }, { $set: { info } }, { upsert: true });
54
+ },
55
+ { concurrency: 2 },
56
+ );
57
+ }