comfy-pr 0.2.24 → 0.2.25

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 (81) hide show
  1. package/CHANGELOG.md +385 -0
  2. package/README.md +225 -225
  3. package/next-env.d.ts +5 -5
  4. package/package.json +12 -2
  5. package/src/Authors.ts +48 -48
  6. package/src/CMNodes.ts +60 -60
  7. package/src/CNRepos.ts +75 -74
  8. package/src/CRNodes.ts +27 -27
  9. package/src/CRPulls.ts +4 -4
  10. package/src/EmailTasks.ts +100 -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 +193 -170
  23. package/src/analyzeTotals.test.ts +5 -5
  24. package/src/analyzeTotals.ts +118 -118
  25. package/src/checkComfyActivated.ts +39 -39
  26. package/src/cli.ts +40 -40
  27. package/src/clone_modify_push_Branches.ts +21 -21
  28. package/src/createComfyRegistryPRsFromCandidates.ts +55 -55
  29. package/src/createComfyRegistryPullRequests.ts +22 -22
  30. package/src/createGithubForkForRepo.ts +40 -37
  31. package/src/createGithubPullRequest.ts +94 -94
  32. package/src/createIssueComment.ts +29 -29
  33. package/src/fetchCMNodes.ts +22 -22
  34. package/src/fetchComfyRegistryNodes.ts +11 -11
  35. package/src/fetchCurrentGeoInfo.ts +6 -6
  36. package/src/fetchRelatedPullWithComments.ts +15 -15
  37. package/src/fetchRepoDescriptionMap.ts +15 -15
  38. package/src/followRuleSchema.ts +78 -76
  39. package/src/getActivatedShell.ts +18 -18
  40. package/src/getBranchWorkingDir.ts +16 -16
  41. package/src/getRepoWorkingDir.ts +5 -5
  42. package/src/ghUser.ts +6 -6
  43. package/src/index.ts +24 -22
  44. package/src/initializeFollowRules.ts +26 -26
  45. package/src/makePublishBranch.ts +58 -58
  46. package/src/makeTomlBranch.ts +53 -53
  47. package/src/matchRelatedPulls.ts +60 -60
  48. package/src/muteInstances.ts +16 -16
  49. package/src/parseIssueUrl.ts +6 -6
  50. package/src/parseOwnerRepo.ts +33 -33
  51. package/src/parsePullUrl.ts +6 -6
  52. package/src/parsePullsState.ts +6 -6
  53. package/src/parseTitleBodyOfMarkdown.ts +8 -8
  54. package/src/postSlackMessage.ts +21 -21
  55. package/src/preload.ts +30 -30
  56. package/src/pullStatusFollowSchema.ts +12 -12
  57. package/src/readTemplateTitle.ts +11 -11
  58. package/src/sendEmailAction.ts +56 -0
  59. package/src/sendGmail.ts +104 -0
  60. package/src/showFollowRuleSet.ts +12 -12
  61. package/src/summaryLastPullComment.ts +8 -8
  62. package/src/tomlFillDescription.ts +17 -17
  63. package/src/updateAuthors.ts +7 -7
  64. package/src/updateAuthorsForGithub.ts +54 -50
  65. package/src/updateAuthorsFromCNRepo.ts +30 -30
  66. package/src/updateCMNodesDuplicationWarnings.ts +56 -56
  67. package/src/updateCMRepos.ts +27 -27
  68. package/src/updateCNRepos.ts +58 -58
  69. package/src/updateCNReposCRPullsComments.ts +40 -40
  70. package/src/updateCNReposInfo.ts +57 -57
  71. package/src/updateCNReposPRCandidate.ts +85 -85
  72. package/src/updateCNReposPulls.ts +28 -28
  73. package/src/updateCNReposPullsDashboard.ts +49 -49
  74. package/src/updateCNReposRelatedPulls.ts +25 -25
  75. package/src/updateCRNodes.ts +50 -50
  76. package/src/updateCRRepos.ts +26 -26
  77. package/src/updateComfyTotals.ts +43 -43
  78. package/src/updateFollowRuleSet.ts +137 -127
  79. package/src/updateOutdatedPullsTemplates.ts +160 -160
  80. package/src/updateSlackMessages.ts +43 -43
  81. package/tailwind.config.ts +20 -20
@@ -1,39 +1,39 @@
1
- import DIE from "@snomiao/die";
2
- import { $ as bunSh } from "bun";
3
- import { os } from "zx";
4
- import { getActivateCMD } from "./cli/getActivateCMD";
5
-
6
- export async function checkComfyActivated() {
7
- console.log("Checking ComfyUI Activated...");
8
-
9
- if (!(await bunSh`comfy --help`.quiet().catch(() => null))) {
10
- const activate = getActivateCMD();
11
- // apt-get install -y python3 python3-venv
12
- const installPython =
13
- os.platform() === "win32"
14
- ? "python3 --version || winget install python3 || choco install -y python3"
15
- : "apt-get install -y python3 python3-venv";
16
-
17
- await bunSh`
18
- ${installPython}
19
- python -m venv .venv
20
- ${activate}
21
- pip install comfy-cli
22
- comfy-cli --help
23
- `.catch(console.error);
24
-
25
- DIE(
26
- `
27
- Cound not found comfy-cli.
28
- Please install comfy-cli before run "bunx comfy-pr" here.
29
-
30
- $ >>>>>>>>>>>>>>>>>>>>>>>>>>
31
- ${installPython}
32
- python -m venv .venv
33
- ${activate}
34
- pip install comfy-cli
35
- comfy-cli --help
36
- `.trim(),
37
- );
38
- }
39
- }
1
+ import DIE from "@snomiao/die";
2
+ import { $ as bunSh } from "bun";
3
+ import { os } from "zx";
4
+ import { getActivateCMD } from "./cli/getActivateCMD";
5
+
6
+ export async function checkComfyActivated() {
7
+ console.log("Checking ComfyUI Activated...");
8
+
9
+ if (!(await bunSh`comfy --help`.quiet().catch(() => null))) {
10
+ const activate = getActivateCMD();
11
+ // apt-get install -y python3 python3-venv
12
+ const installPython =
13
+ os.platform() === "win32"
14
+ ? "python3 --version || winget install python3 || choco install -y python3"
15
+ : "apt-get install -y python3 python3-venv";
16
+
17
+ await bunSh`
18
+ ${installPython}
19
+ python -m venv .venv
20
+ ${activate}
21
+ pip install comfy-cli
22
+ comfy-cli --help
23
+ `.catch(console.error);
24
+
25
+ DIE(
26
+ `
27
+ Cound not found comfy-cli.
28
+ Please install comfy-cli before run "bunx comfy-pr" here.
29
+
30
+ $ >>>>>>>>>>>>>>>>>>>>>>>>>>
31
+ ${installPython}
32
+ python -m venv .venv
33
+ ${activate}
34
+ pip install comfy-cli
35
+ comfy-cli --help
36
+ `.trim(),
37
+ );
38
+ }
39
+ }
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,40 @@
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)
36
+ DIE(
37
+ "forked url not expected, it's likely you already forked this repo in your account before, and now trying to fork it again with different salt. To recovery you could delete that repo forked before by manual. (the repo forked before is listed in FORK OK: .....)",
38
+ );
39
+ return forked;
40
+ }
@@ -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
+ }