@@ -15,18 +15,18 @@ let githubUtils = require('../gtmGithubUtils.js');
1515
1616import KmsUtils from './../../KmsUtils' ;
1717
18- async function listener ( event , context , callback ) {
18+ async function listener ( event ) {
1919 console . log (
2020 `hook call from ${ event . requestContext . identity . sourceIp } forwarded for ${ event . headers [ 'X-Forwarded-For' ] } `
2121 ) ;
2222 const githubEvent = event . headers [ 'X-GitHub-Event' ] || event . headers [ 'x-github-event' ] ;
2323 const githubSignature = event . headers [ 'X-Hub-Signature' ] || event . headers [ 'x-hub-signature' ] ;
2424 let err = await githubUtils . invalidHook ( event ) ;
2525 if ( err ) {
26- return callback ( err , {
26+ return Promise . reject ( {
2727 statusCode : 401 ,
2828 headers : { 'Content-Type' : 'text/plain' } ,
29- body : err . message
29+ body : JSON . stringify ( err )
3030 } ) ;
3131 }
3232
@@ -36,10 +36,10 @@ async function listener(event, context, callback) {
3636 // blacklisted repos result in null error and 200 as this is a valid result
3737 err = checkRepoBlacklisted ( eventBody ) ;
3838 if ( err ) {
39- return callback ( null , {
39+ return Promise . reject ( {
4040 statusCode : 200 ,
4141 headers : { 'Content-Type' : 'text/plain' } ,
42- body : err . message
42+ body : JSON . stringify ( err )
4343 } ) ;
4444 }
4545
@@ -50,25 +50,23 @@ async function listener(event, context, callback) {
5050 console . log ( 'Payload' , json . plain ( eventBody ) ) ;
5151 /* eslint-enable */
5252
53- let response ;
5453 try {
55- await handleEvent ( githubEvent , eventBody , githubSignature ) ;
56- response = {
54+ let ghEventId = await handleEvent ( githubEvent , eventBody , githubSignature ) ;
55+ return Promise . resolve ( {
5756 statusCode : 200 ,
57+ headers : { 'X-ghEventId' : ghEventId } ,
5858 body : JSON . stringify ( {
5959 input : event
6060 } )
61- } ;
61+ } ) ;
6262 } catch ( e ) {
6363 err = e ;
64- response = {
64+ return Promise . reject ( {
6565 statusCode : 400 ,
6666 headers : { 'Content-Type' : 'text/plain' } ,
6767 body : err . message
68- } ;
68+ } ) ;
6969 }
70-
71- return callback ( err , response ) ;
7270}
7371
7472async function handleEvent ( type , body , signature ) {
@@ -132,6 +130,7 @@ async function handleEvent(type, body, signature) {
132130 if ( type === 'pull_request' ) {
133131 setPullRequestEventStatus ( ghEventId , body ) ;
134132 }
133+ return ghEventId ;
135134}
136135
137136async function getTaskConfig ( type , body ) {
0 commit comments