Skip to content

Commit c6dd5ef

Browse files
authored
Merge pull request #35 from probot/email-format
add check for valid email format and test
2 parents 488e528 + 2f76679 commit c6dd5ef

File tree

4 files changed

+29
-0
lines changed

4 files changed

+29
-0
lines changed

lib/dco.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const validator = require('email-validator')
2+
13
// Returns the DCO object containing state and description
24
// Also returns target_url (in case of failure) in object
35
module.exports = function (commits) {
@@ -25,6 +27,10 @@ module.exports = function (commits) {
2527
signedOff = false
2628
defaults.failure.description = `The sign-off is missing.`
2729
} else {
30+
if (!validator.validate(commit.author.email)) {
31+
signedOff = false
32+
defaults.failure.description = `${commit.author.email} is not a valid email address.`
33+
}
2834
match = regex.exec(commit.message)
2935
if (commit.author.name !== match[1] || commit.author.email !== match[2]) {
3036
signedOff = false

package-lock.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
]
2727
},
2828
"dependencies": {
29+
"email-validator": "^1.1.1",
2930
"probot": "^0.11.0"
3031
}
3132
}

test/dco.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,4 +195,21 @@ describe('dco', () => {
195195

196196
expect(JSON.stringify(dcoObject)).toBe(success)
197197
})
198+
199+
it('returns failure when email is invalid', () => {
200+
const commit = {
201+
message: 'bad email\n\nsigned-off-by: hiimbex <hiimbex@bexo>',
202+
author: {
203+
name: 'hiimbex',
204+
email: 'hiimbex@bexo'
205+
}
206+
}
207+
const dcoObject = getDCOStatus([{commit, parents: []}])
208+
209+
expect(JSON.stringify(dcoObject)).toBe(JSON.stringify({
210+
state: 'failure',
211+
description: 'hiimbex@bexo is not a valid email address.',
212+
target_url: 'https://github.com/probot/dco#how-it-works'
213+
}))
214+
})
198215
})

0 commit comments

Comments
 (0)