1
+ #!/usr/bin/env bun
1
2
import { tsmatch } from "@/packages/mongodb-pipeline-ts/Task" ;
2
3
import { db } from "@/src/db" ;
3
4
import { gh , type GH } from "@/src/gh" ;
@@ -20,15 +21,14 @@ import sflow, { pageFlow } from "sflow";
20
21
* Add a label: Send a comment with "+label:[name]" (must have no space)
21
22
* Remove a label: Send a comment with "-label:[name]" (must have no space)
22
23
*
23
- * Bugcop:
24
24
*/
25
25
26
26
const cfg = {
27
27
REPOLIST : [
28
- "https://github.com/Comfy-Org/Comfy-PR" ,
29
28
"https://github.com/comfyanonymous/ComfyUI" ,
30
- "https://github.com/Comfy-Org/ComfyUI_frontend" ,
31
- "https://github.com/Comfy-Org/desktop" ,
29
+ // "https://github.com/Comfy-Org/Comfy-PR", // handled by webhook
30
+ // "https://github.com/Comfy-Org/ComfyUI_frontend", // handled by webhook
31
+ // "https://github.com/Comfy-Org/desktop", // handled by webhook
32
32
] ,
33
33
// allow all users to edit bugcop:*, area:*, Core-*, labels
34
34
allow : [ / ^ (?: C o r e | C o r e - .* ) $ / , / ^ (?: b u g - c o p | a r e a ) : .* $ / ] ,
@@ -54,6 +54,35 @@ const saveTask = async (task: Partial<GithubIssueLabelOps> & { target_url: strin
54
54
55
55
if ( import . meta. main ) {
56
56
await runLabelOpInitializeScan ( ) ;
57
+ await runLabelOpPolling ( ) ;
58
+ }
59
+ async function runLabelOpPolling ( ) {
60
+ console . log ( chalk . bgBlue ( "Start Label Ops Polling..." ) ) ;
61
+ // every 5s, check recent new comments for repo for 1min
62
+ while ( true ) {
63
+ await sflow ( cfg . REPOLIST )
64
+ . map ( ( repoUrl ) =>
65
+ pageFlow ( 1 , async ( page , per_page = 100 ) => {
66
+ console . log ( `Listing issue comments for recent 5min` ) ;
67
+ const { data } = await gh . issues . listCommentsForRepo ( {
68
+ ...parseGithubRepoUrl ( repoUrl ) ,
69
+ page,
70
+ per_page,
71
+ since : new Date ( Date . now ( ) - 5 * 60 * 1000 ) . toISOString ( ) ,
72
+ } ) ;
73
+ return { data, next : data . length >= per_page ? page + 1 : null } ;
74
+ } ) . flat ( ) ,
75
+ )
76
+ . confluenceByParallel ( )
77
+ . forEach ( async ( comment ) => {
78
+ console . log ( comment . html_url ) ;
79
+ const issue = await ghc . issues . get ( { ...parseIssueUrl ( comment . html_url ) } ) ;
80
+ await processIssueCommentForLableops ( { issue : issue . data , comment } ) ;
81
+ } )
82
+ . run ( ) ;
83
+ console . log ( chalk . blue ( "Sleep 5s" ) ) ;
84
+ await new Promise ( ( r ) => setTimeout ( r , 5000 ) ) ;
85
+ }
57
86
}
58
87
/**
59
88
* Scan all issues/prs and it's comments, and process them for label operations.
@@ -64,26 +93,35 @@ if (import.meta.main) {
64
93
*
65
94
*/
66
95
async function runLabelOpInitializeScan ( ) {
96
+ console . log ( chalk . bgBlue ( "Start Label Ops Initialization Scan..." ) ) ;
67
97
await sflow ( cfg . REPOLIST )
68
- . flatMap ( ( repoUrl ) => [
98
+ . map ( ( repoUrl ) =>
69
99
pageFlow ( 1 , async ( page , per_page = 100 ) => {
70
- const { data } = await ghc . issues . list ( { ...parseGithubRepoUrl ( repoUrl ) , page, per_page, state : "open" } ) ;
100
+ console . log ( `Listing issues for ${ repoUrl } page ${ page } ` ) ;
101
+ const { data } = await ghc . issues . listForRepo ( {
102
+ ...parseGithubRepoUrl ( repoUrl ) ,
103
+ page,
104
+ per_page,
105
+ state : "open" ,
106
+ } ) ;
107
+ console . log ( `Fetched ${ data . length } issues from ${ repoUrl } page ${ page } ` ) ;
108
+ return { data, next : data . length >= per_page ? page + 1 : null } ;
109
+ } ) . flat ( ) ,
110
+ )
111
+ . confluenceByParallel ( )
112
+ . map ( async ( issue ) => {
113
+ console . log ( `+issue ${ issue . html_url } with ${ issue . comments } comments` ) ;
114
+ if ( ! issue . comments ) return ;
115
+ await pageFlow ( 1 , async ( page , per_page = 100 ) => {
116
+ const { data } = await ghc . issues . listComments ( { ...parseIssueUrl ( issue . html_url ) , page, per_page } ) ;
71
117
return { data, next : data . length >= per_page ? page + 1 : null } ;
72
118
} )
73
119
. flat ( )
74
- . map ( async ( issue ) => {
75
- // processIssueComment({issue});
76
- if ( ! issue . comments ) return ;
77
- await pageFlow ( 1 , async ( page , per_page = 100 ) => {
78
- const { data } = await ghc . issues . listComments ( { ...parseIssueUrl ( issue . html_url ) , page, per_page } ) ;
79
- return { data, next : data . length >= per_page ? page + 1 : null } ;
80
- } )
81
- . flat ( )
82
- . forEach ( ( comment ) => processIssueCommentForLableops ( { issue, comment } ) )
83
- . run ( ) ;
84
- } ) ,
85
- ] )
120
+ . forEach ( ( comment ) => processIssueCommentForLableops ( { issue, comment } ) )
121
+ . run ( ) ;
122
+ } )
86
123
. run ( ) ;
124
+ console . log ( chalk . bgBlue ( "Label Ops Polling Done." ) ) ;
87
125
}
88
126
89
127
/**
@@ -94,15 +132,15 @@ export async function processIssueCommentForLableops({
94
132
comment,
95
133
} : {
96
134
issue : GH [ "issue" ] ;
97
- comment : GH [ "issue-comment" ] | null ;
135
+ comment ? : GH [ "issue-comment" ] | null ;
98
136
} ) {
99
137
const target = comment || issue ;
138
+ console . log ( " +COMMENT " + target . html_url + " len:" + target . body ?. length ) ;
100
139
let task = await saveTask ( {
101
140
target_url : target . html_url ,
102
141
issue_url : issue . html_url ,
103
142
type : comment ? "issue-comment" : "issue" ,
104
143
} ) ;
105
- console . log ( issue . html_url , target . body ?. length ) ;
106
144
if ( task ?. processed_at && + new Date ( target . updated_at ) <= + task . processed_at ) return null ; // skip if processed
107
145
if ( ! target . body ) return task ;
108
146
@@ -121,7 +159,10 @@ export async function processIssueCommentForLableops({
121
159
122
160
if ( ! labelOps . length ) return saveTask ( { target_url : target . html_url , processed_at : new Date ( ) } ) ;
123
161
124
- console . log ( "Adding reaction" ) ;
162
+ console . log ( "Found a matched Target URL:" , target . html_url , labelOps . map ( ( e ) => e . op + e . name ) . join ( ", " ) ) ;
163
+
164
+ // return task;
165
+ console . log ( chalk . blue ( "Adding reaction" ) ) ;
125
166
if ( comment === target ) {
126
167
await gh . reactions . createForIssueComment ( {
127
168
...parseIssueUrl ( issue . html_url ) ,
0 commit comments