Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/dco.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@ module.exports = async function (commits, isRequiredFor) {
if (signoffRequired) return failure(`The sign-off is missing.`)
if (!commit.verification.verified) return failure(`Commit by organization member is not verified.`)
} else {
if (!validator.validate(commit.author.email)) return failure(`${commit.author.email} is not a valid email address.`)
if (commit.author.name.toLowerCase() !== match[1].toLowerCase() || commit.author.email.toLowerCase() !== match[2].toLowerCase()) {
if (!(validator.validate(commit.author.email || commit.committer.email))) {
return failure(`${commit.author.email} is not a valid email address.`)
}
const authors = [commit.author.name.toLowerCase(), commit.committer.name.toLowerCase()]
const emails = [commit.author.email.toLowerCase(), commit.committer.email.toLowerCase()]
if (!(authors.includes(match[1].toLowerCase())) || !(emails.includes(match[2].toLowerCase()))) {
return failure(`Expected "${commit.author.name} <${commit.author.email}>", but got "${match[1]} <${match[2]}>".`)
}
}
Expand Down
96 changes: 96 additions & 0 deletions test/dco.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ describe('dco', () => {
author: {
name: 'Brandon Keepers',
email: 'bkeepers@github.com'
},
committer: {
name: 'Bex Warner',
email: 'bexmwarner@gmail.com'
}
}
const dcoObject = await getDCOStatus([{commit, author: { login: 'bkeepers' }, parents: []}], alwaysRequireSignoff)
Expand All @@ -28,6 +32,10 @@ describe('dco', () => {
author: {
name: 'Brandon Keepers',
email: 'bkeepers@github.com'
},
committer: {
name: 'Bex Warner',
email: 'bexmwarner@gmail.com'
}
}
const dcoObject = await getDCOStatus([{commit, author: { login: 'bkeepers' }, parents: [1, 2]}], alwaysRequireSignoff)
Expand All @@ -41,6 +49,10 @@ describe('dco', () => {
author: {
name: 'Brandon Keepers',
email: 'bkeepers@github.com'
},
committer: {
name: 'Bex Warner',
email: 'bexmwarner@gmail.com'
}
}
const dcoObject = await getDCOStatus([{commit, author: { login: 'bkeepers' }, parents: []}], alwaysRequireSignoff)
Expand All @@ -60,6 +72,10 @@ describe('dco', () => {
author: {
name: 'hiimbex',
email: 'bex@disney.com'
},
committer: {
name: 'Bex Warner',
email: 'bexmwarner@gmail.com'
}
}
const dcoObject = await getDCOStatus([{commit, author: { login: 'hiimbex' }, parents: []}], alwaysRequireSignoff)
Expand All @@ -80,6 +96,10 @@ describe('dco', () => {
author: {
name: 'bex',
email: 'hiimbex@disney.com'
},
committer: {
name: 'Bex Warner',
email: 'bexmwarner@gmail.com'
}
}
const dcoObject = await getDCOStatus([{commit, author: { login: 'hiimbex' }, parents: []}], alwaysRequireSignoff)
Expand All @@ -100,6 +120,10 @@ describe('dco', () => {
author: {
name: 'bex',
email: 'bex@disney.com'
},
committer: {
name: 'Bex Warner',
email: 'bexmwarner@gmail.com'
}
}
const dcoObject = await getDCOStatus([{commit, author: { login: 'hiimbex' }, parents: []}], alwaysRequireSignoff)
Expand All @@ -120,13 +144,21 @@ describe('dco', () => {
author: {
name: 'bex',
email: 'bex@disney.com'
},
committer: {
name: 'Bex Warner',
email: 'bexmwarner@gmail.com'
}
}
const commitB = {
message: 'signed off correctly\n\nSigned-off-by: bex <bex@disney.com>',
author: {
name: 'bex',
email: 'bex@disney.com'
},
committer: {
name: 'Bex Warner',
email: 'bexmwarner@gmail.com'
}
}
const dcoObject = await getDCOStatus([{commit: commitA, author: { login: 'hiimbex' }, parents: []}, {commit: commitB, author: { login: 'hiimbex' }, parents: []}], alwaysRequireSignoff)
Expand All @@ -147,13 +179,21 @@ describe('dco', () => {
author: {
name: 'bex',
email: 'bex@disney.com'
},
committer: {
name: 'Bex Warner',
email: 'bexmwarner@gmail.com'
}
}
const commitB = {
message: 'signed off by wrong author\n\nSigned-off-by: hiimbex <hiimbex@disney.com>',
author: {
name: 'bex',
email: 'bex@disney.com'
},
committer: {
name: 'Bex Warner',
email: 'bexmwarner@gmail.com'
}
}
const dcoObject = await getDCOStatus([{commit: commitA, author: { login: 'hiimbex' }, parents: []}, {commit: commitB, author: { login: 'hiimbex' }, parents: []}], alwaysRequireSignoff)
Expand All @@ -172,13 +212,21 @@ describe('dco', () => {
author: {
name: 'bex',
email: 'bex@disney.com'
},
committer: {
name: 'Bex Warner',
email: 'bexmwarner@gmail.com'
}
}
const commitB = {
message: 'signed off by wrong author\n\nSigned-off-by: bex <bex@disney.com>',
author: {
name: 'bex',
email: 'bex@disney.com'
},
committer: {
name: 'Bex Warner',
email: 'bexmwarner@gmail.com'
}
}
const dcoObject = await getDCOStatus([{commit: commitA, author: { login: 'hiimbex' }, parents: []}, {commit: commitB, author: { login: 'hiimbex' }, parents: []}], alwaysRequireSignoff)
Expand All @@ -194,6 +242,10 @@ describe('dco', () => {
author: {
name: 'bex is the best name ever and is also very long',
email: 'bexMyVeryLongAlsoButImportantEmail@disney.com'
},
committer: {
name: 'Bex Warner',
email: 'bexmwarner@gmail.com'
}
}
const dcoObject = await getDCOStatus([{commit, author: { login: 'hiimbex' }, parents: []}], alwaysRequireSignoff)
Expand All @@ -214,6 +266,10 @@ describe('dco', () => {
author: {
name: 'hiimbex',
email: 'hiimbex@disney.com'
},
committer: {
name: 'Bex Warner',
email: 'bexmwarner@gmail.com'
}
}
const dcoObject = await getDCOStatus([{commit, author: { login: 'hiimbex' }, parents: []}], alwaysRequireSignoff)
Expand All @@ -228,6 +284,10 @@ describe('dco', () => {
author: {
name: 'hiimbex',
email: 'hiimbex@bexo'
},
committer: {
name: 'Bex Warner',
email: 'bexmwarner@gmail.com'
}
}
const dcoObject = await getDCOStatus([{commit, author: { login: 'hiimbex' }, parents: []}], alwaysRequireSignoff)
Expand All @@ -245,6 +305,10 @@ describe('dco', () => {
author: {
name: 'hiimbexo',
email: 'hiimbex@bexo.com'
},
committer: {
name: 'Bex Warner',
email: 'bexmwarner@gmail.com'
}
}
const dcoObject = await getDCOStatus([{commit, author: { login: 'hiimbex' }, parents: []}], alwaysRequireSignoff)
Expand All @@ -258,6 +322,10 @@ describe('dco', () => {
author: {
name: 'bexobot [bot]',
email: 'wut'
},
committer: {
name: 'Bex Warner',
email: 'bexmwarner@gmail.com'
}
}
const author = {
Expand All @@ -278,6 +346,10 @@ describe('dco', () => {
name: 'Lorant Pinter',
email: 'lorant.pinter@gmail.com'
},
committer: {
name: 'Bex Warner',
email: 'bexmwarner@gmail.com'
},
verification: {
verified: true
}
Expand All @@ -297,6 +369,10 @@ describe('dco', () => {
name: 'Lorant Pinter',
email: 'lorant.pinter@gmail.com'
},
committer: {
name: 'Bex Warner',
email: 'bexmwarner@gmail.com'
},
verification: {
verified: false
}
Expand All @@ -310,4 +386,24 @@ describe('dco', () => {
}))
}
)

test(
'returns success if commit.author is different but commit.committer matches',
async () => {
const commit = {
message: 'What a nice day!\n\nSigned-off-by: Bex Warner <bexmwarner@gmail.com>',
author: {
name: 'Bexo',
email: 'bexo@gmail.com'
},
committer: {
name: 'Bex Warner',
email: 'bexmwarner@gmail.com'
}
}
const dcoObject = await getDCOStatus([{commit, author: { login: 'hiimbex' }, parents: []}], alwaysRequireSignoff)

expect(JSON.stringify(dcoObject)).toBe(success)
}
)
})