Skip to content

Commit 7d37a2a

Browse files
authored
Merge pull request #63 from Comfy-Org/sno-rename-parseUrlRepoOwner
refactor: rename parseUrlRepoOwner to parseGithubRepoUrl
2 parents 8470a00 + 89a695f commit 7d37a2a

26 files changed

+167
-170
lines changed

app/tasks/coreping/coreping.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { TaskMetaCollection } from "@/src/db/TaskMeta";
66
import type { GH } from "@/src/gh";
77
import { ghc } from "@/src/ghc";
88
import { parseIssueUrl } from "@/src/parseIssueUrl";
9-
import { parseUrlRepoOwner } from "@/src/parseOwnerRepo";
9+
import { parseGithubRepoUrl } from "@/src/parseOwnerRepo";
1010
import DIE from "@snomiao/die";
1111
import chalk from "chalk";
1212
import sflow, { pageFlow } from "sflow";
@@ -121,7 +121,7 @@ if (import.meta.main) {
121121
.flatMap((repoUrl) => [
122122
// handle opening pr and it's comments
123123
pageFlow(1, async (page, per_page = 100) => {
124-
const { data } = await ghc.pulls.list({ ...parseUrlRepoOwner(repoUrl), page, per_page, state: "open" });
124+
const { data } = await ghc.pulls.list({ ...parseGithubRepoUrl(repoUrl), page, per_page, state: "open" });
125125
return { data, next: data.length >= per_page ? page + 1 : null };
126126
})
127127
.flat()
@@ -214,13 +214,13 @@ if (import.meta.main) {
214214

215215
// // handle issue comments, (also including pr comments)
216216
// pageFlow(1, async (page, per_page = 100) => {
217-
// const { data } = await ghc.issues.listCommentsForRepo({ ...parseUrlRepoOwner(repoUrl), page, per_page });
217+
// const { data } = await ghc.issues.listCommentsForRepo({ ...parseGithubRepoUrl(repoUrl), page, per_page });
218218
// return { data, next: data.length >= per_page ? page + 1 : null };
219219
// }).flat(),
220220

221221
// // handle pr review comments
222222
// pageFlow(1, async (page, per_page = 100) => {
223-
// const { data } = await ghc.pulls.listReviewCommentsForRepo({ ...parseUrlRepoOwner(repoUrl), page, per_page });
223+
// const { data } = await ghc.pulls.listReviewCommentsForRepo({ ...parseGithubRepoUrl(repoUrl), page, per_page });
224224
// return { data, next: data.length >= per_page ? page + 1 : null };
225225
// }).flat(),
226226
])

app/tasks/gh-design/gh-design.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { db } from "@/src/db";
22
import { TaskMetaCollection } from "@/src/db/TaskMeta";
33
import { gh } from "@/src/gh";
44
import { parseIssueUrl } from "@/src/parseIssueUrl";
5-
import { parseUrlRepoOwner } from "@/src/parseOwnerRepo";
5+
import { parseGithubRepoUrl } from "@/src/parseOwnerRepo";
66
import { slack } from "@/src/slack";
77
import { getSlackChannel } from "@/src/slack/channels";
88
import DIE from "@snomiao/die";
@@ -137,7 +137,7 @@ export async function runGithubDesignTask() {
137137
// Get configuration from meta or use defaults
138138
const slackMessageTemplate = meta.slackMessageTemplate || DIE("Missing Slack message template");
139139
const designItemsFlow = await sflow(meta.repoUrls || DIE("Missing repo URLs"))
140-
.map((e) => parseUrlRepoOwner(e))
140+
.map((e) => parseGithubRepoUrl(e))
141141
.pMap(
142142
async ({ owner, repo }) =>
143143
pageFlow(1, async (page) => {

app/tasks/gh-desktop-release-notification/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { db } from "@/src/db";
22
import { gh } from "@/src/gh";
3-
import { parseUrlRepoOwner } from "@/src/parseOwnerRepo";
3+
import { parseGithubRepoUrl } from "@/src/parseOwnerRepo";
44
import { getSlackChannel } from "@/src/slack/channels";
55
import DIE from "@snomiao/die";
66
import isCI from "is-ci";
@@ -71,7 +71,7 @@ async function runGithubDesktopReleaseNotificationTask() {
7171
);
7272

7373
await sflow(config.repos)
74-
.map(parseUrlRepoOwner)
74+
.map(parseGithubRepoUrl)
7575
.flatMap(({ owner, repo }) =>
7676
gh.repos
7777
.listReleases({

app/tasks/github-contributor-analyze/githubContributorAnalyze.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { $pipeline } from "@/packages/mongodb-pipeline-ts/$pipeline";
22
import { CNRepos } from "@/src/CNRepos";
3-
import { parseUrlRepoOwner, stringifyGithubRepoUrl } from "@/src/parseOwnerRepo";
3+
import { parseGithubRepoUrl, stringifyGithubRepoUrl } from "@/src/parseOwnerRepo";
44
import { mkdir, rmdir } from "fs/promises";
55
import isCI from "is-ci";
66
import sflow from "sflow";
@@ -29,40 +29,40 @@ if (import.meta.main) {
2929
"This repository exceeded its LFS budget. The account responsible for the budget should increase it to restore access.",
3030
"Access to this repository has been disabled by GitHub staff.",
3131
];
32-
32+
3333
await sflow(
3434
GithubContributorAnalyzeTask.find({
3535
// data stale after 1day
3636
updatedAt: { $not: { $gt: new Date(Date.now() - 1000 * 60 * 60 * 24) } },
3737
}),
3838
)
39-
//filter out not retryable error
40-
.filter(e=>{
41-
if (e.error) {
42-
for (const error of notRetryableErrors) {
43-
if (e.error.match(error)) {
44-
console.log("filter out not retryable error", { repoUrl: e.repoUrl, error });
45-
return false;
39+
//filter out not retryable error
40+
.filter((e) => {
41+
if (e.error) {
42+
for (const error of notRetryableErrors) {
43+
if (e.error.match(error)) {
44+
console.log("filter out not retryable error", { repoUrl: e.repoUrl, error });
45+
return false;
46+
}
4647
}
4748
}
48-
}
49-
return true;
50-
})
51-
.filter((e) =>!e.error?.match("Repository not found")) //filter out not retryable error
49+
return true;
50+
})
51+
.filter((e) => !e.error?.match("Repository not found")) //filter out not retryable error
5252
.filter((e) => !e.error?.match("repoUrl not match")) //filter out not retryable error
5353
.filter(
5454
(e) =>
5555
!e.error?.match(
5656
"This repository exceeded its LFS budget. The account responsible for the budget should increase it to restore access.",
5757
),
58-
)
58+
)
5959
.filter((e) => !e.error?.match("Access to this repository has been disabled by GitHub staff.")) //filter out not retryable error
6060

6161
.pMap(
6262
async ({ _id, repoUrl }, index) => {
6363
console.log(`Task githubContributorAnalyze ${index}/${remain}/${total}`, { repoUrl });
6464
try {
65-
const ghurl = stringifyGithubRepoUrl(parseUrlRepoOwner(repoUrl));
65+
const ghurl = stringifyGithubRepoUrl(parseGithubRepoUrl(repoUrl));
6666
if (ghurl !== repoUrl) {
6767
console.log("repoUrl not match", { repoUrl, ghurl });
6868
throw new Error("repoUrl not match");
@@ -86,7 +86,7 @@ if (import.meta.main) {
8686
.run();
8787

8888
console.log("done");
89-
if(isCI) process.exit(0);
89+
if (isCI) process.exit(0);
9090
// Array.prototype.groupBy = function <T, K extends keyof T>(key: K) {
9191
// const arr = this;
9292
// return Object.groupBy(arr, (e) => e[key]);

app/tasks/github-contributor-analyze/summaryGithubContributorAnalyzeTask.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import { GithubContributorAnalyzeTask, GithubContributorAnalyzeTaskFilter } from
99
if (import.meta.main) {
1010
// analyze
1111
await summaryGithubContributorAnalyzeTask();
12-
13-
if(isCI) process.exit(0);
12+
13+
if (isCI) process.exit(0);
1414
}
1515

1616
export async function summaryGithubContributorAnalyzeTask() {
@@ -28,7 +28,7 @@ export async function summaryGithubContributorAnalyzeTask() {
2828
email,
2929
commitCount: sum(e!.map((e) => e!.count)),
3030
// repos: e!
31-
// .map((e) => stringifyGithubRepoUrl(parseUrlRepoOwner(e!.repoUrl)).slice("https://github.com".length))
31+
// .map((e) => stringifyGithubRepoUrl(parseGithubRepoUrl(e!.repoUrl)).slice("https://github.com".length))
3232
// .join(" "),
3333
repoCount: uniq(e!.map((e) => e!.repoUrl)).length,
3434
usernameCount: uniq(e!.map((e) => e!.name)).length,
@@ -48,10 +48,10 @@ export async function summaryGithubContributorAnalyzeTask() {
4848
allRepoCount: uniq(data.map((e) => e.repoUrl)).length,
4949
usernameCount: sum(json.map((e) => e.usernameCount)),
5050

51-
cloneableRepoCount: data.length - remains
51+
cloneableRepoCount: data.length - remains,
5252
};
5353
console.log(total);
54-
const date = new Date().toISOString().slice(0, 10) ;
54+
const date = new Date().toISOString().slice(0, 10);
5555
await globalThis.Bun?.write(`./report/uniq-contributor-emails.csv`, d3.csvFormat(json));
5656
await globalThis.Bun?.write(`./report/uniq-contributor-emails-total.yaml`, yaml.stringify(total));
5757
await globalThis.Bun?.write(`./report/${date}-uniq-contributor-emails.csv`, d3.csvFormat(json));

run/easylabel.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { db } from "@/src/db";
33
import { gh, type GH } from "@/src/gh";
44
import { ghc } from "@/src/ghc";
55
import { parseIssueUrl } from "@/src/parseIssueUrl";
6-
import { parseUrlRepoOwner } from "@/src/parseOwnerRepo";
6+
import { parseGithubRepoUrl } from "@/src/parseOwnerRepo";
77
import DIE from "@snomiao/die";
88
import chalk from "chalk";
99
import sflow, { pageFlow } from "sflow";
@@ -67,7 +67,7 @@ async function runLabelOpInitializeScan() {
6767
await sflow(cfg.REPOLIST)
6868
.flatMap((repoUrl) => [
6969
pageFlow(1, async (page, per_page = 100) => {
70-
const { data } = await ghc.issues.list({ ...parseUrlRepoOwner(repoUrl), page, per_page, state: "open" });
70+
const { data } = await ghc.issues.list({ ...parseGithubRepoUrl(repoUrl), page, per_page, state: "open" });
7171
return { data, next: data.length >= per_page ? page + 1 : null };
7272
})
7373
.flat()

run/gh-bugcop/gh-bugcop.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { db } from "@/src/db";
1010
import { TaskMetaCollection } from "@/src/db/TaskMeta";
1111
import { gh, type GH } from "@/src/gh";
1212
import { parseIssueUrl } from "@/src/parseIssueUrl";
13-
import { parseUrlRepoOwner } from "@/src/parseOwnerRepo";
13+
import { parseGithubRepoUrl } from "@/src/parseOwnerRepo";
1414
import KeyvSqlite from "@keyv/sqlite";
1515
import DIE from "@snomiao/die";
1616
import chalk from "chalk";
@@ -102,7 +102,7 @@ export default async function runGithubBugcopTask() {
102102
pageFlow(1, async (page) => {
103103
const { data: issues } = await hotMemo(gh.issues.listForRepo, [
104104
{
105-
...parseUrlRepoOwner(repoUrl),
105+
...parseGithubRepoUrl(repoUrl),
106106
state: "open" as const,
107107
page,
108108
per_page: 100,

run/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { match, P } from "ts-pattern";
77
import { type UnionToIntersection } from "type-fest";
88
import { gh, type GH } from "../src/gh/index.js";
99
import { ghc } from "../src/ghc.js";
10-
import { parseUrlRepoOwner } from "../src/parseOwnerRepo.js";
10+
import { parseGithubRepoUrl } from "../src/parseOwnerRepo.js";
1111
import { processIssueCommentForLableops } from "./easylabel";
1212
import type { WEBHOOK_EVENT } from "./github-webhook-event-type";
1313
export const REPOLIST = [
@@ -349,7 +349,7 @@ class RepoEventMonitor {
349349
private async checkPollingRepos() {
350350
sflow(this.pollingRepos).map((html_url) => {
351351
pageFlow(1, async (page, per_page = 100) => {
352-
const { data } = await ghc.issues.listForRepo({ ...parseUrlRepoOwner(html_url), page, per_page });
352+
const { data } = await ghc.issues.listForRepo({ ...parseGithubRepoUrl(html_url), page, per_page });
353353
return { data, next: data.length >= per_page ? page + 1 : null };
354354
}).flat();
355355
});

src/GithubActionUpdateTask/updateGithubActionPrepareBranch.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,21 @@ import { readFile, writeFile } from "fs/promises";
33
import { globby } from "globby";
44
import pProps from "p-props";
55
import { $ } from "../cli/echoBunShell";
6-
import { parseUrlRepoOwner, stringifyGithubOrigin } from "../parseOwnerRepo";
6+
import { parseGithubRepoUrl, stringifyGithubOrigin } from "../parseOwnerRepo";
77
import { parseTitleBodyOfMarkdown } from "../parseTitleBodyOfMarkdown";
88
import { yaml } from "../utils/yaml";
99
import { forkCheckoutRepoOnBranch } from "./forkCheckoutRepoOnBranch";
1010
import { gptWriter } from "./gptWriter";
1111
import {
12-
referenceActionContent,
13-
referenceActionContentHash,
14-
referencePullRequestMessage,
12+
referenceActionContent,
13+
referenceActionContentHash,
14+
referencePullRequestMessage,
1515
} from "./updateGithubActionTask";
1616
export const updateGithubActionPrepareBranchBanPatterns = [
1717
/if: \${{ github.repository_owner == 'NODE_AUTHOR_OWNER' }}/,
1818
/- master/,
1919
/submodules: true/,
20-
/\+ personal_access_token: \${{ secrets.REGISTRY_ACCESS_TOKEN }}/
20+
/\+ personal_access_token: \${{ secrets.REGISTRY_ACCESS_TOKEN }}/,
2121
];
2222
export async function updateGithubActionPrepareBranch(repo: string) {
2323
console.log(`$ updateGithubActionPrepareBranch("${repo}")`);
@@ -48,7 +48,7 @@ export async function updateGithubActionPrepareBranch(repo: string) {
4848
{ role: "developer", content: "$ read Pull Request message template" },
4949
{ role: "function", name: "read", content: referencePullRequestMessage },
5050
{ role: "developer", content: "$ read NODE_AUTHOR_OWNER" },
51-
{ role: "function", name: "read", content: parseUrlRepoOwner(repo).owner },
51+
{ role: "function", name: "read", content: parseGithubRepoUrl(repo).owner },
5252
{
5353
role: "user",
5454
content:
@@ -117,7 +117,7 @@ export async function updateGithubActionPrepareBranch(repo: string) {
117117
},
118118
]),
119119
});
120-
const origin = await stringifyGithubOrigin(parseUrlRepoOwner(html_url));
120+
const origin = await stringifyGithubOrigin(parseGithubRepoUrl(html_url));
121121
await $`cd ${cwd} && git add . && git commit -am ${commitMessage} && git push -f ${origin} ${branch}`;
122122
// ensure pr message is parsable
123123
const { title, body } = parseTitleBodyOfMarkdown(pullRequestMessage);

src/createComfyRegistryPRsFromCandidates.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { $OK, TaskError, TaskOK } from "../packages/mongodb-pipeline-ts/Task";
55
import { CNRepos } from "./CNRepos";
66
import { createComfyRegistryPullRequests } from "./createComfyRegistryPullRequests";
77
import { $flatten, $stale } from "./db";
8-
import { parseUrlRepoOwner, stringifyOwnerRepo } from "./parseOwnerRepo";
8+
import { parseGithubRepoUrl, stringifyOwnerRepo } from "./parseOwnerRepo";
99
import { notifySlackLinks } from "./slack/notifySlackLinks";
1010
import { tLog } from "./utils/tLog";
1111
if (import.meta.main) {
@@ -36,7 +36,7 @@ export async function createComfyRegistryPRsFromCandidates() {
3636
match(createdPulls).with($OK, async ({ data }) => {
3737
const links = data.map((e) => ({
3838
href: e.html_url,
39-
name: stringifyOwnerRepo(parseUrlRepoOwner(e.html_url.replace(/\/pull\/.*$/, ""))) + " #" + e.title,
39+
name: stringifyOwnerRepo(parseGithubRepoUrl(e.html_url.replace(/\/pull\/.*$/, ""))) + " #" + e.title,
4040
}));
4141
await notifySlackLinks("PR Created", links);
4242
await pMap(data, async (pull) => {

0 commit comments

Comments
 (0)