Skip to content

Commit 826d911

Browse files
committed
Switch /git-artifacts from Azure Pipelines to GitHub workflows
With this commit, a `/git-artifacts` command will no longer trigger the `Git Artifacts` Azure Pipeline but instead the `tag-git` GitHub workflow. This relies on the previous commit which teaches the GitForWindows GitHub App to react to a completed `tag-git` run by triggering the corresponding `git-artifacts` runs. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent 01c51fa commit 826d911

2 files changed

Lines changed: 57 additions & 3 deletions

File tree

GitForWindowsHelper/slash-commands.js

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -267,11 +267,33 @@ module.exports = async (context, req) => {
267267
await checkPermissions()
268268
await thumbsUp()
269269

270-
const { triggerGitArtifacts } = require('./azure-pipelines')
271-
const answer = await triggerGitArtifacts(context, req.body.issue.number)
270+
const { getPRCommitSHA } = require('./issues')
271+
const rev = await getPRCommitSHA(context, await getToken(), owner, repo, issueNumber)
272+
273+
const triggerWorkflowDispatch = require('./trigger-workflow-dispatch')
274+
const answer = await triggerWorkflowDispatch(
275+
context,
276+
await getToken(),
277+
'git-for-windows',
278+
'git-for-windows-automation',
279+
'tag-git.yml',
280+
'main', {
281+
rev,
282+
owner,
283+
repo,
284+
snapshot: false
285+
}
286+
)
272287

273288
const { appendToIssueComment } = require('./issues')
274-
const answer2 = await appendToIssueComment(context, await getToken(), owner, repo, commentId, `The Azure Pipeline run [was started](${answer.url})`)
289+
const answer2 = await appendToIssueComment(
290+
context,
291+
await getToken(),
292+
owner,
293+
repo,
294+
commentId,
295+
`The \`tag-git\` workflow run [was started](${answer.html_url})`
296+
)
275297
return `I edited the comment: ${answer2.html_url}`
276298
}
277299

__tests__/index.test.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ let mockGitHubApiRequest = jest.fn((_context, _token, method, requestPath, paylo
103103
if (method === 'GET' && requestPath.endsWith('/pulls/86')) return {
104104
head: { sha: '707a11ee' }
105105
}
106+
if (method === 'GET' && requestPath.endsWith('/pulls/4322')) return {
107+
head: { sha: 'c8edb521bdabec14b07e9142e48cab77a40ba339' }
108+
}
106109
throw new Error(`Unhandled ${method}-${requestPath}-${JSON.stringify(payload)}`)
107110
})
108111
jest.mock('../GitForWindowsHelper/github-api-request', () => {
@@ -390,3 +393,32 @@ The \`git-artifacts-i686\` workflow run [was started](dispatched-workflow-git-ar
390393
throw e;
391394
}
392395
})
396+
397+
testIssueComment('/git-artifacts', {
398+
issue: {
399+
number: 4322,
400+
title: 'Rebase to v2.40.0-rc1',
401+
pull_request: {
402+
html_url: 'https://github.com/git-for-windows/git/pull/4322'
403+
}
404+
}
405+
}, async (context) => {
406+
expect(await index(context, context.req)).toBeUndefined()
407+
expect(context.res).toEqual({
408+
body: `I edited the comment: appended-comment-body-existing comment body
409+
410+
The \`tag-git\` workflow run [was started](dispatched-workflow-tag-git.yml)`,
411+
headers: undefined,
412+
status: undefined
413+
})
414+
expect(mockGetInstallationAccessToken).toHaveBeenCalledTimes(1)
415+
expect(mockGitHubApiRequestAsApp).not.toHaveBeenCalled()
416+
expect(dispatchedWorkflows).toHaveLength(1)
417+
expect(dispatchedWorkflows[0].html_url).toEqual('dispatched-workflow-tag-git.yml')
418+
expect(dispatchedWorkflows[0].payload.inputs).toEqual({
419+
owner: 'git-for-windows',
420+
repo: 'git',
421+
rev: 'c8edb521bdabec14b07e9142e48cab77a40ba339',
422+
snapshot: false
423+
})
424+
})

0 commit comments

Comments
 (0)