Skip to content
Closed
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Commit object properties:
- `files`: the number of files changed
- `insertions`: the number of new lines inserted
- `deletions`: the number of old lines removed
* `prUrl`: a URL pointing to a pull-request where this change was made if the commit metadata contains a `PR-URL: https://github.com/user/project/pull/XX` line. Note that whatever proceeds the `PR-URL: ` string will be collected in this property; one exception being that if a shortened `#XX` version is found and you have supplied `defaultGitHubUser` and `defaultGitHubProject` arguments to the constructor then a full GitHub pull-request will be reconstituted in its place.
* `prUrl`: a URL pointing to a pull-request where this change was made if the commit metadata contains a `PR-URL: https://github.com/user/project/pull/XX` line. Note that whatever proceeds the `PR-URL: ` string will be collected in this property; one exception being that if a shortened `#XX` version is found and you have supplied `defaultGitHubUser` and `defaultGitHubProject` arguments to the constructor then a full GitHub pull-request will be reconstituted in its place. Also, if a commit message line ends with ` (#XX)` as is done with green-button merges, this will be used.
* `ghUser`, `ghProject, `ghIssue`: if a proper GitHub pull request is found for the `prUrl` property (including shortened `#XX` ones), these properties will be added to point to the original user, project and issue (pull-request) for this change, as extracted from the URL.

## License
Expand Down
5 changes: 4 additions & 1 deletion commit-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function commitStream (ghUser, ghProject) {
if (!commit.reviewers)
commit.reviewers = []
commit.reviewers.push({ name: m[1], email: m[2] })
} else if (m = line.match(/^\s+PR(?:[- ]?URL)?:?\s*(.+)\s*$/)) {
} else if (m = line.match(/^\s+PR(?:[- ]?URL)?:?\s*(.+)\s*$/) || line.match(/\(#(\d+)\)$/)) {
commit.prUrl = m[1]
if (ghUser && ghProject && (m = commit.prUrl.match(/^\s*#?(\d+)\s*$/))) {
commit.prUrl = 'https://github.com/' + ghUser + '/' + ghProject + '/pull/' + m[1]
Expand All @@ -55,6 +55,9 @@ function commitStream (ghUser, ghProject) {
commit.ghUser = m[2]
commit.ghProject = m[3]
}
if ((m = line.match(/^ (.*)\s\(#\d+\)$/)) && !commit.summary) {
commit.summary = m[1]
}
} else if (/^ /.test(line) && (line = line.trim()).length) {
if (!commit.summary) {
commit.summary = line
Expand Down
33 changes: 31 additions & 2 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@ const through2 = require('through2')
, listStream = require('list-stream')


function gitToList (gitCmd, callback) {
function gitToList (gitCmd, user, repo, callback) {
if (typeof user === 'function') {
callback = user
user = undefined
repo = undefined
}
var child = spawn('bash', [ '-c', gitCmd ])
child.stdout.pipe(split2()).pipe(commitStream()).pipe(listStream.obj(callback))
child.stdout.pipe(split2()).pipe(commitStream(user, repo)).pipe(listStream.obj(callback))
}


Expand Down Expand Up @@ -126,3 +131,27 @@ test('current commit log with changes', function (t) {
t.end()
})
})

test('current commit log with ghUser and ghRepo passed', function (t) {
gitToList('git log', 'rvagg', 'commit-stream', function (err, list) {
t.error(err, 'no error')

t.ok(list && list.length > 1, 'got a list')

t.deepEqual(list[list.length - 18], {
sha : 'b23208796d7e3fd08b36f6106aa7f027aa827137'
, authorDate: 'Mon Oct 11 19:29:18 2021 -0700'
, author : { name: 'Rich Trott', email: 'rtrott@gmail.com' }
, authors: [
{ name: 'Rich Trott', email: 'rtrott@gmail.com' }
]
, ghIssue : 5
, ghProject : 'commit-stream'
, ghUser : 'rvagg'
, prUrl : 'https://github.com/rvagg/commit-stream/pull/5'
, summary: 'chore: update strip-ansi to 6.x'
}, 'got correct pr url for green-button merge')

t.end()
})
})