Skip to content

Commit ba63040

Browse files
committed
Trigger the new GitHub workflow to handle PR comments
This _almost_ retires these Azure Pipelines: - GitGitGadget PR Handler https://dev.azure.com/gitgitgadget/git/_build?definitionId=3 - GitGitGadget PR Handler (git) https://dev.azure.com/gitgitgadget/git/_build?definitionId=13 - GitGitGadget PR Handler (dscho) https://dev.azure.com/gitgitgadget/git/_build?definitionId=12 The remaining responsibility of those Pipelines is to handle PR _pushes_, which I will address in the next commit. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 2d7ebae commit ba63040

File tree

2 files changed

+13
-42
lines changed

2 files changed

+13
-42
lines changed

GitGitGadget/index.js

Lines changed: 10 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
*/
1111
const { validateGitHubWebHook } = require('./validate-github-webhook');
1212

13-
const { triggerAzurePipeline } = require('./trigger-azure-pipeline');
14-
1513
const { triggerWorkflowDispatch, listWorkflowRuns } = require('./trigger-workflow-dispatch')
1614

1715
module.exports = async (context, req) => {
@@ -29,27 +27,18 @@ module.exports = async (context, req) => {
2927

3028
try {
3129
/*
32-
* The Azure Pipeline needs to be installed as a PR build on _the very
33-
* same_ repository that triggers this function. That is, when the
34-
* Azure Function triggers GitGitGadget for gitgitgadget/git, it needs
35-
* to know that pipelineId 3 is installed on gitgitgadget/git, and
36-
* trigger that very pipeline.
37-
*
38-
* So whenever we extend GitGitGadget to handle another repository, we
39-
* will have to add an Azure Pipeline, install it on that repository as
40-
* a PR build, and add the information here.
30+
* For various reasons, the GitGitGadget GitHub App can be installed
31+
* on any random repository. However, GitGitGadget only wants to support
32+
* the `gitgitgadget/git` and the `git/git` repository (with the
33+
* `dscho/git` one thrown in for debugging purposes).
4134
*/
42-
const pipelines = {
43-
'dscho': 12,
44-
'git': 13,
45-
'gitgitgadget': 3,
46-
};
35+
const orgs = ['gitgitgadget', 'git', 'dscho']
4736
const a = [context, undefined, 'gitgitgadget-workflows', 'gitgitgadget-workflows']
4837

4938
const eventType = context.req.headers['x-github-event'];
5039
context.log(`Got eventType: ${eventType}`);
5140
const repositoryOwner = req.body.repository.owner.login;
52-
if (pipelines[repositoryOwner] === undefined) {
41+
if (!orgs.includes(repositoryOwner)) {
5342
context.res = {
5443
status: 403,
5544
body: 'Refusing to work on a repository other than gitgitgadget/git or git/git'
@@ -95,11 +84,6 @@ module.exports = async (context, req) => {
9584
context.res = { body: `push(${req.body.ref}): triggered ${run.html_url}${extra.join('')}` }
9685
}
9786
} else if (eventType === 'issue_comment') {
98-
const triggerToken = process.env['GITGITGADGET_TRIGGER_TOKEN'];
99-
if (!triggerToken) {
100-
throw new Error('No configured trigger token');
101-
}
102-
10387
const comment = req.body.comment;
10488
const prNumber = req.body.issue.number;
10589
if (!comment || !comment.id || !prNumber) {
@@ -121,19 +105,13 @@ module.exports = async (context, req) => {
121105
return;
122106
}
123107

124-
const sourceBranch = `refs/pull/${prNumber}/head`;
125-
const parameters = {
126-
'pr.comment.id': comment.id,
127-
};
128-
const pipelineId = pipelines[repositoryOwner];
129-
if (!pipelineId || pipelineId < 1)
130-
throw new Error(`No pipeline set up for org ${repositoryOwner}`);
131-
context.log(`Queuing with branch ${sourceBranch} and parameters ${JSON.stringify(parameters)}`);
132-
await triggerAzurePipeline(triggerToken, 'gitgitgadget', 'git', pipelineId, sourceBranch, parameters);
108+
const run = await triggerWorkflowDispatch(...a, 'handle-pr-comment.yml', 'main', {
109+
'pr-comment-url': comment.html_url
110+
})
133111

134112
context.res = {
135113
// status: 200, /* Defaults to 200 */
136-
body: 'Okay!',
114+
body: `Okay, triggered ${run.html_url}!`,
137115
};
138116
} else {
139117
context.log(`Unhandled request:\n${JSON.stringify(req, null, 4)}`);

__tests__/index.test.js

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -153,17 +153,10 @@ const testIssueComment = (comment, repoOwner, fn) => {
153153
testIssueComment('/test', async (context) => {
154154
expect(context.done).toHaveBeenCalledTimes(1)
155155
expect(context.res).toEqual({
156-
body: 'Okay!'
156+
body: 'Okay, triggered <the URL to the workflow handle-pr-comment.yml run on main with inputs {"pr-comment-url":"https://github.com/gitgitgadget/git/pull/1886743660"}>!'
157157
})
158-
expect(mockRequest.write).toHaveBeenCalledTimes(1)
159-
expect(JSON.parse(mockRequest.write.mock.calls[0][0])).toEqual({
160-
definition: {
161-
id: 3
162-
},
163-
sourceBranch: 'refs/pull/1886743660/head',
164-
parameters: '{"pr.comment.id":27988538471837300}'
165-
})
166-
expect(mockRequest.end).toHaveBeenCalledTimes(1)
158+
expect(mockRequest.write).not.toHaveBeenCalled()
159+
expect(mockRequest.end).not.toHaveBeenCalled()
167160
})
168161

169162
testIssueComment('/verify-repository', 'nope', (context) => {

0 commit comments

Comments
 (0)