Skip to content

Commit

Permalink
Merge pull request dcoapp#14 from probot/ignore-merges
Browse files Browse the repository at this point in the history
Avoid checking for sign off on merges

add env to gitignore

Signed-off-by: Bex Warner <hiimbex@github.com>

update to use current probot version and standards

Signed-off-by: Bex Warner <hiimbex@github.com>

Added error handling and update tests

Signed-off-by: Bex Warner <hiimbex@github.com>

fix logic

Signed-off-by: Bex Warner <hiimbex@github.com>

fix test

Signed-off-by: Bex Warner <hiimbex@github.com>

refactor to use regex

Signed-off-by: Bex Warner <hiimbex@github.com>

update tests for regex

Signed-off-by: Bex Warner <hiimbex@github.com>

target_url = probot/doc/#how-it-works

Signed-off-by: Bex Warner <hiimbex@github.com>
  • Loading branch information
bkeepers authored and Bex Warner committed Aug 18, 2017
2 parents 44bdfa4 + 9e66264 commit 7838e47
Show file tree
Hide file tree
Showing 8 changed files with 4,674 additions and 31 deletions.
2 changes: 0 additions & 2 deletions .env

This file was deleted.

4 changes: 2 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# The ID of your GitHub integration
INTEGRATION_ID=
# The ID of your GitHub App
APP_ID=
WEBHOOK_SECRET=development
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
npm-debug.log
private-key.pem
.env
30 changes: 22 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,45 @@ const defaults = {
},
failure: {
state: 'failure',
description: 'All commits must have a DCO sign-off from the author',
target_url: 'https://developercertificate.org/'
description: '',
target_url: 'https://github.com/probot/dco#how-it-works'
}
};

module.exports = robot => {
robot.on('pull_request.opened', check);
robot.on('pull_request.synchronize', check);

async function check(event, context) {
const github = await robot.auth(event.payload.installation.id);
const pr = event.payload.pull_request;
async function check(context) {
const pr = context.payload.pull_request;

const compare = await github.repos.compareCommits(context.repo({
const compare = await context.github.repos.compareCommits(context.repo({
base: pr.base.sha,
head: pr.head.sha
}));

const signedOff = compare.commits.every(data => dco(data.commit));
let signedOff = true;
compare.data.commits.forEach(commit => {
const res = dco(commit);
if (typeof res === 'string') {
signedOff = false;
if (!defaults.failure.description.includes(res)) {
if (res.includes(`The sign-off is missing.`)) {
defaults.failure.description += res;
} else if (res.includes(`Expected`) && !defaults.failure.description.includes(`Expected`)) {
// Prevents build up of several incorrect error messages
// Only returns the first incorrect error message
defaults.failure.description += res;
}
}
}
});

const params = Object.assign({
sha: pr.head.sha,
context: 'DCO'
}, signedOff ? defaults.success : defaults.failure);

return github.repos.createStatus(context.repo(params));
return context.github.repos.createStatus(context.repo(params));
}
};
23 changes: 20 additions & 3 deletions lib/dco.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
module.exports = commit => {
const signOff = `Signed-off-by: ${commit.author.name} <${commit.author.email}>`;
return commit.message.includes(signOff);
module.exports = ({commit, parents}) => {
const isMerge = parents && parents.length > 1;
const expectedSignOff = `Signed-off-by: ${commit.author.name} <${commit.author.email}>`;
const regex = /^Signed-off-by: (.*) <(.*)>$/m;
let match;

if (isMerge) {
return true;
} else if ((match = regex.exec(commit.message)) === null) {
return 'The sign-off is missing. ';
} else {
match = regex.exec(commit.message);
if (match[0] === expectedSignOff) {
return true;
} else if (!match[0].includes(`Signed-off-by:`)) {
return 'The sign-off is missing. ';
} else if (commit.author.name !== match[1] || commit.author.email !== match[2]) {
return `Expected "${commit.author.name} <${commit.author.email}>", but got "${match[1]} <${match[2]}>" `;
}
}
};
Loading

0 comments on commit 7838e47

Please sign in to comment.