From 0fdb636dde237062406d556b3129bede20a24da5 Mon Sep 17 00:00:00 2001 From: Bex Warner Date: Mon, 9 Jul 2018 09:57:03 -0700 Subject: [PATCH] fix regression from #77 and add test Signed-off-by: Bex Warner --- lib/dco.js | 2 +- test/dco.test.js | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/lib/dco.js b/lib/dco.js index c335048..edba0dc 100644 --- a/lib/dco.js +++ b/lib/dco.js @@ -17,7 +17,7 @@ module.exports = async function (commits, isRequiredFor) { const signoffRequired = !author || await isRequiredFor(author.login) if (isMerge || (!signoffRequired && commit.verification.verified)) { continue - } else if (!author || author.type === 'Bot') { + } else if (author && author.type === 'Bot') { continue } const match = regex.exec(commit.message) diff --git a/test/dco.test.js b/test/dco.test.js index d3b397c..79074b2 100644 --- a/test/dco.test.js +++ b/test/dco.test.js @@ -427,4 +427,29 @@ describe('dco', () => { expect(JSON.stringify(dcoObject)).toBe(success) } ) + + test( + 'returns failure if author does not exist and there is no sign off', + async () => { + const commit = { + message: 'What a nice day!', + author: { + name: 'Bexo', + email: 'bexo@gmail.com' + }, + committer: { + name: 'Bex Warner', + email: 'bexmwarner@gmail.com' + } + } + const author = null + const dcoObject = await getDCOStatus([{commit, author, parents: []}], alwaysRequireSignoff) + + expect(JSON.stringify(dcoObject)).toBe(JSON.stringify({ + state: 'failure', + description: 'The sign-off is missing.', + target_url: 'https://github.com/probot/dco#how-it-works' + })) + } + ) })