Skip to content

Commit 9e87160

Browse files
benglrvagg
authored andcommitted
feat: add support for green-button merges
1 parent c902d56 commit 9e87160

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Commit object properties:
4747
- `insertions`: the number of new lines inserted
4848
- `deletions`: the number of old lines removed
4949
- `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.
50-
- `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.
50+
- `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. Also, if a commit message line ends with ` (#XX)` as is done with green-button merges, this will be used.
5151

5252
## License
5353

commit-stream.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export default function commitStream (ghUser, ghProject) {
4646
commit.reviewers = []
4747
}
4848
commit.reviewers.push({ name: m[1], email: m[2] })
49-
} else if ((m = line.match(/^\s+PR(?:[- ]?URL)?:?\s*(.+)\s*$/)) !== null) {
49+
} else if ((m = line.match(/^\s+PR(?:[- ]?URL)?:?\s*(.+)\s*$/) || line.match(/\(#(\d+)\)$/)) !== null) {
5050
commit.prUrl = m[1]
5151
if (
5252
typeof ghUser === 'string' &&
@@ -66,6 +66,9 @@ export default function commitStream (ghUser, ghProject) {
6666
commit.ghUser = m[2]
6767
commit.ghProject = m[3]
6868
}
69+
if ((m = line.match(/^ {4}(.*)\s\(#\d+\)$/)) && !commit.summary) {
70+
commit.summary = m[1]
71+
}
6972
} else if (/^ {4}/.test(line) && (line = line.trim()).length !== 0) {
7073
if (commit.summary === undefined || commit.summary === null) {
7174
commit.summary = line

test.js

+29-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ import listStream from 'list-stream'
66
import { pipeline } from 'readable-stream'
77
import bl from 'bl'
88

9-
function gitToList (t, gitCmd, callback) {
9+
function gitToList (t, gitCmd, user, repo, callback) {
10+
if (typeof user === 'function') {
11+
callback = user
12+
user = undefined
13+
repo = undefined
14+
}
1015
const child = spawn('bash', ['-c', gitCmd])
1116
child.stderr.pipe(bl((_, out) => {
1217
t.strictEqual(out.toString(), '')
@@ -21,7 +26,7 @@ function gitToList (t, gitCmd, callback) {
2126
pipeline(
2227
child.stdout,
2328
split2(),
24-
commitStream(),
29+
commitStream(user, repo),
2530
listStream.obj(callback),
2631
() => {}
2732
)
@@ -197,3 +202,25 @@ test('current commit log with changes', (t) => {
197202
)
198203
})
199204
})
205+
206+
test('current commit log with ghUser and ghRepo passed', function (t) {
207+
gitToList(t, 'git log', 'rvagg', 'commit-stream', function (err, list) {
208+
t.error(err, 'no error')
209+
210+
t.ok(list && list.length > 1, 'got a list')
211+
212+
t.deepEqual(list[list.length - 18], {
213+
sha: 'b23208796d7e3fd08b36f6106aa7f027aa827137',
214+
authors: [
215+
{ name: 'Rich Trott', email: '[email protected]' }
216+
],
217+
authorDate: 'Mon Oct 11 19:29:18 2021 -0700',
218+
prUrl: 'https://github.com/rvagg/commit-stream/pull/5',
219+
ghIssue: 5,
220+
ghUser: 'rvagg',
221+
ghProject: 'commit-stream',
222+
author: { name: 'Rich Trott', email: '[email protected]' },
223+
summary: 'chore: update strip-ansi to 6.x'
224+
}, 'got correct pr url for green-button merge')
225+
})
226+
})

0 commit comments

Comments
 (0)