@@ -92,7 +92,7 @@ const syncConfig = async (context, owner) => {
9292 }
9393}
9494
95- const getDeployPayloads = async ( context , { owner, repo, pullNumber, sha } , components = [ ] ) => {
95+ const getDeployPayloads = async ( context , { owner, repo, pullNumber, sha = '' } , components = [ ] ) => {
9696 const config = getConfig ( owner ) ;
9797 const componentsMap = new Map ( components . map ( ( c ) => [ c . component , c ] ) ) ;
9898 const domain = config . domain ;
@@ -335,6 +335,28 @@ module.exports = (app) => {
335335 await createDeployments ( app , context , owner , payloads ) ;
336336 } ,
337337 ) ;
338+ app . on (
339+ "push" ,
340+ async ( context ) => {
341+ const {
342+ context : ctx ,
343+ commit : { sha } ,
344+ repository : { owner : { login : owner } , name : repo } ,
345+ } = context . payload ;
346+ app . log . info ( 'push' ) ;
347+ app . log . info ( { owner, repo, sha, ctx } ) ;
348+ await syncConfig ( context , owner ) ;
349+
350+ const pullNumber = await findOpenPullRequestNumber ( context , owner , repo , sha ) ;
351+ if ( ! pullNumber ) {
352+ app . log . debug ( `Open pull request for sha ${ sha } cannot be find. Deploy dismissed.` ) ;
353+ return ;
354+ }
355+
356+ const payloads = await getDeployPayloads ( context , { owner, repo, pullNumber, sha } ) ;
357+ await createDeployments ( app , context , owner , payloads ) ;
358+ } ,
359+ ) ;
338360 app . on (
339361 "pull_request" ,
340362 async ( context ) => {
@@ -356,8 +378,16 @@ module.exports = (app) => {
356378 app . log . info ( { owner, repo, ctx, pullNumber } ) ;
357379 await syncConfig ( context , owner ) ;
358380
359- const payloads = await getDeletePayloads ( context , { owner, repo, pullNumber } ) ;
360- await deleteDeployments ( app , context , owner , payloads ) ;
381+ if ( [ 'opened' , 'reopened' ] . includes ( action ) ) {
382+ const payloads = await getDeployPayloads ( context , { owner, repo, pullNumber } ) ;
383+ await createDeployments ( app , context , owner , payloads ) ;
384+ }
385+
386+ if ( [ 'closed' , 'merged' ] . includes ( action ) ) {
387+ app . log . info ( `Action on pull request. But action ${ action } is not appropriate. Skipping...` ) ;
388+ const payloads = await getDeletePayloads ( context , { owner, repo, pullNumber } ) ;
389+ await deleteDeployments ( app , context , owner , payloads ) ;
390+ }
361391 } ,
362392 ) ;
363393 // app.on(
0 commit comments