Skip to content

Commit 2d7ebae

Browse files
committed
Trigger handle-new-mails on new mails
GitGitGadget maintains a mirror of the Git mailing list at https://github.com/gitgitgadget/git-mailing-list-mirror/, synchronizing it via the `sync-git-mailing-list-mirror` workflow. As a side effect of having installed the `gitgitgadget` GitHub App on that repository (so that the workflow can push updates), GitGitGadget's App also receives webhook events from that repository. Let's put that fact to good use by triggering the new `handle-new-mails` GitHub workflow that wants to replace GitGitGadget's "Mirror Git List to GitGitGadget's PRs" Azure Pipeline at https://dev.azure.com/gitgitgadget/git/_build?definitionId=5 (which polled the upstream Git mailing list repository). Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 8580d33 commit 2d7ebae

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

GitGitGadget/index.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,21 @@ module.exports = async (context, req) => {
5959
body: `Ignored event type: ${eventType}`,
6060
};
6161
} else if (eventType === 'push') {
62-
if (req.body.repository.full_name !== 'git/git') {
62+
if (req.body.repository.full_name ==='gitgitgadget/git-mailing-list-mirror') {
63+
context.res = { body: `push(${req.body.ref} in ${req.body.repository.full_name}): ` }
64+
if (req.body.ref === 'refs/heads/lore-1') {
65+
const queued = await listWorkflowRuns(...a, 'handle-new-mails.yml', 'queued')
66+
if (queued.length) {
67+
context.res.body += [
68+
`skip triggering handle-new-emails, ${queued} already queued:`,
69+
queued.map(e => `- ${e.html_url}`)
70+
].join('\n')
71+
} else {
72+
const run = await triggerWorkflowDispatch(...a, 'handle-new-mails.yml', 'main')
73+
context.res.body += `triggered ${run.html_url}`
74+
}
75+
} else context.res.body += `Ignoring non-default branches`
76+
} else if (req.body.repository.full_name !== 'git/git') {
6377
context.res = { body: `Ignoring pushes to ${req.body.repository.full_name}` }
6478
} else {
6579
const run = await triggerWorkflowDispatch(

__tests__/index.test.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,4 +255,31 @@ testWebhookPayload('react to `seen` being pushed to git/git', 'push', {
255255
'main',
256256
undefined
257257
])
258+
})
259+
260+
testWebhookPayload('react to `lore-1` being pushed to https://github.com/gitgitgadget/git-mailing-list-mirror', 'push', {
261+
ref: 'refs/heads/lore-1',
262+
repository: {
263+
full_name: 'gitgitgadget/git-mailing-list-mirror',
264+
owner: {
265+
login: 'gitgitgadget'
266+
}
267+
}
268+
}, (context) => {
269+
expect(context.res).toEqual({
270+
body: [
271+
'push(refs/heads/lore-1 in gitgitgadget/git-mailing-list-mirror):',
272+
'triggered <the URL to the workflow handle-new-mails.yml run on main with inputs undefined>'
273+
].join(' ')
274+
})
275+
expect(mockTriggerWorkflowDispatch).toHaveBeenCalledTimes(1)
276+
expect(mockTriggerWorkflowDispatch.mock.calls[0]).toEqual([
277+
context,
278+
undefined,
279+
'gitgitgadget-workflows',
280+
'gitgitgadget-workflows',
281+
'handle-new-mails.yml',
282+
'main',
283+
undefined
284+
])
258285
})

0 commit comments

Comments
 (0)