@@ -6,45 +6,54 @@ export async function hidePriorCommentsWithPrefix({
66 resolved = true ,
77 user = 'github-actions[bot]' ,
88} ) {
9- const comments = await github . rest . issues . listComments ( {
10- owner : context . repo . owner ,
11- repo : context . repo . repo ,
12- issue_number : context . issue . number ,
13- } ) ;
9+ const comments = await withRetry ( ( ) =>
10+ github . rest . issues . listComments ( {
11+ owner : context . repo . owner ,
12+ repo : context . repo . repo ,
13+ issue_number : context . issue . number ,
14+ } )
15+ ) ;
16+ await exec . exec ( 'sleep 0.5s' ) ;
1417 for ( const comment of comments . data ) {
15- const isHidden = ( await github . graphql ( `
16- query($nodeId: ID!) {
17- node(id: $nodeId) {
18- ... on IssueComment {
19- isMinimized
18+ const commentData = await withRetry ( ( ) =>
19+ github . graphql ( `
20+ query($nodeId: ID!) {
21+ node(id: $nodeId) {
22+ ... on IssueComment {
23+ isMinimized
24+ }
2025 }
2126 }
22- }
23- ` , { nodeId : comment . node_id } ) ) ?. node ?. isMinimized ;
27+ ` , { nodeId : comment . node_id } )
28+ ) ;
2429 await exec . exec ( 'sleep 0.5s' ) ;
30+ const isHidden = commentData ?. node ?. isMinimized ;
2531 if ( isHidden ) { continue ; }
2632 if (
2733 comment . user . login === user &&
2834 comment . body . startsWith ( prefix )
2935 ) {
3036 console . log ( 'Comment node_id:' , comment . node_id ) ;
31- console . log ( await github . graphql ( `
32- mutation($subjectId: ID!, $classifier: ReportedContentClassifiers!) {
33- minimizeComment(input: {
34- subjectId: $subjectId,
35- classifier: $classifier
36- }) {
37- minimizedComment {
38- isMinimized
39- minimizedReason
37+ const commentStatus = await withRetry ( ( ) =>
38+ github . graphql ( `
39+ mutation($subjectId: ID!, $classifier: ReportedContentClassifiers!) {
40+ minimizeComment(input: {
41+ subjectId: $subjectId,
42+ classifier: $classifier
43+ }) {
44+ minimizedComment {
45+ isMinimized
46+ minimizedReason
47+ }
4048 }
4149 }
42- }
43- ` , {
44- subjectId : comment . node_id ,
45- classifier : resolved ? 'RESOLVED' : 'OUTDATED' ,
46- } ) ) ;
50+ ` , {
51+ subjectId : comment . node_id ,
52+ classifier : resolved ? 'RESOLVED' : 'OUTDATED' ,
53+ } )
54+ ) ;
4755 await exec . exec ( 'sleep 0.5s' ) ;
56+ console . log ( commentStatus ) ;
4857 }
4958 }
5059}
@@ -55,10 +64,35 @@ export async function createComment({
5564 exec, // injected by GitHub
5665 body = '' ,
5766} ) {
58- await github . rest . issues . createComment ( {
59- owner : context . repo . owner ,
60- repo : context . repo . repo ,
61- issue_number : context . issue . number ,
62- body : body ,
63- } ) ;
67+ await withRetry ( ( ) =>
68+ github . rest . issues . createComment ( {
69+ owner : context . repo . owner ,
70+ repo : context . repo . repo ,
71+ issue_number : context . issue . number ,
72+ body : body ,
73+ } )
74+ ) ;
75+ }
76+
77+ /** @param fn {() => Promise<any>} */
78+ async function withRetry ( fn , maxRetries = 3 , baseDelayMs = 1500 ) {
79+ let lastError ;
80+ for ( let attempt = 1 ; attempt <= maxRetries ; attempt += 1 ) {
81+ try {
82+ return await fn ( ) ;
83+ } catch ( error ) {
84+ // Don't retry on 4xx errors (client errors), only on 5xx or network issues
85+ if ( error . status && error . status >= 400 && error . status < 500 ) {
86+ throw error ;
87+ }
88+ lastError = error ;
89+
90+ // Exponential backoff
91+ const delay = baseDelayMs * Math . pow ( 2 , attempt - 1 ) ;
92+ console . log ( `Attempt ${ attempt } failed, retrying in ${ delay / 1000 } s...` ) ;
93+ await new Promise ( ( resolve ) => setTimeout ( resolve , delay ) ) ;
94+ }
95+ }
96+ // Did not produce results after multiple retries
97+ throw lastError ;
6498}
0 commit comments