10
10
*/
11
11
const { validateGitHubWebHook } = require ( './validate-github-webhook' ) ;
12
12
13
- const { triggerAzurePipeline } = require ( './trigger-azure-pipeline' ) ;
14
-
15
13
const { triggerWorkflowDispatch, listWorkflowRuns } = require ( './trigger-workflow-dispatch' )
16
14
17
15
module . exports = async ( context , req ) => {
@@ -29,27 +27,18 @@ module.exports = async (context, req) => {
29
27
30
28
try {
31
29
/*
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).
41
34
*/
42
- const pipelines = {
43
- 'dscho' : 12 ,
44
- 'git' : 13 ,
45
- 'gitgitgadget' : 3 ,
46
- } ;
35
+ const orgs = [ 'gitgitgadget' , 'git' , 'dscho' ]
47
36
const a = [ context , undefined , 'gitgitgadget-workflows' , 'gitgitgadget-workflows' ]
48
37
49
38
const eventType = context . req . headers [ 'x-github-event' ] ;
50
39
context . log ( `Got eventType: ${ eventType } ` ) ;
51
40
const repositoryOwner = req . body . repository . owner . login ;
52
- if ( pipelines [ repositoryOwner ] === undefined ) {
41
+ if ( ! orgs . includes ( repositoryOwner ) ) {
53
42
context . res = {
54
43
status : 403 ,
55
44
body : 'Refusing to work on a repository other than gitgitgadget/git or git/git'
@@ -95,11 +84,6 @@ module.exports = async (context, req) => {
95
84
context . res = { body : `push(${ req . body . ref } ): triggered ${ run . html_url } ${ extra . join ( '' ) } ` }
96
85
}
97
86
} 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
-
103
87
const comment = req . body . comment ;
104
88
const prNumber = req . body . issue . number ;
105
89
if ( ! comment || ! comment . id || ! prNumber ) {
@@ -121,19 +105,13 @@ module.exports = async (context, req) => {
121
105
return ;
122
106
}
123
107
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
+ } )
133
111
134
112
context . res = {
135
113
// status: 200, /* Defaults to 200 */
136
- body : ' Okay!' ,
114
+ body : ` Okay, triggered ${ run . html_url } !` ,
137
115
} ;
138
116
} else {
139
117
context . log ( `Unhandled request:\n${ JSON . stringify ( req , null , 4 ) } ` ) ;
0 commit comments