forked from cookpete/auto-changelog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreleases.js
131 lines (124 loc) · 4.25 KB
/
releases.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
const { describe, it, afterEach } = require('mocha')
const { expect } = require('chai')
const remotes = require('./data/remotes')
const { generateCommits } = require('./utils/commits')
const {
parseReleases,
__Rewire__: mock,
__ResetDependency__: unmock
} = require('../src/releases')
describe('parseReleases', () => {
afterEach(() => {
unmock('fetchCommits')
})
it('parses releases', async () => {
const map = {
'v1.0.0..v2.0.0': generateCommits([
'Merge pull request #4 from branch\n\nSixth commit',
'Fifth commit\nFixes #3',
'Fourth commit'
]),
'v1.0.0': generateCommits([
'Merge pull request #2 from branch\n\nThird commit',
'Second commit\nFixes #1',
'First commit'
])
}
mock('fetchCommits', diff => Promise.resolve(map[diff]))
const options = {
commitLimit: 3,
backfillLimit: 3,
tagPrefix: '',
latestVersion: null,
...remotes.github
}
const tags = [
{
tag: 'v2.0.0',
date: '2000-01-01',
diff: 'v1.0.0..v2.0.0',
major: true,
href: 'https://github.com/user/repo/compare/v1.0.0...v2.0.0'
},
{
tag: 'v1.0.0',
date: '2000-01-01',
diff: 'v1.0.0',
major: false,
href: null
}
]
const releases = await parseReleases(tags, options)
expect(releases).to.be.an('array')
expect(releases[0]).to.include({
tag: 'v2.0.0',
major: true,
href: 'https://github.com/user/repo/compare/v1.0.0...v2.0.0'
})
expect(releases[0].commits).to.have.lengthOf(1)
expect(releases[0].commits[0]).to.include({ subject: 'Fourth commit' })
expect(releases[1]).to.include({
tag: 'v1.0.0',
major: false,
href: null
})
expect(releases[1].commits).to.have.lengthOf(1)
expect(releases[1].commits[0]).to.include({ subject: 'First commit' })
})
it('applies commitLimit', async () => {
const map = {
'v1.0.0': generateCommits(['Second commit', 'First commit\nFixes #1'])
}
mock('fetchCommits', diff => Promise.resolve(map[diff]))
const options = { commitLimit: 1 }
const tags = [{ tag: 'v1.0.0', date: '2000-01-01', diff: 'v1.0.0' }]
const releases = await parseReleases(tags, options)
expect(releases[0].commits).to.have.lengthOf(1)
expect(releases[0].commits[0]).to.include({ subject: 'Second commit' })
})
it('false commitLimit', async () => {
const map = {
'v1.0.0': generateCommits(['Fourth commit', 'Third commit', 'Second commit', 'First commit'])
}
mock('fetchCommits', diff => Promise.resolve(map[diff]))
const options = { commitLimit: false }
const tags = [{ tag: 'v1.0.0', date: '2000-01-01', diff: 'v1.0.0' }]
const releases = await parseReleases(tags, options)
expect(releases[0].commits).to.have.lengthOf(4)
})
it('applies backfillLimit', async () => {
const map = {
'v1.0.0': generateCommits(['Second commit', 'First commit'])
}
mock('fetchCommits', diff => Promise.resolve(map[diff]))
const options = { backfillLimit: 1 }
const tags = [{ tag: 'v1.0.0', date: '2000-01-01', diff: 'v1.0.0' }]
const releases = await parseReleases(tags, options)
expect(releases[0].commits).to.have.lengthOf(1)
expect(releases[0].commits[0]).to.include({ subject: 'Second commit' })
})
it('includes breaking commits', async () => {
const map = {
'v1.0.0': generateCommits([
{ message: 'Second commit' },
{ message: 'First commit', breaking: true }
])
}
mock('fetchCommits', diff => Promise.resolve(map[diff]))
const options = { commitLimit: 0, backfillLimit: 0 }
const tags = [{ tag: 'v1.0.0', date: '2000-01-01', diff: 'v1.0.0' }]
const releases = await parseReleases(tags, options)
expect(releases[0].commits).to.have.lengthOf(1)
expect(releases[0].commits[0]).to.include({ subject: 'First commit' })
})
it('hides empty releases', async () => {
const map = {
'v1.0.0': []
}
mock('fetchCommits', diff => Promise.resolve(map[diff]))
const options = { hideEmptyReleases: true }
const tags = [{ tag: 'v1.0.0', date: '2000-01-01', diff: 'v1.0.0' }]
const releases = await parseReleases(tags, options)
expect(releases).to.have.lengthOf(0)
})
})