Skip to content

Commit

Permalink
feat(2492): Update to eslint-config-screwdriver v5 (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
tkyi authored Jul 9, 2021
1 parent 43ed752 commit 3a1b2d4
Show file tree
Hide file tree
Showing 4 changed files with 354 additions and 397 deletions.
47 changes: 25 additions & 22 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class ScmRouter extends Scm {
this.scms = {};

if (typeof scmsConfig === 'object') {
Object.keys(scmsConfig).forEach((displayName) => {
Object.keys(scmsConfig).forEach(displayName => {
const scm = scmsConfig[displayName];

if (typeof scm !== 'object') {
Expand Down Expand Up @@ -95,17 +95,22 @@ class ScmRouter extends Scm {
* @return {Promise} scm object
*/
chooseWebhookScm(headers, payload) {
return new Promise((resolve) => {
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)
.then((result) => {
cb(result === false ? null : scm);
}).catch((err) => {
logger.error(err);
cb(null);
});
}, ret => resolve(ret));
async.detect(
this.scms,
(scm, cb) => {
scm.canHandleWebhook(headers, payload)
.then(result => {
cb(result === false ? null : scm);
})
.catch(err => {
logger.error(err);
cb(null);
});
},
ret => resolve(ret)
);
});
}

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

return null;
}
return null;
}

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

/**
Expand Down Expand Up @@ -387,7 +391,7 @@ class ScmRouter extends Scm {
stats() {
let result = {};

Object.keys(this.scms).forEach((key) => {
Object.keys(this.scms).forEach(key => {
result = Object.assign(result, this.scms[key].stats());
});

Expand All @@ -411,8 +415,7 @@ class ScmRouter extends Scm {
* @return {String} Full scmContext (e.g. github:github.com)
*/
_getScmContext({ hostname }) {
return Object.keys(this.scms).find(scmContext =>
scmContext.split(':')[1] === hostname);
return Object.keys(this.scms).find(scmContext => scmContext.split(':')[1] === hostname);
}

/**
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@
"Tiffany Kyi <[email protected]>"
],
"devDependencies": {
"chai": "^3.5.0",
"eslint": "^4.19.1",
"eslint-config-screwdriver": "^3.0.1",
"chai": "^4.2.0",
"eslint": "^7.5.0",
"eslint-config-screwdriver": "^5.0.1",
"mocha": "^8.2.1",
"mocha-multi-reporters": "^1.5.1",
"mocha-sonarqube-reporter": "^1.0.2",
"nyc": "^15.0.0",
"mockery": "^2.0.0",
"sinon": "^2.3.4"
"sinon": "^9.0.0"
},
"dependencies": {
"@hapi/hoek": "^9.0.4",
Expand Down
4 changes: 2 additions & 2 deletions test/data/testScm.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const ScmBase = require('screwdriver-scm-base');

module.exports = {
getBaseClass: () => ScmBase,
createMock: (stubsMap) => {
createMock: stubsMap => {
/**
* Generic scm class for testing
* @type {Class}
Expand All @@ -15,7 +15,7 @@ module.exports = {

this.options = options;

Object.keys(stubsMap).forEach((key) => {
Object.keys(stubsMap).forEach(key => {
this[key] = stubsMap[key];
});
}
Expand Down
Loading

0 comments on commit 3a1b2d4

Please sign in to comment.