diff --git a/README.md b/README.md index 29e5571..7420091 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/commit-stream.js b/commit-stream.js index 62d9d87..9256272 100644 --- a/commit-stream.js +++ b/commit-stream.js @@ -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] @@ -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 diff --git a/test.js b/test.js index be1b9bf..87f8b11 100644 --- a/test.js +++ b/test.js @@ -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)) } @@ -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() + }) +})