Skip to content

Commit 4dbae12

Browse files
committed
/git-artifacts: add the git-artifacts runs to the PR comment more reliably
When `/git-artifacts` has to trigger a `tag-git` run first, the actual `git-artifacts-<arch>` jobs are triggered as "cascading runs". At that stage, the connection to the original PR comment ID is lost, and therefore that comment is no longer updated to link to those `git-artifacts-<arch>` runs. With this patch, GitForWindowsHelper learns to find that PR comment ID when a completed `tag-git` check run triggers the `git-artifacts-` runs and then to update that comment accordingly. This addresses #38 Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent b18a11b commit 4dbae12

2 files changed

Lines changed: 32 additions & 1 deletion

File tree

GitForWindowsHelper/cascading-runs.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,17 @@ const cascadingRuns = async (context, req) => {
114114
throw new Error(`Refusing to handle cascading run in ${checkRunOwner}/${checkRunRepo}`)
115115
}
116116

117-
return await triggerGitArtifactsRuns(context, checkRunOwner, checkRunRepo, checkRun)
117+
const comment = await triggerGitArtifactsRuns(context, checkRunOwner, checkRunRepo, checkRun)
118+
119+
const token = await getToken(context, checkRunOwner, checkRunRepo)
120+
const { getGitArtifactsCommentID, appendToIssueComment } = require('./issues')
121+
const gitArtifactsCommentID = await getGitArtifactsCommentID(context, token, checkRunOwner, checkRunRepo, req.body.check_run.head_sha)
122+
123+
if (gitArtifactsCommentID) {
124+
await appendToIssueComment(context, token, checkRunOwner, checkRunRepo, gitArtifactsCommentID, comment)
125+
}
126+
127+
return comment
118128
}
119129
return `Not a cascading run: ${name}; Doing nothing.`
120130
}

__tests__/index.test.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,27 @@ let mockGitHubApiRequest = jest.fn((_context, _token, method, requestPath, paylo
127127
if (method === 'GET' && requestPath.endsWith('/pulls/4323')) return {
128128
head: { sha: 'dee501d15' }
129129
}
130+
if (method === 'GET' && requestPath === '/search/issues?q=repo:git-for-windows/git+c8edb521bdabec14b07e9142e48cab77a40ba339+type:pr+%22git-artifacts%22') return {
131+
items: [{
132+
text_matches: [{
133+
object_url: 'https://api.github.com/repositories/23216272/issues/comments/1450703020',
134+
fragment: '/git-artifacts\n\nThe tag-git workflow run was started\n'
135+
}]
136+
}]
137+
}
138+
if (method === 'GET' && requestPath === '/repos/git-for-windows/git/issues/comments/1450703020') return {
139+
body: '/git-artifacts\n\nThe tag-git workflow run [was started](https://url-to-tag-git/)'
140+
}
141+
if (method === 'PATCH' && requestPath === '/repos/git-for-windows/git/issues/comments/1450703020') {
142+
expect(payload.body).toEqual(`/git-artifacts
143+
144+
The tag-git workflow run [was started](https://url-to-tag-git/)
145+
146+
git-artifacts-x86_64 run already exists at <url-to-existing-x86_64-run>.
147+
The \`git-artifacts-i686\` workflow run [was started](dispatched-workflow-git-artifacts.yml).
148+
`)
149+
return { html_url: 'https://github.com/git-for-windows/git/pull/4322#issuecomment-1450703020' }
150+
}
130151
throw new Error(`Unhandled ${method}-${requestPath}-${JSON.stringify(payload)}`)
131152
})
132153
jest.mock('../GitForWindowsHelper/github-api-request', () => {

0 commit comments

Comments
 (0)