Skip to content

Commit d5eed8c

Browse files
committed
Trigger handle-pr-push on PR updates
This is the final bit of the migration from GitGitGadget's Azure Pipelines to GitHub workflows. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent ba63040 commit d5eed8c

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

GitGitGadget/index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,17 @@ module.exports = async (context, req) => {
4343
status: 403,
4444
body: 'Refusing to work on a repository other than gitgitgadget/git or git/git'
4545
};
46+
} else if (eventType === 'pull_request') {
47+
if (req.body.action !== 'opened' && req.body.action !== 'synchronize') {
48+
context.res = {
49+
body: `Ignoring pull request action: ${req.body.action}`,
50+
};
51+
} else {
52+
const run = await triggerWorkflowDispatch(...a, 'handle-pr-push.yml', 'main', {
53+
'pr-url': req.body.pull_request.html_url
54+
})
55+
context.res = { body: `Okay, triggered ${run.html_url}!` };
56+
}
4657
} else if ((new Set(['check_run', 'status']).has(eventType))) {
4758
context.res = {
4859
body: `Ignored event type: ${eventType}`,

__tests__/index.test.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,4 +275,34 @@ testWebhookPayload('react to `lore-1` being pushed to https://github.com/gitgitg
275275
'main',
276276
undefined
277277
])
278+
})
279+
testWebhookPayload('react to PR push', 'pull_request', {
280+
action: 'synchronize',
281+
pull_request: {
282+
html_url: 'https://github.com/gitgitgadget/git/pull/1956',
283+
},
284+
repository: {
285+
full_name: 'gitgitgadget/git',
286+
owner: {
287+
login: 'gitgitgadget'
288+
}
289+
}
290+
}, (context) => {
291+
expect(context.res).toEqual({
292+
body: [
293+
'Okay, triggered <the URL to the workflow handle-pr-push.yml run on main with inputs',
294+
'{"pr-url":"https://github.com/gitgitgadget/git/pull/1956"}>!'
295+
].join(' ')
296+
})
297+
expect(mockTriggerWorkflowDispatch).toHaveBeenCalledTimes(1)
298+
expect(mockTriggerWorkflowDispatch.mock.calls[0]).toEqual([
299+
context,
300+
undefined,
301+
'gitgitgadget-workflows',
302+
'gitgitgadget-workflows',
303+
'handle-pr-push.yml',
304+
'main', {
305+
'pr-url': 'https://github.com/gitgitgadget/git/pull/1956',
306+
}
307+
])
278308
})

0 commit comments

Comments
 (0)