Skip to content

Commit

Permalink
Merge pull request #4 from nodejs/co-authored-by
Browse files Browse the repository at this point in the history
add support for co-authored-by
  • Loading branch information
ralphtheninja authored Jul 18, 2018
2 parents 0eadf45 + cb1488c commit 09fae89
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 11 additions & 5 deletions commit-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
16 changes: 16 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ test('current plain commit log', function (t) {

t.deepEqual(list[list.length - 9], {
author : { email: '[email protected]', name: 'Lars-Magnus Skog' }
, authors : [ { email: '[email protected]', name: 'Lars-Magnus Skog' } ]
, authorDate : 'Tue Feb 9 15:46:46 2016 +0100'
, description : [
'Fixes: https://github.com/rvagg/changelog-maker/issues/35'
Expand All @@ -35,13 +36,15 @@ test('current plain commit log', function (t) {

t.deepEqual(list[list.length - 4], {
author: { email: '[email protected]', name: 'Rod Vagg' }
, authors: [ { email: '[email protected]', name: 'Rod Vagg' } ]
, authorDate: 'Fri Apr 17 11:16:51 2015 +1000'
, sha: 'f92b93c3c7175b07f847dd45058b121cea6b3a20'
, summary: 'deleted package.json line'
}, 'got correct fourth commit')

t.deepEqual(list[list.length - 3], {
author: { email: '[email protected]', name: 'Rod Vagg' }
, authors: [ { email: '[email protected]', name: 'Rod Vagg' } ]
, authorDate: 'Fri Apr 17 11:13:06 2015 +1000'
, description: [ 'comment', 'Reviewed-By: Nobody' ]
, sha: 'db34ce2af09a6a9fb70241d43965a2bc48b90b4c'
Expand All @@ -50,6 +53,7 @@ test('current plain commit log', function (t) {

t.deepEqual(list[list.length - 2], {
author : { email: '[email protected]', name: 'Rod Vagg' }
, authors : [ { email: '[email protected]', name: 'Rod Vagg' } ]
, authorDate: 'Fri Apr 17 10:52:16 2015 +1000'
, description : [
'Some extra summary information here'
Expand All @@ -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: '[email protected]' }
, authors: [ { email: '[email protected]', 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: '[email protected]' }
, authors: [
{ name: 'Anna Henningsen', email: '[email protected]' }
, { name: 'nobody', email: 'nobody@nowhere' }
]
, summary: 'add support for co-authored-by'
}, 'got correct co-authored-by commit')

t.end()
})
})
Expand Down

0 comments on commit 09fae89

Please sign in to comment.