Skip to content
Open
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
4 changes: 2 additions & 2 deletions lib/rules/co-authored-by-is-trailer.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ export default {
validate: (context, rule) => {
const parsed = context.toJSON()
const lines = parsed.body.map((line, i) => [line, i])
const re = /^\s*Co-authored-by:/gi
const re = /^Co-authored-by:/gi
const coauthors = lines.filter(([line]) => re.test(line))
if (coauthors.length !== 0) {
const firstCoauthor = coauthors[0]
const emptyLines = lines.filter(([text]) => text.trim().length === 0)
// There must be at least one empty line, and the last empty line must be
// above the first Co-authored-by line.
const isTrailer = (emptyLines.length !== 0) &&
emptyLines.pop()[1] < firstCoauthor[1]
emptyLines.at(-1)[1] < firstCoauthor[1]
if (isTrailer) {
context.report({
id,
Expand Down
31 changes: 31 additions & 0 deletions test/rules/co-authored-by-is-trailer.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,37 @@ test('rule: co-authored-by-is-trailer', (t) => {
Rule.validate(context)
})

t.test('quoting another commit message', (tt) => {
tt.plan(4)
const v = new Validator()
const context = new Commit({
sha: 'e7c077c610afa371430180fbd447bfef60ebc5ea',
author: {
name: 'Foo',
email: 'foo@example.com',
date: '2016-04-12T19:42:23Z'
},
message: 'deps: v8: cherry-pick deadbeef\n' +
'\n' +
'Original commit message:' +
'\n' +
' Some description.\n' +
'\n' +
' Co-authored-by: Someone <someone@example.com>\n' +
'\n' +
'Reviewed-By: Bar <bar@example.com>'
}, v)

context.report = (opts) => {
tt.pass('called report')
tt.equal(opts.id, 'co-authored-by-is-trailer', 'id')
tt.equal(opts.message, 'no Co-authored-by metadata', 'message')
tt.equal(opts.level, 'pass', 'level')
}

Rule.validate(context)
})

t.test('not trailer', (tt) => {
tt.plan(7)
const v = new Validator()
Expand Down