Skip to content

Commit

Permalink
fix: fix parsed hook response (#16)
Browse files Browse the repository at this point in the history
* fix: fix parsed hook response

* fix: add log info
  • Loading branch information
yokawara authored and minzcmu committed Jan 22, 2019
1 parent aad6818 commit f780c6f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
22 changes: 13 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const Scm = require('screwdriver-scm-base');
const async = require('async');
const hoek = require('hoek');
const winston = require('winston');

class ScmRouter extends Scm {
/**
Expand Down Expand Up @@ -94,7 +95,7 @@ class ScmRouter extends Scm {
* @return {Promise} scm object
*/
chooseWebhookScm(headers, payload) {
return new Promise((resolve, reject) => {
return new Promise((resolve) => {
// choose a webhook scm module, or null if there is no suitable one
async.detect(this.scms, (scm, cb) => {
scm.canHandleWebhook(headers, payload)
Expand All @@ -103,13 +104,7 @@ class ScmRouter extends Scm {
}).catch(() => {
cb(null);
});
}, (ret) => {
if (ret === null) {
return reject(new Error('there is no suitable webhook module'));
}

return resolve(ret);
});
}, ret => resolve(ret));
});
}

Expand Down Expand Up @@ -177,7 +172,16 @@ class ScmRouter extends Scm {
* @return {Promise}
*/
_parseHook(headers, payload) {
return this.chooseWebhookScm(headers, payload).then(scm => scm.parseHook(headers, payload));
return this.chooseWebhookScm(headers, payload)
.then((scm) => {
if (!scm) {
winston.info('Webhook does not match any expected events or actions.');

return null;
}

return scm.parseHook(headers, payload);
});
}

/**
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
},
"dependencies": {
"async": "^2.6.1",
"screwdriver-scm-base": "^5.0.0"
"screwdriver-scm-base": "^5.0.0",
"winston": "^3.1.0"
},
"release": {
"debug": false,
Expand Down

0 comments on commit f780c6f

Please sign in to comment.