Skip to content

Commit cb1488c

Browse files
addaleaxyashikno
andcommitted
add support for co-authored-by
Co-authored-by: nobody <nobody@nowhere>
1 parent 0eadf45 commit cb1488c

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ Commit object properties:
3737
* `author`: an object representing the author of the commit
3838
- `name`: the name of the committer
3939
- `email`: the email of the committer
40+
* `authors`: a list of such objects representing the authors of the commit, supporting multiple authors through `Co-authored-by:`
4041
* `authorDate`: a string representing the date of the original commit by the author (never change)
4142
* `commitDate`: a string representing the date of the last change of the commit
4243
* `summary`: the one-line summary of the commit

commit-stream.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,21 @@ function commitStream (ghUser, ghProject) {
2323
commit = {
2424
sha: line.split(' ')[1]
2525
}
26-
} else if (m = line.match(/^CommitDate: (.*)$/)) {
26+
} else if (m = line.match(/^CommitDate:\s+(.*)$/)) {
2727
if (!commit)
2828
throw new Error('wut?')
2929
commit.commitDate = m[1].trim()
30-
} else if (m = line.match(/^Author: ([^<]+) <([^>]+)>$/)) {
30+
} else if (m = line.match(/^\s*(?:Author|Co[- ]?authored[- ]?by):?\s*([^<]+) <([^>]+)>\s*$/i)) {
3131
if (!commit)
3232
throw new Error('wut?')
33-
commit.author = { name: m[1], email: m[2] }
34-
} else if (m = line.match(/^AuthorDate: (.*)$/)) {
33+
if (!commit.authors)
34+
commit.authors = []
35+
commit.authors.push({ name: m[1], email: m[2] })
36+
} else if (m = line.match(/^AuthorDate:\s+(.*)$/)) {
3537
if (!commit)
3638
throw new Error('wut?')
3739
commit.authorDate = m[1].trim()
38-
} else if (m = line.match(/^Date: (.*)$/)) {
40+
} else if (m = line.match(/^Date:\s+(.*)$/)) {
3941
if (!commit)
4042
throw new Error('wut?')
4143
commit.authorDate = m[1].trim()
@@ -76,12 +78,16 @@ function commitStream (ghUser, ghProject) {
7678

7779
function onLine (line, _, callback) {
7880
var commit = addLine(line)
81+
if (commit && commit.authors && commit.authors.length > 0)
82+
commit.author = commit.authors[0]
7983
if (commit)
8084
this.push(commit)
8185
callback()
8286
}
8387

8488
function onEnd (callback) {
89+
if (commit && commit.authors && commit.authors.length > 0)
90+
commit.author = commit.authors[0]
8591
if (commit)
8692
this.push(commit)
8793
callback()

test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ test('current plain commit log', function (t) {
2020

2121
t.deepEqual(list[list.length - 9], {
2222
author : { email: 'ralphtheninja@riseup.net', name: 'Lars-Magnus Skog' }
23+
, authors : [ { email: 'ralphtheninja@riseup.net', name: 'Lars-Magnus Skog' } ]
2324
, authorDate : 'Tue Feb 9 15:46:46 2016 +0100'
2425
, description : [
2526
'Fixes: https://github.com/rvagg/changelog-maker/issues/35'
@@ -35,13 +36,15 @@ test('current plain commit log', function (t) {
3536

3637
t.deepEqual(list[list.length - 4], {
3738
author: { email: 'rod@vagg.org', name: 'Rod Vagg' }
39+
, authors: [ { email: 'rod@vagg.org', name: 'Rod Vagg' } ]
3840
, authorDate: 'Fri Apr 17 11:16:51 2015 +1000'
3941
, sha: 'f92b93c3c7175b07f847dd45058b121cea6b3a20'
4042
, summary: 'deleted package.json line'
4143
}, 'got correct fourth commit')
4244

4345
t.deepEqual(list[list.length - 3], {
4446
author: { email: 'rod@vagg.org', name: 'Rod Vagg' }
47+
, authors: [ { email: 'rod@vagg.org', name: 'Rod Vagg' } ]
4548
, authorDate: 'Fri Apr 17 11:13:06 2015 +1000'
4649
, description: [ 'comment', 'Reviewed-By: Nobody' ]
4750
, sha: 'db34ce2af09a6a9fb70241d43965a2bc48b90b4c'
@@ -50,6 +53,7 @@ test('current plain commit log', function (t) {
5053

5154
t.deepEqual(list[list.length - 2], {
5255
author : { email: 'rod@vagg.org', name: 'Rod Vagg' }
56+
, authors : [ { email: 'rod@vagg.org', name: 'Rod Vagg' } ]
5357
, authorDate: 'Fri Apr 17 10:52:16 2015 +1000'
5458
, description : [
5559
'Some extra summary information here'
@@ -69,9 +73,21 @@ test('current plain commit log', function (t) {
6973
sha : 'd94841274e2979e7758413a0f48fa37560d0dde6'
7074
, authorDate: 'Thu Apr 16 20:49:21 2015 +1000'
7175
, author : { name: 'Rod Vagg', email: 'rod@vagg.org' }
76+
, authors: [ { email: 'rod@vagg.org', name: 'Rod Vagg' } ]
7277
, summary: 'make it so'
7378
}, 'got correct first commit')
7479

80+
t.deepEqual(list[list.length - 16], {
81+
sha : list[list.length - 16].sha // unknown at time of writing :)
82+
, authorDate: 'Tue Jun 12 23:41:35 2018 +0200'
83+
, author : { name: 'Anna Henningsen', email: 'anna@addaleax.net' }
84+
, authors: [
85+
{ name: 'Anna Henningsen', email: 'anna@addaleax.net' }
86+
, { name: 'nobody', email: 'nobody@nowhere' }
87+
]
88+
, summary: 'add support for co-authored-by'
89+
}, 'got correct co-authored-by commit')
90+
7591
t.end()
7692
})
7793
})

0 commit comments

Comments
 (0)