@@ -23,15 +23,46 @@ const getIssueComment = async (context, token, owner, repo, comment_id) => {
2323 return await sendGitHubAPIRequest ( context , token , 'GET' , `/repos/${ owner } /${ repo } /issues/comments/${ comment_id } ` )
2424}
2525
26- const getGitArtifactsCommentID = async ( context , token , owner , repo , headSHA ) => {
26+ const getGitArtifactsCommentID = async ( context , token , owner , repo , headSHA , tagGitWorkflowRunURL ) => {
2727 const answer = await sendGitHubAPIRequest ( context , token , 'GET' , `/search/issues?q=repo:${ owner } /${ repo } +${ headSHA } +type:pr+%22git-artifacts%22` , null , {
2828 Accept : 'application/vnd.github.text-match+json'
2929 } )
30- const items = answer . items . filter ( item =>
31- item . text_matches . length === 1
32- && item . text_matches [ 0 ] . fragment . trim ( ) === '/git-artifacts\n\nThe tag-git workflow run was started'
30+ let commentID = false
31+ for ( const item of answer . items ) {
32+ for ( const text_match of item . text_matches ) {
33+ if ( text_match . fragment . startsWith ( '/git-artifacts' ) ) {
34+ if ( commentID !== false ) return false // more than one match, maybe a trickster at play, ignore altogether
35+ else {
36+ commentID = text_match . object_url . replace ( / ^ .* \/ ( \d + ) $ / , '$1' )
37+ break // continue with outer loop, to see whether another PR matches, too
38+ }
39+ }
40+ }
41+ }
42+ if ( commentID === false ) return false
43+
44+ // ensure that this is the correct comment; It should contain the URL of the actual tag-git workflow run
45+ const comment = await getIssueComment ( context , token , owner , repo , commentID )
46+ if ( ! comment ) return false
47+ const needle = `The \`tag-git\` workflow run [was started](${ tagGitWorkflowRunURL } )`
48+ if ( comment . body . includes ( needle ) ) return commentID
49+
50+ // nope, so let's look for other comments on the same PR
51+ commentID = false
52+ const comments = await sendGitHubAPIRequest (
53+ context ,
54+ token ,
55+ 'GET' ,
56+ `/repos/${ owner } /${ repo } /issues/${ comment . issue_url . replace ( / ^ .* \/ ( \d + ) $ / , '$1' ) } /comments`
3357 )
34- return items . length === 1 && items [ 0 ] . text_matches [ 0 ] . object_url . replace ( / ^ .* \/ ( \d + ) $ / , '$1' )
58+ for ( const comment2 of comments ) {
59+ if ( comment2 . body . startsWith ( `/git-artifacts` ) && comment2 . body . includes ( needle ) ) {
60+ if ( commentID !== false ) return false // more than one match, maybe a trickster at play, ignore altogether
61+ commentID = comment2 . id
62+ }
63+ }
64+
65+ return commentID
3566}
3667
3768const appendToIssueComment = async ( context , token , owner , repo , comment_id , append ) => {
0 commit comments