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
@@ -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,76 @@
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
- author_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
- .partial()
73
- .strict(),
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
+ 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,18 +1,18 @@
1
- import { $ as zx } from "zx";
2
- import { getActivateCMD } from "./cli/getActivateCMD";
3
-
4
- if (import.meta.main) {
5
- // await checkComfyActivated();
6
- zx.verbose = true;
7
- const $ = getActivatedShell();
8
- const p = await $`comfy-cli --version`;
9
- console.log(p.stdout);
10
- // zx({ prefix: })`comfy-cli --help`;
11
- }
12
-
13
- export function getActivatedShell() {
14
- const activate = getActivateCMD();
15
- return zx({
16
- prefix: `echo Comfy CLI version: $(comfy-cli --version) || (apt-get install -y python3-venv && python -m venv .venv && ${activate} && pip install comfy-cli); `,
17
- });
18
- }
1
+ import { $ as zx } from "zx";
2
+ import { getActivateCMD } from "./cli/getActivateCMD";
3
+
4
+ if (import.meta.main) {
5
+ // await checkComfyActivated();
6
+ zx.verbose = true;
7
+ const $ = getActivatedShell();
8
+ const p = await $`comfy-cli --version`;
9
+ console.log(p.stdout);
10
+ // zx({ prefix: })`comfy-cli --help`;
11
+ }
12
+
13
+ export function getActivatedShell() {
14
+ const activate = getActivateCMD();
15
+ return zx({
16
+ prefix: `echo Comfy CLI version: $(comfy-cli --version) || (apt-get install -y python3-venv && python -m venv .venv && ${activate} && pip install comfy-cli); `,
17
+ });
18
+ }
@@ -1,16 +1,16 @@
1
- import { rm } from "fs/promises";
2
- import { getRepoWorkingDir } from "./getRepoWorkingDir";
3
- import { parseUrlRepoOwner } from "./parseOwnerRepo";
4
-
5
- export async function getBranchWorkingDir(
6
- upstreamUrl: string,
7
- forkUrl: string,
8
- branch: string
9
- ) {
10
- const src = parseUrlRepoOwner(upstreamUrl);
11
- const dir = getRepoWorkingDir(forkUrl);
12
- const packageName = src.repo;
13
- const cwd = `${dir}/${branch}/${packageName}`;
14
- await rm(cwd, { recursive: true }).catch(() => null);
15
- return cwd;
16
- }
1
+ import { rm } from "fs/promises";
2
+ import { getRepoWorkingDir } from "./getRepoWorkingDir";
3
+ import { parseUrlRepoOwner } from "./parseOwnerRepo";
4
+
5
+ export async function getBranchWorkingDir(
6
+ upstreamUrl: string,
7
+ forkUrl: string,
8
+ branch: string
9
+ ) {
10
+ const src = parseUrlRepoOwner(upstreamUrl);
11
+ const dir = getRepoWorkingDir(forkUrl);
12
+ const packageName = src.repo;
13
+ const cwd = `${dir}/${branch}/${packageName}`;
14
+ await rm(cwd, { recursive: true }).catch(() => null);
15
+ return cwd;
16
+ }
@@ -1,6 +1,6 @@
1
- import { parseUrlRepoOwner } from "./parseOwnerRepo";
2
-
3
- export function getRepoWorkingDir(forkUrl: string) {
4
- return `prs/${parseUrlRepoOwner(forkUrl).repo}`;
5
- }
1
+ import { parseUrlRepoOwner } from "./parseOwnerRepo";
2
+
3
+ export function getRepoWorkingDir(forkUrl: string) {
4
+ return `prs/${parseUrlRepoOwner(forkUrl).repo}`;
5
+ }
6
6
 
package/src/ghUser.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { gh } from "./gh";
2
-
3
- export const ghUser = (await gh.users.getAuthenticated()).data;
4
-
5
- console.log("Fetch Current Github User...");
6
- console.log(`Current Github User: ${ghUser.login} <${ghUser.email}>`);
1
+ import { gh } from "./gh";
2
+
3
+ export const ghUser = (await gh.users.getAuthenticated()).data;
4
+
5
+ console.log("Fetch Current Github User...");
6
+ console.log(`Current Github User: ${ghUser.login} <${ghUser.email}>`);
package/src/index.ts CHANGED
@@ -1,21 +1,22 @@
1
- #!/usr/bin/env bun
2
- import "dotenv/config";
3
- import { checkComfyActivated } from "./checkComfyActivated";
4
- import { initializeFollowRules } from "./initializeFollowRules";
5
- import { updateCNRepos } from "./updateCNRepos";
6
- import { runFollowRuleSet } from "./updateFollowRuleSet";
7
- import { updateSlackMessages } from "./updateSlackMessages";
8
- import { tLog } from "./utils/tLog";
9
-
10
- if (import.meta.main) {
11
- await Promise.all([
12
- // try send msgs that didn't send in last run
13
- updateSlackMessages(),
14
- checkComfyActivated(), // needed if make pr
15
- updateCNRepos(),
16
- ]);
17
- await initializeFollowRules();
18
- await tLog("runFollowRuleSet", runFollowRuleSet);
19
- console.log("All done");
20
- process.exit(0);
21
- }
1
+ import "dotenv/config";
2
+ import { checkComfyActivated } from "./checkComfyActivated";
3
+ import { initializeFollowRules } from "./initializeFollowRules";
4
+ import { updateAuthors } from "./updateAuthors";
5
+ import { updateCNRepos } from "./updateCNRepos";
6
+ import { runFollowRuleSet } from "./updateFollowRuleSet";
7
+ import { updateSlackMessages } from "./updateSlackMessages";
8
+ import { tLog } from "./utils/tLog";
9
+
10
+ if (import.meta.main) {
11
+ await Promise.all([
12
+ // try send msgs that didn't send in last run
13
+ updateSlackMessages(),
14
+ checkComfyActivated(), // needed if make pr
15
+ updateCNRepos(),
16
+ updateAuthors(),
17
+ ]);
18
+ await initializeFollowRules();
19
+ await tLog("runFollowRuleSet", runFollowRuleSet);
20
+ console.log("All done");
21
+ process.exit(0);
22
+ }
@@ -1,26 +1,26 @@
1
- import DIE from "@snomiao/die";
2
- import { readFile } from "fs/promises";
3
- import { FollowRuleSets } from "./FollowRules";
4
-
5
- if (import.meta.main) {
6
- const followRules = await initializeFollowRules();
7
- const ruleset = (await FollowRuleSets.findOne({ name: "default" })) ?? DIE("default ruleset not found");
8
- if (!ruleset?.enabled) DIE("default ruleset not enabled");
9
-
10
- console.log("initialized follow rules");
11
- }
12
- /**
13
- *
14
- * @author: snomiao <snomiao@gmail.com>
15
- */
16
- export async function initializeFollowRules() {
17
- return await updateFollowRules("default", await readFile("./templates/follow-rules.yaml", "utf8"));
18
- }
19
-
20
- export async function updateFollowRules(name: string, rawRuleYaml: string) {
21
- return (await FollowRuleSets.findOneAndUpdate(
22
- { name },
23
- { $setOnInsert: { yaml: rawRuleYaml, enabled: false } },
24
- { upsert: true, returnDocument: "after" },
25
- ))!;
26
- }
1
+ import DIE from "@snomiao/die";
2
+ import { readFile } from "fs/promises";
3
+ import { FollowRuleSets } from "./FollowRules";
4
+
5
+ if (import.meta.main) {
6
+ const followRules = await initializeFollowRules();
7
+ const ruleset = (await FollowRuleSets.findOne({ name: "default" })) ?? DIE("default ruleset not found");
8
+ if (!ruleset?.enabled) DIE("default ruleset not enabled");
9
+
10
+ console.log("initialized follow rules");
11
+ }
12
+ /**
13
+ *
14
+ * @author: snomiao <snomiao@gmail.com>
15
+ */
16
+ export async function initializeFollowRules() {
17
+ return await updateFollowRules("default", await readFile("./templates/follow-rules.yaml", "utf8"));
18
+ }
19
+
20
+ export async function updateFollowRules(name: string, rawRuleYaml: string) {
21
+ return (await FollowRuleSets.findOneAndUpdate(
22
+ { name },
23
+ { $setOnInsert: { yaml: rawRuleYaml, enabled: false } },
24
+ { upsert: true, returnDocument: "after" },
25
+ ))!;
26
+ }
@@ -1,58 +1,58 @@
1
- import { readFile } from "fs/promises";
2
- import { dirname } from "path";
3
- import { GIT_USEREMAIL } from "./GIT_USEREMAIL";
4
- import { GIT_USERNAME } from "./GIT_USERNAME";
5
- import { $ } from "./cli/echoBunShell";
6
- import { getBranchWorkingDir } from "./getBranchWorkingDir";
7
- import { gh } from "./gh";
8
- import { parseUrlRepoOwner, stringifyGithubOrigin, stringifyGithubRepoUrl } from "./parseOwnerRepo";
9
- import { parseTitleBodyOfMarkdown } from "./parseTitleBodyOfMarkdown";
10
-
11
- /**
12
- * Clone from upstream
13
- * push to fork url
14
- * @param dir
15
- * @param upstreamUrl
16
- * @param origin
17
- * @returns
18
- */
19
- export async function makePublishcrBranch(upstreamUrl: string, forkUrl: Readonly<string>) {
20
- const type = "publishcr" as const;
21
-
22
- const origin = await stringifyGithubOrigin(parseUrlRepoOwner(forkUrl));
23
- const branch = "publish";
24
- const tmpl = await readFile("./templates/add-action.md", "utf8");
25
- const { title, body } = parseTitleBodyOfMarkdown(tmpl);
26
- const repo = parseUrlRepoOwner(origin);
27
-
28
- if (await gh.repos.getBranch({ ...repo, branch }).catch(() => null)) {
29
- console.log("Skip changes as branch existed: " + branch);
30
- return { type, title, body, branch };
31
- }
32
-
33
- const cwd = await getBranchWorkingDir(upstreamUrl, forkUrl, branch);
34
-
35
- const file = `${cwd}/.github/workflows/publish.yml`;
36
- const publishYmlPath = "./templates/publish.yaml";
37
-
38
- // commit & push changes
39
- await $`
40
- git clone ${upstreamUrl} ${cwd}
41
-
42
- mkdir -p ${dirname(file)}
43
- cat ${publishYmlPath} > ${file}
44
-
45
- cd ${cwd}
46
-
47
- git config user.name ${GIT_USERNAME} && \
48
- git config user.email ${GIT_USEREMAIL} && \
49
- git checkout -b ${branch} && \
50
- git add . && \
51
- git commit -am "chore(${branch}): ${title}" && \
52
- git push "${origin}" ${branch}:${branch}
53
- `;
54
-
55
- const branchUrl = `${stringifyGithubRepoUrl(repo)}/tree/${branch}`;
56
- console.log(`Branch Push OK: ${branchUrl}`);
57
- return { type, title, body, branch };
58
- }
1
+ import { readFile } from "fs/promises";
2
+ import { dirname } from "path";
3
+ import { GIT_USEREMAIL } from "./GIT_USEREMAIL";
4
+ import { GIT_USERNAME } from "./GIT_USERNAME";
5
+ import { $ } from "./cli/echoBunShell";
6
+ import { getBranchWorkingDir } from "./getBranchWorkingDir";
7
+ import { gh } from "./gh";
8
+ import { parseUrlRepoOwner, stringifyGithubOrigin, stringifyGithubRepoUrl } from "./parseOwnerRepo";
9
+ import { parseTitleBodyOfMarkdown } from "./parseTitleBodyOfMarkdown";
10
+
11
+ /**
12
+ * Clone from upstream
13
+ * push to fork url
14
+ * @param dir
15
+ * @param upstreamUrl
16
+ * @param origin
17
+ * @returns
18
+ */
19
+ export async function makePublishcrBranch(upstreamUrl: string, forkUrl: Readonly<string>) {
20
+ const type = "publishcr" as const;
21
+
22
+ const origin = await stringifyGithubOrigin(parseUrlRepoOwner(forkUrl));
23
+ const branch = "publish";
24
+ const tmpl = await readFile("./templates/add-action.md", "utf8");
25
+ const { title, body } = parseTitleBodyOfMarkdown(tmpl);
26
+ const repo = parseUrlRepoOwner(origin);
27
+
28
+ if (await gh.repos.getBranch({ ...repo, branch }).catch(() => null)) {
29
+ console.log("Skip changes as branch existed: " + branch);
30
+ return { type, title, body, branch };
31
+ }
32
+
33
+ const cwd = await getBranchWorkingDir(upstreamUrl, forkUrl, branch);
34
+
35
+ const file = `${cwd}/.github/workflows/publish.yml`;
36
+ const publishYmlPath = "./templates/publish.yaml";
37
+
38
+ // commit & push changes
39
+ await $`
40
+ git clone ${upstreamUrl} ${cwd}
41
+
42
+ mkdir -p ${dirname(file)}
43
+ cat ${publishYmlPath} > ${file}
44
+
45
+ cd ${cwd}
46
+
47
+ git config user.name ${GIT_USERNAME} && \
48
+ git config user.email ${GIT_USEREMAIL} && \
49
+ git checkout -b ${branch} && \
50
+ git add . && \
51
+ git commit -am "chore(${branch}): ${title}" && \
52
+ git push "${origin}" ${branch}:${branch}
53
+ `;
54
+
55
+ const branchUrl = `${stringifyGithubRepoUrl(repo)}/tree/${branch}`;
56
+ console.log(`Branch Push OK: ${branchUrl}`);
57
+ return { type, title, body, branch };
58
+ }