Skip to content
This repository was archived by the owner on Jul 20, 2019. It is now read-only.

Commit

Permalink
Allow ignoring web-flow commits
Browse files Browse the repository at this point in the history
  • Loading branch information
jarrodldavis committed Oct 14, 2017
1 parent 46f5c0d commit 6578a87
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 13 deletions.
18 changes: 8 additions & 10 deletions lib/create-status.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ const statuses = {
state: 'success',
description: 'All commits have a verified GPG signature'
},
'web-flow-ignored': {
state: 'success',
description: 'All non-web-flow commits have a verified GPG signature'
},
failure: {
state: 'failure',
description: 'All commits must have a verified GPG signature',
Expand All @@ -20,16 +24,10 @@ module.exports = async (github, context, gpgStatus) => {
context: 'GPG'
};

switch (gpgStatus) {
case 'success':
Object.assign(statusParams, statuses.success);
break;
case 'failure':
Object.assign(statusParams, statuses.failure);
break;
default:
Object.assign(statusParams, statuses.error);
break;
if (gpgStatus in statuses) {
Object.assign(statusParams, statuses[gpgStatus]);
} else {
Object.assign(statusParams, statuses.error);
}

return github.repos.createStatus(context.repo(statusParams));
Expand Down
8 changes: 8 additions & 0 deletions lib/get-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const defaultConfig = {
ignoreWebFlow: false
};

module.exports = async context => {
const repoConfig = await context.config('config.yml', { gpg: defaultConfig });
return repoConfig.gpg;
};
5 changes: 3 additions & 2 deletions lib/handle-event.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const getCommits = require('./get-commits');
const getConfig = require('./get-config');
const validateCommit = require('./validate-commit');
const reduceStatuses = require('./reduce-statuses');
const createStatus = require('./create-status');
Expand All @@ -8,8 +9,8 @@ module.exports = async (robot, context) => {

let status;
try {
const commits = await getCommits(github, context);
const statusChain = commits.map(validateCommit);
const [commits, config] = await Promise.all(getCommits(github, context), getConfig(context));
const statusChain = commits.map(commit => validateCommit(config, commit));
status = reduceStatuses(statusChain);
} catch (err) {
status = 'error';
Expand Down
4 changes: 4 additions & 0 deletions lib/reduce-statuses.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ module.exports = function (statusChain) {
return 'failure';
}

if (overallStatus === 'web-flow-ignored') {
return 'web-flow-ignored';
}

return currentStatus;
});
};
6 changes: 5 additions & 1 deletion lib/validate-commit.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
module.exports = function (commit) {
module.exports = function (config, commit) {
if (config.ignoreWebFlow === true && commit.login === 'web-flow') {
return 'web-flow-ignored';
}

if (commit.verification === undefined) {
return 'error';
}
Expand Down

0 comments on commit 6578a87

Please sign in to comment.