diff --git a/README.md b/README.md index bdda70a..29e5571 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,7 @@ Commit object properties: * `author`: an object representing the author of the commit - `name`: the name of the committer - `email`: the email of the committer +* `authors`: a list of such objects representing the authors of the commit, supporting multiple authors through `Co-authored-by:` * `authorDate`: a string representing the date of the original commit by the author (never change) * `commitDate`: a string representing the date of the last change of the commit * `summary`: the one-line summary of the commit diff --git a/commit-stream.js b/commit-stream.js index 61b8d92..62d9d87 100644 --- a/commit-stream.js +++ b/commit-stream.js @@ -23,19 +23,21 @@ function commitStream (ghUser, ghProject) { commit = { sha: line.split(' ')[1] } - } else if (m = line.match(/^CommitDate: (.*)$/)) { + } else if (m = line.match(/^CommitDate:\s+(.*)$/)) { if (!commit) throw new Error('wut?') commit.commitDate = m[1].trim() - } else if (m = line.match(/^Author: ([^<]+) <([^>]+)>$/)) { + } else if (m = line.match(/^\s*(?:Author|Co[- ]?authored[- ]?by):?\s*([^<]+) <([^>]+)>\s*$/i)) { if (!commit) throw new Error('wut?') - commit.author = { name: m[1], email: m[2] } - } else if (m = line.match(/^AuthorDate: (.*)$/)) { + if (!commit.authors) + commit.authors = [] + commit.authors.push({ name: m[1], email: m[2] }) + } else if (m = line.match(/^AuthorDate:\s+(.*)$/)) { if (!commit) throw new Error('wut?') commit.authorDate = m[1].trim() - } else if (m = line.match(/^Date: (.*)$/)) { + } else if (m = line.match(/^Date:\s+(.*)$/)) { if (!commit) throw new Error('wut?') commit.authorDate = m[1].trim() @@ -76,12 +78,16 @@ function commitStream (ghUser, ghProject) { function onLine (line, _, callback) { var commit = addLine(line) + if (commit && commit.authors && commit.authors.length > 0) + commit.author = commit.authors[0] if (commit) this.push(commit) callback() } function onEnd (callback) { + if (commit && commit.authors && commit.authors.length > 0) + commit.author = commit.authors[0] if (commit) this.push(commit) callback() diff --git a/test.js b/test.js index 27525ab..be1b9bf 100644 --- a/test.js +++ b/test.js @@ -20,6 +20,7 @@ test('current plain commit log', function (t) { t.deepEqual(list[list.length - 9], { author : { email: 'ralphtheninja@riseup.net', name: 'Lars-Magnus Skog' } + , authors : [ { email: 'ralphtheninja@riseup.net', name: 'Lars-Magnus Skog' } ] , authorDate : 'Tue Feb 9 15:46:46 2016 +0100' , description : [ 'Fixes: https://github.com/rvagg/changelog-maker/issues/35' @@ -35,6 +36,7 @@ test('current plain commit log', function (t) { t.deepEqual(list[list.length - 4], { author: { email: 'rod@vagg.org', name: 'Rod Vagg' } + , authors: [ { email: 'rod@vagg.org', name: 'Rod Vagg' } ] , authorDate: 'Fri Apr 17 11:16:51 2015 +1000' , sha: 'f92b93c3c7175b07f847dd45058b121cea6b3a20' , summary: 'deleted package.json line' @@ -42,6 +44,7 @@ test('current plain commit log', function (t) { t.deepEqual(list[list.length - 3], { author: { email: 'rod@vagg.org', name: 'Rod Vagg' } + , authors: [ { email: 'rod@vagg.org', name: 'Rod Vagg' } ] , authorDate: 'Fri Apr 17 11:13:06 2015 +1000' , description: [ 'comment', 'Reviewed-By: Nobody' ] , sha: 'db34ce2af09a6a9fb70241d43965a2bc48b90b4c' @@ -50,6 +53,7 @@ test('current plain commit log', function (t) { t.deepEqual(list[list.length - 2], { author : { email: 'rod@vagg.org', name: 'Rod Vagg' } + , authors : [ { email: 'rod@vagg.org', name: 'Rod Vagg' } ] , authorDate: 'Fri Apr 17 10:52:16 2015 +1000' , description : [ 'Some extra summary information here' @@ -69,9 +73,21 @@ test('current plain commit log', function (t) { sha : 'd94841274e2979e7758413a0f48fa37560d0dde6' , authorDate: 'Thu Apr 16 20:49:21 2015 +1000' , author : { name: 'Rod Vagg', email: 'rod@vagg.org' } + , authors: [ { email: 'rod@vagg.org', name: 'Rod Vagg' } ] , summary: 'make it so' }, 'got correct first commit') + t.deepEqual(list[list.length - 16], { + sha : list[list.length - 16].sha // unknown at time of writing :) + , authorDate: 'Tue Jun 12 23:41:35 2018 +0200' + , author : { name: 'Anna Henningsen', email: 'anna@addaleax.net' } + , authors: [ + { name: 'Anna Henningsen', email: 'anna@addaleax.net' } + , { name: 'nobody', email: 'nobody@nowhere' } + ] + , summary: 'add support for co-authored-by' + }, 'got correct co-authored-by commit') + t.end() }) })