Skip to content

Commit a9099ca

Browse files
authored
Merge pull request #87 from dscho/support-open-pr-in-msys2-runtime-prs
`/open pr`: support running in git-for-windows/msys2-runtime PRs
2 parents d7956bd + 90bea20 commit a9099ca

4 files changed

Lines changed: 78 additions & 3 deletions

File tree

.vscode/launch.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"args": ["--runInBand", "--config", "jest.config.js"],
1212
"windows": {
1313
"program": "${workspaceFolder}/node_modules/jest/bin/jest"
14-
}
14+
},
15+
"console": "integratedTerminal"
1516
},
1617
{
1718
"name": "Attach to Node Functions",

GitForWindowsHelper/component-updates.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const guessComponentUpdateDetails = (title, body) => {
22
let [ , package_name, version ] =
33
title.match(/^\[New (\S+) version\] (?:[^0-9]+\s+)?(\S+(?:\s+patch\s+\d+)?)(?! new items)/) ||
44
title.match(/^(\S+): update to v?(\d[0-9.]\S*)/) ||
5+
title.match(/^(msys2-runtime): update to ([0-9a-f]{40,64})/) ||
56
body.match(/^# \[New (\S+) version\] (?:[^0-9]+\s+)?(\S+(?:\s+patch\s+\d+)?)/) ||
67
[]
78
if (!package_name || !version) throw new Error(`Could not guess component-update details from title '${title}'`)

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: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,12 @@ 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+
}
142+
if (method === 'GET' && requestPath.endsWith('/pulls/177')) return {
143+
head: { sha: '03bdffe5997'}
144+
}
139145
if (method === 'PATCH' && requestPath.endsWith('/git/refs/heads/main')) {
140146
if (payload.sha !== 'c0ffee1ab7e') throw new Error(`Unexpected sha: ${payload.sha}`)
141147
if (payload.force !== false) throw new Error(`Unexpected force value: ${payload.force}`)
@@ -330,6 +336,44 @@ The MINGW workflow run [was started](dispatched-workflow-open-pr.yml)`
330336
})
331337
})
332338

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

551+
testIssueComment('/deploy', {
552+
issue: {
553+
number: 177,
554+
title: 'msys2-runtime: update to 4b3a2e08f545432b62461313082193d6df09b6b8',
555+
body: 'This corresponds to https://github.com/git-for-windows/msys2-runtime/pull/70',
556+
pull_request: {
557+
html_url: 'https://github.com/git-for-windows/MSYS2-packages/pull/177'
558+
}
559+
},
560+
repository: {
561+
name: 'MSYS2-packages'
562+
}
563+
}, async (context) => {
564+
expect(await index(context, context.req)).toBeUndefined()
565+
expect(context.res.body).toEqual(`I edited the comment: appended-comment-body-existing comment body
566+
567+
The workflow run [was started](dispatched-workflow-build-and-deploy.yml).`)
568+
expect(mockQueueCheckRun).toHaveBeenCalledTimes(1)
569+
expect(mockUpdateCheckRun).toHaveBeenCalledTimes(1)
570+
expect(dispatchedWorkflows.map(e => e.payload.inputs.architecture)).toEqual(['x86_64'])
571+
expect(dispatchedWorkflows.map(e => e.payload.inputs.package)).toEqual(['msys2-runtime'])
572+
})
573+
507574
testIssueComment('/deploy msys2-runtime-3.3', {
508575
issue: {
509576
number: 96,

0 commit comments

Comments
 (0)