-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathcommit-to-list.js
76 lines (66 loc) · 2.29 KB
/
commit-to-list.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import _debug from 'debug'
import process from 'process'
import { pipeline as _pipeline } from 'stream'
import { promisify } from 'util'
import commitStream from 'commit-stream'
import gitexec from 'gitexec'
import split2 from 'split2'
import { isReleaseCommit } from './groups.js'
const debug = _debug('changelog-maker')
const pipeline = promisify(_pipeline)
const gitcmd = 'git log --pretty=full --since="{{sincecmd}}" --until="{{untilcmd}}"'
const commitdatecmd = '$(git show -s --format=%cd `{{refcmd}}`)'
const untilcmd = ''
const defaultRef = '--tags=v*.*.* 2> /dev/null ' +
'|| git rev-list --max-count=1 --tags=*.*.* 2> /dev/null ' +
'|| git rev-list --max-count=1 HEAD'
function replace (s, m) {
Object.keys(m).forEach((k) => {
s = s.replace(new RegExp(`\\{\\{${k}\\}\\}`, 'g'), m[k])
})
return s
}
function organiseCommits (argv, list) {
if (argv['start-ref'] || argv.a || argv.all) {
if (argv['filter-release']) {
list = list.filter((commit) => !isReleaseCommit(commit.summary))
}
return list
}
// filter commits to those _before_ 'working on ...'
let started = false
return list.filter((commit) => {
if (started) {
return false
}
if (isReleaseCommit(commit.summary)) {
started = true
}
return !started
})
}
export async function commitToList (ghId, argv) {
const refcmd = argv.a || argv.all ? 'git rev-list --max-parents=0 HEAD' : 'git rev-list --max-count=1 {{ref}}'
const _startrefcmd = replace(refcmd, { ref: argv['start-ref'] || defaultRef })
const _endrefcmd = argv['end-ref'] && replace(refcmd, { ref: argv['end-ref'] })
const _sincecmd = replace(commitdatecmd, { refcmd: _startrefcmd })
const _untilcmd = argv['end-ref'] ? replace(commitdatecmd, { refcmd: _endrefcmd }) : untilcmd
const _gitcmd = replace(gitcmd, { sincecmd: _sincecmd, untilcmd: _untilcmd })
debug('%s', _startrefcmd)
debug('%s', _endrefcmd)
debug('%s', _sincecmd)
debug('%s', _untilcmd)
debug('%s', _gitcmd)
let commitList = []
await pipeline(
gitexec.exec(process.cwd(), _gitcmd),
split2(),
commitStream(ghId.user, ghId.repo),
async function * (source) {
for await (const commit of source) {
commitList.push(commit)
}
})
commitList = organiseCommits(argv, commitList)
return commitList
}