Skip to content

Commit

Permalink
Find the /git-artifacts comment even more reliably
Browse files Browse the repository at this point in the history
Over in git-for-windows/git#4918, _something_ in
the range-diff was matched _somehow_ by that search string. The
`text_matches` of the returned objects look like this:

  text_matches: [
    {
      object_url: "https://api.github.com/repositories/23216272/issues/comments/2067288321",
      object_type: "IssueComment",
      property: "body",
      fragment: "/git-artifacts\n\nThe tag-git workflow run was started\n",
      matches: [
        {
          text: "git",
          indices: [
            1,
            4,
          ],
        },
        {
          text: "artifacts",
          indices: [
            5,
            14,
          ],
        },
        {
          text: "git",
          indices: [
            24,
            27,
          ],
        },
      ],
    },
    {
      object_url: "https://api.github.com/repositories/23216272/issues/4918",
      object_type: "Issue",
      property: "body",
      fragment: " = 53: 33d9a68ea63 vcxproj: handle GUI programs, too\n\n  - 55: 417ce96c240 = 54: 4c3acea6c21 ci(vs-build) also build Windows/ARM64 artifacts\n\n  - 52: d044e202fa2 = 55: ac6ad169b01 cmake: install",
      matches: [
        {
          text: "artifacts",
          indices: [
            130,
            139,
          ],
        },
      ],
    },
  ],

In other words, there is not even the word "git" in the matches, and
we'll just have to deal with this possible scenario.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
  • Loading branch information
dscho committed Apr 22, 2024
1 parent 4d5e6e5 commit 3d86a82
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions GitForWindowsHelper/issues.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,19 @@ const getGitArtifactsCommentID = async (context, token, owner, repo, headSHA) =>
const answer = await sendGitHubAPIRequest(context, token, 'GET', `/search/issues?q=repo:${owner}/${repo}+${headSHA}+type:pr+%22git-artifacts%22`, null, {
Accept: 'application/vnd.github.text-match+json'
})
const items = answer.items.filter(item =>
item.text_matches.length === 1
&& item.text_matches[0].fragment.trim() === '/git-artifacts\n\nThe tag-git workflow run was started'
)
return items.length === 1 && items[0].text_matches[0].object_url.replace(/^.*\/(\d+)$/, '$1')
let commentID = false
for (const item of answer.items) {
for (const text_match of item.text_matches) {
if (text_match.fragment.startsWith('/git-artifacts\n\nThe tag-git workflow run was started')) {
if (commentID !== false) return false // more than one match, maybe a trickster at play, ignore altogether
else {
commentID = text_match.object_url.replace(/^.*\/(\d+)$/, '$1')
break // continue with outer loop, to see whether another PR matches, too
}
}
}
}
return commentID
}

const appendToIssueComment = async (context, token, owner, repo, comment_id, append) => {
Expand Down

0 comments on commit 3d86a82

Please sign in to comment.