comfy-pr 0.2.19 → 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 -125
  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 -75
  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 -25
  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 -109
package/src/cli.ts CHANGED
@@ -1,40 +1,40 @@
1
- #!bun
2
- import DIE from "@snomiao/die";
3
- import { readFile } from "fs/promises";
4
- import { argv, $ as zx } from "zx";
5
- import { checkComfyActivated } from "./checkComfyActivated";
6
- import { createComfyRegistryPullRequests } from "./createComfyRegistryPullRequests";
7
- zx.verbose = true;
8
-
9
- if (argv.help) {
10
- console.log(
11
- `
12
- bunx comfy-pr --repolist repos.txt one repo per-line
13
- bunx comfy-pr [...GITHUB_REPO_URLS] github repos
14
- bunx cross-env REPO=https://github.com/OWNER/REPO bunx comfy-pr
15
- `.trim(),
16
- );
17
- }
18
-
19
- {
20
- await checkComfyActivated();
21
-
22
- const envRepos =
23
- process.env.REPO?.split("\n")
24
- .map((e) => e.trim())
25
- .filter(Boolean) || [];
26
- const argvRepos = argv._.filter((a) => !a.endsWith(import.meta.filename));
27
- const listRepos =
28
- (argv.repolist &&
29
- (await readFile(argv.repolist, "utf8").catch(() => ""))
30
- .split("\n")
31
- .map((e) => e.trim())
32
- .filter(Boolean)) ||
33
- [];
34
- const repos = (listRepos.length && listRepos) ||
35
- (argvRepos.length && argvRepos) ||
36
- (envRepos.length && envRepos) || [DIE("Missing PR target, please set env.REPO")];
37
- for await (const upstreamUrl of repos) {
38
- await createComfyRegistryPullRequests(upstreamUrl);
39
- }
40
- }
1
+ #!bun
2
+ import DIE from "@snomiao/die";
3
+ import { readFile } from "fs/promises";
4
+ import { argv, $ as zx } from "zx";
5
+ import { checkComfyActivated } from "./checkComfyActivated";
6
+ import { createComfyRegistryPullRequests } from "./createComfyRegistryPullRequests";
7
+ zx.verbose = true;
8
+
9
+ if (argv.help) {
10
+ console.log(
11
+ `
12
+ bunx comfy-pr --repolist repos.txt one repo per-line
13
+ bunx comfy-pr [...GITHUB_REPO_URLS] github repos
14
+ bunx cross-env REPO=https://github.com/OWNER/REPO bunx comfy-pr
15
+ `.trim(),
16
+ );
17
+ }
18
+
19
+ {
20
+ await checkComfyActivated();
21
+
22
+ const envRepos =
23
+ process.env.REPO?.split("\n")
24
+ .map((e) => e.trim())
25
+ .filter(Boolean) || [];
26
+ const argvRepos = argv._.filter((a) => !a.endsWith(import.meta.filename));
27
+ const listRepos =
28
+ (argv.repolist &&
29
+ (await readFile(argv.repolist, "utf8").catch(() => ""))
30
+ .split("\n")
31
+ .map((e) => e.trim())
32
+ .filter(Boolean)) ||
33
+ [];
34
+ const repos = (listRepos.length && listRepos) ||
35
+ (argvRepos.length && argvRepos) ||
36
+ (envRepos.length && envRepos) || [DIE("Missing PR target, please set env.REPO")];
37
+ for await (const upstreamUrl of repos) {
38
+ await createComfyRegistryPullRequests(upstreamUrl);
39
+ }
40
+ }
@@ -1,21 +1,21 @@
1
- import { makePublishcrBranch } from "./makePublishBranch";
2
- import { makePyprojectBranch } from "./makeTomlBranch";
3
-
4
- export async function clone_modify_push_Branches(
5
- upstreamUrl: string,
6
- forkUrl: string,
7
- ) {
8
- return (
9
- await Promise.all([
10
- makePyprojectBranch(upstreamUrl, forkUrl),
11
- makePublishcrBranch(upstreamUrl, forkUrl),
12
- ])
13
- ).map(({ body, branch, title, type }) => ({
14
- body,
15
- branch,
16
- title,
17
- type,
18
- srcUrl: forkUrl,
19
- dstUrl: upstreamUrl,
20
- }));
21
- }
1
+ import { makePublishcrBranch } from "./makePublishBranch";
2
+ import { makePyprojectBranch } from "./makeTomlBranch";
3
+
4
+ export async function clone_modify_push_Branches(
5
+ upstreamUrl: string,
6
+ forkUrl: string,
7
+ ) {
8
+ return (
9
+ await Promise.all([
10
+ makePyprojectBranch(upstreamUrl, forkUrl),
11
+ makePublishcrBranch(upstreamUrl, forkUrl),
12
+ ])
13
+ ).map(({ body, branch, title, type }) => ({
14
+ body,
15
+ branch,
16
+ title,
17
+ type,
18
+ srcUrl: forkUrl,
19
+ dstUrl: upstreamUrl,
20
+ }));
21
+ }
@@ -1,55 +1,55 @@
1
- import { $pipeline } from "@/packages/mongodb-pipeline-ts/$pipeline";
2
- import pMap from "p-map";
3
- import { match } from "ts-pattern";
4
- import { $OK, TaskError, TaskOK } from "../packages/mongodb-pipeline-ts/Task";
5
- import { CNRepos } from "./CNRepos";
6
- import { createComfyRegistryPullRequests } from "./createComfyRegistryPullRequests";
7
- import { $filaten, $stale } from "./db";
8
- import { parseUrlRepoOwner, stringifyOwnerRepo } from "./parseOwnerRepo";
9
- import { notifySlackLinks } from "./slack/notifySlackLinks";
10
- import { tLog } from "./utils/tLog";
11
- if (import.meta.main) {
12
- await tLog("createComfyRegistryPRsFromCandidates", createComfyRegistryPRsFromCandidates);
13
- console.log("all done");
14
- }
15
- export async function createComfyRegistryPRsFromCandidates() {
16
- await CNRepos.createIndex($filaten({ candidate: { data: 1 } }));
17
- await CNRepos.createIndex(
18
- $filaten({
19
- candidate: { data: 1 },
20
- createdPulls: { state: 1, mtime: 1 },
21
- }),
22
- );
23
- return await pMap(
24
- $pipeline(CNRepos)
25
- .match(
26
- $filaten({
27
- candidate: { data: { $eq: true } },
28
- createdPulls: { state: { $ne: "ok" }, mtime: $stale("5m") },
29
- }),
30
- )
31
- .aggregate(),
32
- async (repo) => {
33
- const { repository } = repo;
34
- console.log("Making PRs for " + repository);
35
- const createdPulls = await createComfyRegistryPullRequests(repository).then(TaskOK).catch(TaskError);
36
- match(createdPulls).with($OK, async ({ data }) => {
37
- const links = data.map((e) => ({
38
- href: e.html_url,
39
- name: stringifyOwnerRepo(parseUrlRepoOwner(e.html_url.replace(/\/pull\/.*$/, ""))) + " #" + e.title,
40
- }));
41
- await notifySlackLinks("PR just Created, @HaoHao check plz", links);
42
- await pMap(data, async (pull) => {
43
- const { html_url } = pull;
44
- // also update to crPulls
45
- await CNRepos.updateOne($filaten({ repository, crPulls: { data: { pull: { html_url } } } }), {
46
- $set: { "crPulls.data.$.pull": pull },
47
- });
48
- });
49
- });
50
-
51
- return await CNRepos.updateOne({ repository }, { $set: { createdPulls } });
52
- },
53
- { concurrency: 2, stopOnError: false },
54
- );
55
- }
1
+ import { $pipeline } from "@/packages/mongodb-pipeline-ts/$pipeline";
2
+ import pMap from "p-map";
3
+ import { match } from "ts-pattern";
4
+ import { $OK, TaskError, TaskOK } from "../packages/mongodb-pipeline-ts/Task";
5
+ import { CNRepos } from "./CNRepos";
6
+ import { createComfyRegistryPullRequests } from "./createComfyRegistryPullRequests";
7
+ import { $filaten, $stale } from "./db";
8
+ import { parseUrlRepoOwner, stringifyOwnerRepo } from "./parseOwnerRepo";
9
+ import { notifySlackLinks } from "./slack/notifySlackLinks";
10
+ import { tLog } from "./utils/tLog";
11
+ if (import.meta.main) {
12
+ await tLog("createComfyRegistryPRsFromCandidates", createComfyRegistryPRsFromCandidates);
13
+ console.log("all done");
14
+ }
15
+ export async function createComfyRegistryPRsFromCandidates() {
16
+ await CNRepos.createIndex($filaten({ candidate: { data: 1 } }));
17
+ await CNRepos.createIndex(
18
+ $filaten({
19
+ candidate: { data: 1 },
20
+ createdPulls: { state: 1, mtime: 1 },
21
+ }),
22
+ );
23
+ return await pMap(
24
+ $pipeline(CNRepos)
25
+ .match(
26
+ $filaten({
27
+ candidate: { data: { $eq: true } },
28
+ createdPulls: { state: { $ne: "ok" }, mtime: $stale("5m") },
29
+ }),
30
+ )
31
+ .aggregate(),
32
+ async (repo) => {
33
+ const { repository } = repo;
34
+ console.log("Making PRs for " + repository);
35
+ const createdPulls = await createComfyRegistryPullRequests(repository).then(TaskOK).catch(TaskError);
36
+ match(createdPulls).with($OK, async ({ data }) => {
37
+ const links = data.map((e) => ({
38
+ href: e.html_url,
39
+ name: stringifyOwnerRepo(parseUrlRepoOwner(e.html_url.replace(/\/pull\/.*$/, ""))) + " #" + e.title,
40
+ }));
41
+ await notifySlackLinks("PR just Created, @HaoHao check plz", links);
42
+ await pMap(data, async (pull) => {
43
+ const { html_url } = pull;
44
+ // also update to crPulls
45
+ await CNRepos.updateOne($filaten({ repository, crPulls: { data: { pull: { html_url } } } }), {
46
+ $set: { "crPulls.data.$.pull": pull },
47
+ });
48
+ });
49
+ });
50
+
51
+ return await CNRepos.updateOne({ repository }, { $set: { createdPulls } });
52
+ },
53
+ { concurrency: 2, stopOnError: false },
54
+ );
55
+ }
@@ -1,22 +1,22 @@
1
- import pMap from "p-map";
2
- import yaml from "yaml";
3
- // import { chalk } from "zx";
4
- import { clone_modify_push_Branches } from "./clone_modify_push_Branches";
5
- import { createGithubForkForRepo } from "./createGithubForkForRepo";
6
- import { createGithubPullRequest } from "./createGithubPullRequest";
7
- import type { GithubPull } from "./gh/GithubPull";
8
- import { parsePulls } from "./parsePullsState";
9
-
10
- export async function createComfyRegistryPullRequests(upstreamRepoUrl: string) {
11
- const forkedRepo = await createGithubForkForRepo(upstreamRepoUrl);
12
- const PR_REQUESTS = await clone_modify_push_Branches(upstreamRepoUrl, forkedRepo.html_url);
13
- // branch is ready in fork now
14
- // create prs for each branch
15
- console.log("Going to create PRs for the following branches:");
16
- // console.log(chalk.green(yaml.stringify({ PR_REQUESTS })));
17
- console.log(yaml.stringify({ PR_REQUESTS }));
18
- // prs
19
- const prs = await pMap(PR_REQUESTS, async ({ type, ...prInfo }) => await createGithubPullRequest({ ...prInfo }));
20
- console.log("ALL PRs DONE");
21
- return (prs as GithubPull[]).map((e) => parsePulls([e])[0]);
22
- }
1
+ import pMap from "p-map";
2
+ import yaml from "yaml";
3
+ // import { chalk } from "zx";
4
+ import { clone_modify_push_Branches } from "./clone_modify_push_Branches";
5
+ import { createGithubForkForRepo } from "./createGithubForkForRepo";
6
+ import { createGithubPullRequest } from "./createGithubPullRequest";
7
+ import type { GithubPull } from "./gh/GithubPull";
8
+ import { parsePulls } from "./parsePullsState";
9
+
10
+ export async function createComfyRegistryPullRequests(upstreamRepoUrl: string) {
11
+ const forkedRepo = await createGithubForkForRepo(upstreamRepoUrl);
12
+ const PR_REQUESTS = await clone_modify_push_Branches(upstreamRepoUrl, forkedRepo.html_url);
13
+ // branch is ready in fork now
14
+ // create prs for each branch
15
+ console.log("Going to create PRs for the following branches:");
16
+ // console.log(chalk.green(yaml.stringify({ PR_REQUESTS })));
17
+ console.log(yaml.stringify({ PR_REQUESTS }));
18
+ // prs
19
+ const prs = await pMap(PR_REQUESTS, async ({ type, ...prInfo }) => await createGithubPullRequest({ ...prInfo }));
20
+ console.log("ALL PRs DONE");
21
+ return (prs as GithubPull[]).map((e) => parsePulls([e])[0]);
22
+ }
@@ -1,37 +1,37 @@
1
- import DIE from "@snomiao/die";
2
- import md5 from "md5";
3
- import minimist from "minimist";
4
- import { FORK_OWNER } from "./FORK_OWNER";
5
- import { FORK_PREFIX } from "./FORK_PREFIX";
6
- import { createGithubFork } from "./gh/createGithubFork";
7
- import { ghUser } from "./ghUser";
8
- import { parseUrlRepoOwner } from "./parseOwnerRepo";
9
-
10
- /**
11
- * this function creates a fork of the upstream repo,
12
- * fork to the FORK_OWNER, and add a prefix to the repo name
13
- * - the prefix is optional, if not provided, the repo name will be the same as the upstream repo
14
- * - the prefix is useful to distinguish the forked repo from the other repo in the same owner
15
- * SALT is used to generate a unique repo name, so that the forked repo will not conflict with other forks
16
- *
17
- * @author snomiao <snomiao@gmail.com>
18
- * @param upstreamRepoUrl
19
- * @returns forked repo info
20
- */
21
- export async function createGithubForkForRepo(upstreamRepoUrl: string) {
22
- // debug
23
- // console.log(`* Change env.SALT=${salt} will fork into a different repo`);
24
- // console.log("PR_SRC: ", forkSSHUrl);
25
- // console.log("PR_DST: ", upstreamUrl);
26
- // console.log(forkSSHUrl);
27
- const upstream = parseUrlRepoOwner(upstreamRepoUrl);
28
- const argv = minimist(process.argv.slice(2));
29
- const salt = argv.salt || process.env.SALT || "m3KMgZ2AeZGWYh7W";
30
- const repo_hash = md5(`${salt}-${ghUser.name}-${upstream.owner}/${upstream.repo}`).slice(0, 8);
31
- const forkRepoName = (FORK_PREFIX && `${FORK_PREFIX}${upstream.repo}-${repo_hash}`) || upstream.repo;
32
- const forkDst = `${FORK_OWNER}/${forkRepoName}`;
33
- const forkUrl = `https://github.com/${forkDst}`;
34
- const forked = await createGithubFork(upstreamRepoUrl, forkUrl);
35
- if (forked.html_url !== forkUrl) DIE("forked url not expected");
36
- return forked;
37
- }
1
+ import DIE from "@snomiao/die";
2
+ import md5 from "md5";
3
+ import minimist from "minimist";
4
+ import { FORK_OWNER } from "./FORK_OWNER";
5
+ import { FORK_PREFIX } from "./FORK_PREFIX";
6
+ import { createGithubFork } from "./gh/createGithubFork";
7
+ import { ghUser } from "./ghUser";
8
+ import { parseUrlRepoOwner } from "./parseOwnerRepo";
9
+
10
+ /**
11
+ * this function creates a fork of the upstream repo,
12
+ * fork to the FORK_OWNER, and add a prefix to the repo name
13
+ * - the prefix is optional, if not provided, the repo name will be the same as the upstream repo
14
+ * - the prefix is useful to distinguish the forked repo from the other repo in the same owner
15
+ * SALT is used to generate a unique repo name, so that the forked repo will not conflict with other forks
16
+ *
17
+ * @author snomiao <snomiao@gmail.com>
18
+ * @param upstreamRepoUrl
19
+ * @returns forked repo info
20
+ */
21
+ export async function createGithubForkForRepo(upstreamRepoUrl: string) {
22
+ // debug
23
+ // console.log(`* Change env.SALT=${salt} will fork into a different repo`);
24
+ // console.log("PR_SRC: ", forkSSHUrl);
25
+ // console.log("PR_DST: ", upstreamUrl);
26
+ // console.log(forkSSHUrl);
27
+ const upstream = parseUrlRepoOwner(upstreamRepoUrl);
28
+ const argv = minimist(process.argv.slice(2));
29
+ const salt = argv.salt || process.env.SALT || "m3KMgZ2AeZGWYh7W";
30
+ const repo_hash = md5(`${salt}-${ghUser.name}-${upstream.owner}/${upstream.repo}`).slice(0, 8);
31
+ const forkRepoName = (FORK_PREFIX && `${FORK_PREFIX}${upstream.repo}-${repo_hash}`) || upstream.repo;
32
+ const forkDst = `${FORK_OWNER}/${forkRepoName}`;
33
+ const forkUrl = `https://github.com/${forkDst}`;
34
+ const forked = await createGithubFork(upstreamRepoUrl, forkUrl);
35
+ if (forked.html_url !== forkUrl) DIE("forked url not expected");
36
+ return forked;
37
+ }
@@ -1,94 +1,94 @@
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 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,29 +1,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
- }
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
+ }
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,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
+ }