File tree Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Original file line number Diff line number Diff 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 } ` ,
Original file line number Diff line number Diff 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} )
You can’t perform that action at this time.
0 commit comments