@@ -63,50 +63,38 @@ export async function commentOrUpdate(
63
63
body ,
64
64
commentIdentifier ,
65
65
) {
66
- try {
67
- // Get the authenticated user to know who we are
68
- const { data : user } = await github . rest . users . getAuthenticated ( ) ;
69
- const authenticatedUsername = user . login ;
70
- const computedBody = body + `\n<!-- ${ commentIdentifier } -->` ;
66
+ const computedBody = body + `\n<!-- ${ commentIdentifier } -->` ;
71
67
72
- /** @type {IssueComment[] } */
73
- const comments = await github . paginate ( github . rest . issues . listComments , {
68
+ /** @type {IssueComment[] } */
69
+ const comments = await github . paginate ( github . rest . issues . listComments , {
70
+ owner,
71
+ repo,
72
+ issue_number,
73
+ per_page : PER_PAGE_MAX ,
74
+ } ) ;
75
+
76
+ const [ commentId , commentBody ] = parseExistingComments ( comments , commentIdentifier ) ;
77
+
78
+ if ( commentId ) {
79
+ if ( commentBody === computedBody ) {
80
+ core . info ( `No update needed for comment ${ commentId } .` ) ;
81
+ return ; // No-op if the body is the same
82
+ }
83
+ await github . rest . issues . updateComment ( {
84
+ owner,
85
+ repo,
86
+ comment_id : commentId ,
87
+ body : computedBody ,
88
+ } ) ;
89
+ core . info ( `Updated existing comment ${ commentId } .` ) ;
90
+ } else {
91
+ // Create a new comment
92
+ const { data : newComment } = await github . rest . issues . createComment ( {
74
93
owner,
75
94
repo,
76
95
issue_number,
77
- per_page : PER_PAGE_MAX ,
96
+ body : computedBody ,
78
97
} ) ;
79
-
80
- // only examine the comments from user in our current GITHUB_TOKEN context
81
- const existingComments = comments . filter (
82
- ( comment ) => comment . user ?. login === authenticatedUsername ,
83
- ) ;
84
-
85
- const [ commentId , commentBody ] = parseExistingComments ( existingComments , commentIdentifier ) ;
86
-
87
- if ( commentId ) {
88
- if ( commentBody === computedBody ) {
89
- core . info ( `No update needed for comment ${ commentId } by ${ authenticatedUsername } ` ) ;
90
- return ; // No-op if the body is the same
91
- }
92
- await github . rest . issues . updateComment ( {
93
- owner,
94
- repo,
95
- comment_id : commentId ,
96
- body : computedBody ,
97
- } ) ;
98
- core . info ( `Updated existing comment ${ commentId } by ${ authenticatedUsername } ` ) ;
99
- } else {
100
- // Create a new comment
101
- const { data : newComment } = await github . rest . issues . createComment ( {
102
- owner,
103
- repo,
104
- issue_number,
105
- body : computedBody ,
106
- } ) ;
107
- core . info ( `Created new comment #${ newComment . id } ` ) ;
108
- }
109
- } catch ( /** @type {any } */ error ) {
110
- core . error ( `Failed to comment or update: ${ error . message } ` ) ;
98
+ core . info ( `Created new comment #${ newComment . id } ` ) ;
111
99
}
112
100
}
0 commit comments