Skip to content

Commit f71966a

Browse files
committed
/open pr: support running in git-for-windows/msys2-runtime
The MSYS2 runtime is a special thing indeed. Most of the time, patches for Git for Windows' variant of this component come in not via MSYS2, but via PRs in https://github.com/git-for-windows/msys2-runtime. I already taught the `open-pr` GitHub workflow about this in git-for-windows/git-for-windows-automation#87, and now it is time to extend the `/open pr` slash command to cover this scenario, too. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent 81c727c commit f71966a

2 files changed

Lines changed: 49 additions & 2 deletions

File tree

GitForWindowsHelper/slash-commands.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,18 @@ module.exports = async (context, req) => {
5050

5151
try {
5252
if (command == '/open pr') {
53-
if (owner !== 'git-for-windows' || repo !== 'git') return `Ignoring ${command} in unexpected repo: ${commentURL}`
53+
if (owner !== 'git-for-windows' || !['git', 'msys2-runtime'].includes(repo)) return `Ignoring ${command} in unexpected repo: ${commentURL}`
5454

5555
await checkPermissions()
5656

5757
const { guessComponentUpdateDetails, packageNeedsBothMSYSAndMINGW } = require('./component-updates')
58-
const { package_name, version } = guessComponentUpdateDetails(req.body.issue.title, req.body.issue.body)
58+
const { getPRCommitSHA } = require('./issues')
59+
const { package_name, version } = repo === 'msys2-runtime'
60+
? {
61+
package_name: repo,
62+
version: await getPRCommitSHA(context, await getToken(), owner, repo, issueNumber)
63+
}
64+
: guessComponentUpdateDetails(req.body.issue.title, req.body.issue.body)
5965

6066
await thumbsUp()
6167

__tests__/index.test.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,9 @@ let mockGitHubApiRequest = jest.fn((_context, _token, method, requestPath, paylo
136136
if (method === 'GET' && requestPath.endsWith('/pulls/765')) return {
137137
head: { sha: 'c0ffee1ab7e' }
138138
}
139+
if (method === 'GET' && requestPath.endsWith('/pulls/69')) return {
140+
head: { sha: '59d71150a6ee93ab954221c43ca86f8eafe68ddc'}
141+
}
139142
if (method === 'PATCH' && requestPath.endsWith('/git/refs/heads/main')) {
140143
if (payload.sha !== 'c0ffee1ab7e') throw new Error(`Unexpected sha: ${payload.sha}`)
141144
if (payload.force !== false) throw new Error(`Unexpected force value: ${payload.force}`)
@@ -330,6 +333,44 @@ The MINGW workflow run [was started](dispatched-workflow-open-pr.yml)`
330333
})
331334
})
332335

336+
testIssueComment('/open pr', {
337+
repository: {
338+
name: 'msys2-runtime'
339+
},
340+
issue: {
341+
number: 69,
342+
title: 'Support OneDrive better',
343+
body: `This backports patches that avoid hydrating files on OneDrive _just_ to \`stat()\` them.
344+
345+
See also https://github.com/msys2/msys2-runtime/issues/206.`,
346+
pull_request: {
347+
html_url: 'https://github.com/git-for-windows/msys2-runtime/pull/69'
348+
}
349+
}
350+
}, async (context) => {
351+
expect(await index(context, context.req)).toBeUndefined()
352+
expect(context.res).toEqual({
353+
body: `I edited the comment: appended-comment-body-existing comment body
354+
355+
The workflow run [was started](dispatched-workflow-open-pr.yml)`,
356+
headers: undefined,
357+
status: undefined
358+
})
359+
expect(mockGetInstallationAccessToken).toHaveBeenCalledTimes(1)
360+
expect(mockGitHubApiRequestAsApp).not.toHaveBeenCalled()
361+
expect(dispatchedWorkflows).toHaveLength(1)
362+
expect(dispatchedWorkflows[0].payload.inputs.package).toEqual('msys2-runtime')
363+
expect(dispatchedWorkflows[0].payload.inputs.version).toEqual('59d71150a6ee93ab954221c43ca86f8eafe68ddc')
364+
expect(mockGitHubApiRequest).toHaveBeenCalled()
365+
const msysComment = mockGitHubApiRequest.mock.calls[mockGitHubApiRequest.mock.calls.length - 1]
366+
expect(msysComment[3]).toEqual('/repos/git-for-windows/msys2-runtime/issues/comments/0')
367+
expect(msysComment[4]).toEqual({
368+
body: `existing comment body
369+
370+
The workflow run [was started](dispatched-workflow-open-pr.yml)`
371+
})
372+
})
373+
333374
testIssueComment('/updpkgsums', {
334375
issue: {
335376
number: 104,

0 commit comments

Comments
 (0)