Skip to content

Commit cd63ba6

Browse files
authored
Merge pull request #43 from Comfy-Org/sno-bugcop-responsed
feat: enhance gh-bugcop task with improved response handling and database integration
2 parents 497d340 + 4e7e26d commit cd63ba6

File tree

4 files changed

+54
-50
lines changed

4 files changed

+54
-50
lines changed

app/tasks/gh-bugcop/gh-bugcop.tsx

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,25 +72,26 @@ export default async function runGithubBugcopTask() {
7272
tlog("Running Github Bugcop Task...");
7373
await sflow(REPOLIST)
7474
// list issues for each repo
75-
.map((url) => {
75+
.map((repoUrl) => {
7676
// tlog(`Fetching issues for ${url}...`);
7777
return pageFlow(1, async (page) => {
7878
const { data: issues } = await hotMemo(gh.issues.listForRepo, [
7979
{
80-
...parseUrlRepoOwner(url),
80+
...parseUrlRepoOwner(repoUrl),
8181
state: "open" as const,
8282
page,
8383
per_page: 100,
8484
labels: ASKING_LABEL,
8585
},
8686
]);
87-
tlog(`Found ${issues.length} matched issues in ${url}`);
87+
tlog(`Found ${issues.length} matched issues in ${repoUrl}`);
8888
return { data: issues, next: issues.length >= 100 ? page + 1 : undefined };
89-
});
89+
})
90+
.filter((e) => e.length)
91+
.flat();
92+
// .by(flats());
9093
})
9194
.confluenceByParallel() // order does not matter, so we can run in parallel
92-
.filter((e) => e.length) // filter out empty pages
93-
.flat() // flatten the page results
9495
// .by((issueFlow) => {
9596
// const tr = new TransformStream<GH["issue"], GH["issue"]>();
9697
// const writer = tr.writable.getWriter();
@@ -170,12 +171,13 @@ export default async function runGithubBugcopTask() {
170171
]);
171172
return { data: events, next: events.length >= 100 ? page + 1 : undefined };
172173
})
174+
// flat
173175
.filter((e) => e.length)
174-
.flat()
176+
.by((s) => s.pipeThrough(flats()))
175177
.toArray();
176178

177179
// list all label events
178-
const labelEvents = await sflow(timeline)
180+
const labelEvents = await sflow([...timeline])
179181
.forEach((_e) => {
180182
if (_e.event === "labeled") {
181183
const e = _e as GH["labeled-issue-event"];
@@ -297,3 +299,15 @@ export default async function runGithubBugcopTask() {
297299
.run();
298300
tlog(chalk.green("Github Bugcop Task completed successfully!"));
299301
}
302+
303+
function flats<T>(): TransformStream<T[], T> {
304+
return new TransformStream<T[], T>({
305+
transform: (e, controller) => {
306+
e.forEach((event) => controller.enqueue(event));
307+
},
308+
flush: (controller) => {
309+
// No finalization needed
310+
// Stream will be closed automatically after flush
311+
},
312+
});
313+
}

app/tasks/gh-bugcop/page.tsx

Lines changed: 18 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,7 @@
11
import { Badge } from "@/components/ui/badge";
2-
import {
3-
Table,
4-
TableBody,
5-
TableCaption,
6-
TableCell,
7-
TableHead,
8-
TableHeader,
9-
TableRow,
10-
} from "@/components/ui/table";
2+
import { Table, TableBody, TableCaption, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table";
113
import Link from "next/link";
124
import { GithubBugcopTask } from "./gh-bugcop";
13-
// import { GithubBugcopTaskMetaEditor } from "./GithubBugcopTaskMetaEditor";
145

156
/**
167
* GitHub Bug Cop Task Dashboard
@@ -20,7 +11,6 @@ export default async function GithubBugCopTaskPage() {
2011
// Fetch all tasks from the database
2112
const tasks = await GithubBugcopTask.find({}).sort({ lastChecked: -1 }).toArray();
2213

23-
2414
const formatDate = (date: Date | string | undefined) => {
2515
if (!date) return "N/A";
2616
try {
@@ -36,7 +26,6 @@ export default async function GithubBugCopTaskPage() {
3626
}
3727
};
3828

39-
4029
const getIssueNumber = (url: string) => {
4130
const match = url.match(/\/(\d+)$/);
4231
return match?.[1] ? `#${match[1]}` : "";
@@ -60,8 +49,7 @@ export default async function GithubBugCopTaskPage() {
6049
<TableCaption>
6150
{tasks.length === 0
6251
? "No bug cop tasks found"
63-
: `A list of ${tasks.length} bug cop task${tasks.length !== 1 ? 's' : ''} being tracked`
64-
}
52+
: `A list of ${tasks.length} bug cop task${tasks.length !== 1 ? "s" : ""} being tracked`}
6553
</TableCaption>
6654
<TableHeader>
6755
<TableRow>
@@ -86,8 +74,12 @@ export default async function GithubBugCopTaskPage() {
8674
tasks.map((task: any) => (
8775
<TableRow key={task.url}>
8876
<TableCell>
89-
<Link className="text-sm text-muted-foreground outline outline-[1px] rounded-full px-2 py-1 whitespace-pre" href={`https://github.com/${task.user}`}
90-
target="_blank" rel="noopener noreferrer">
77+
<Link
78+
className="text-sm text-muted-foreground outline outline-[1px] rounded-full px-2 py-1 whitespace-pre"
79+
href={`https://github.com/${task.user}`}
80+
target="_blank"
81+
rel="noopener noreferrer"
82+
>
9183
@{task.user}
9284
</Link>
9385
</TableCell>
@@ -100,19 +92,15 @@ export default async function GithubBugCopTaskPage() {
10092
>
10193
<div className="flex items-center gap-2">
10294
<Badge className="w-16 text-center justify-center">
103-
{({ "pull_request": "PR", 'issue': "Issue" } as any)[task.type] || "Task"}
95+
{({ pull_request: "PR", issue: "Issue" } as any)[task.type] || "Task"}
10496
</Badge>
105-
<span className="text-sm text-muted-foreground">
106-
{getIssueNumber(task.url)}
107-
</span>
108-
<h3>
109-
{task.title}
110-
</h3>
97+
<span className="text-sm text-muted-foreground">{getIssueNumber(task.url)}</span>
98+
<h3>{task.title}</h3>
11199
</div>
112100
</Link>
113101
</TableCell>
114102
<TableCell className="text-center">
115-
<Badge variant={'outline'}>{task.status?.toUpperCase() || '?'}</Badge>
103+
<Badge variant={"outline"}>{task.status?.toUpperCase() || "?"}</Badge>
116104
</TableCell>
117105
<TableCell className="text-center text-sm text-muted-foreground">
118106
{formatDate(task.updatedAt)}
@@ -126,13 +114,11 @@ export default async function GithubBugCopTaskPage() {
126114
</Badge>
127115
))}
128116
</div>
129-
) : (
130-
null
131-
)}</TableCell>
117+
) : null}
118+
</TableCell>
132119
<TableCell className="text-center text-sm text-muted-foreground">
133120
{formatDate(task.lastChecked)}
134121
</TableCell>
135-
136122
</TableRow>
137123
))
138124
)}
@@ -142,9 +128,11 @@ export default async function GithubBugCopTaskPage() {
142128

143129
<div className="mt-6 text-sm text-muted-foreground">
144130
<p>
145-
{('This table shows all GitHub issues and pull requests with the "Bug Cop" label that have been processed by the automated tracking system. The system monitors repositories, sends Slack notifications, and requests reviews for bug-cop-related items.')}
131+
{
132+
'This table shows all GitHub issues and pull requests with the "Bug Cop" label that have been processed by the automated tracking system. The system monitors repositories, sends Slack notifications, and requests reviews for bug-cop-related items.'
133+
}
146134
</p>
147135
</div>
148136
</div>
149137
);
150-
}
138+
}

app/tasks/run-gh-tasks.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ import isCI from "is-ci";
44

55
// Import all the 5-minute tasks
66
import runGithubBountyTask from "./gh-bounty/gh-bounty";
7+
import runGithubBugcopTask from "./gh-bugcop/gh-bugcop";
78
import { runGithubDesignTask } from "./gh-design/gh-design";
89
import runGithubDesktopReleaseNotificationTask from "./gh-desktop-release-notification/index";
9-
import runGithubBugcopTask from "./gh-bugcop/gh-bugcop";
1010

1111
const TASKS = [
1212
{
1313
name: "GitHub Bounty Task",
1414
run: runGithubBountyTask,
1515
},
1616
{
17-
name: "GitHub Design Task",
17+
name: "GitHub Design Task",
1818
run: runGithubDesignTask,
1919
},
2020
{
@@ -29,13 +29,13 @@ const TASKS = [
2929

3030
async function runAllTasks() {
3131
console.log("=� Starting all GitHub tasks...");
32-
32+
3333
// Run all tasks concurrently using Promise.allSettled
3434
const results = await Promise.allSettled(
3535
TASKS.map(async (task) => {
3636
console.log(`� Starting: ${task.name}`);
3737
const startTime = Date.now();
38-
38+
3939
try {
4040
await task.run();
4141
const duration = Date.now() - startTime;
@@ -46,27 +46,27 @@ async function runAllTasks() {
4646
console.error(`L Failed: ${task.name} (${duration}ms)`, error);
4747
throw { name: task.name, status: "error", duration, error };
4848
}
49-
})
49+
}),
5050
);
5151

5252
// Process results
53-
const successful = results.filter(result => result.status === "fulfilled");
54-
const failed = results.filter(result => result.status === "rejected");
53+
const successful = results.filter((result) => result.status === "fulfilled");
54+
const failed = results.filter((result) => result.status === "rejected");
5555

5656
console.log(`\n=� Summary:`);
5757
console.log(`  Successful: ${successful.length}`);
5858
console.log(` L Failed: ${failed.length}`);
5959
console.log(` =� Total: ${results.length}`);
6060

6161
// Log details for successful tasks
62-
successful.forEach(result => {
62+
successful.forEach((result) => {
6363
if (result.status === "fulfilled") {
6464
console.log(`  ${result.value.name}: ${result.value.duration}ms`);
6565
}
6666
});
6767

6868
// Log details for failed tasks
69-
failed.forEach(result => {
69+
failed.forEach((result) => {
7070
if (result.status === "rejected") {
7171
const error = result.reason;
7272
console.error(` L ${error.name}: ${error.duration}ms - ${error.error?.message || error.error}`);
@@ -83,7 +83,7 @@ async function runAllTasks() {
8383
}
8484

8585
console.log("\n<� All tasks completed successfully!");
86-
86+
8787
if (isCI) {
8888
await db.close();
8989
process.exit(0);
@@ -94,4 +94,4 @@ if (import.meta.main) {
9494
await runAllTasks();
9595
}
9696

97-
export default runAllTasks;
97+
export default runAllTasks;

src/db/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ import { MongoClient } from "mongodb";
77
import sflow from "sflow";
88

99
// allow build without env
10+
if (!process.env.MONGODB_URI)
11+
console.warn("MONGODB_URI is not set, using default value. This may cause issues in production.");
1012
const MONGODB_URI = process.env.MONGODB_URI ?? "mongodb://PLEASE_SET_MONGODB_URI:27017";
1113

1214
export const mongo = await hotResource(async () => [new MongoClient(MONGODB_URI), (conn) => conn.close()]);
1315
export const db = Object.assign(mongo.db(), {
14-
close: async () => await mongo.close()
16+
close: async () => await mongo.close(),
1517
});
1618

1719
// allow db conn for 45 mins in CI env to prevent long running CI jobs

0 commit comments

Comments
 (0)