1010 */
1111const { validateGitHubWebHook } = require ( './validate-github-webhook' ) ;
1212
13- const { triggerAzurePipeline } = require ( './trigger-azure-pipeline' ) ;
14-
1513const { triggerWorkflowDispatch, listWorkflowRuns } = require ( './trigger-workflow-dispatch' )
1614
1715module . 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 ) } ` ) ;
0 commit comments