-
Notifications
You must be signed in to change notification settings - Fork 322
/
default-changelog-notes.ts
286 lines (284 loc) · 9.98 KB
/
default-changelog-notes.ts
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
// Copyright 2021 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import {describe, it} from 'mocha';
import {expect} from 'chai';
import {
buildCommitFromFixture,
buildMockCommit,
safeSnapshot,
} from '../helpers';
import {DefaultChangelogNotes} from '../../src/changelog-notes/default';
import {parseConventionalCommits} from '../../src/commit';
describe('DefaultChangelogNotes', () => {
const commits = [
{
sha: 'sha1',
message: 'feat: some feature',
files: ['path1/file1.txt'],
type: 'feat',
scope: null,
bareMessage: 'some feature',
notes: [],
references: [],
breaking: false,
},
{
sha: 'sha2',
message: 'fix!: some bugfix',
files: ['path1/file1.rb'],
type: 'fix',
scope: null,
bareMessage: 'some bugfix',
notes: [{title: 'BREAKING CHANGE', text: 'some bugfix'}],
references: [],
breaking: true,
},
{
sha: 'sha3',
message: 'docs: some documentation',
files: ['path1/file1.java'],
type: 'docs',
scope: null,
bareMessage: 'some documentation',
notes: [],
references: [],
breaking: false,
},
];
describe('buildNotes', () => {
const notesOptions = {
owner: 'googleapis',
repository: 'java-asset',
version: '1.2.3',
previousTag: 'v1.2.2',
currentTag: 'v1.2.3',
targetBranch: 'main',
};
it('should build default release notes', async () => {
const changelogNotes = new DefaultChangelogNotes();
const notes = await changelogNotes.buildNotes(commits, notesOptions);
expect(notes).to.is.string;
safeSnapshot(notes);
});
it('should build with custom changelog sections', async () => {
const changelogNotes = new DefaultChangelogNotes();
const notes = await changelogNotes.buildNotes(commits, {
...notesOptions,
changelogSections: [
{type: 'feat', section: 'Features'},
{type: 'fix', section: 'Bug Fixes'},
{type: 'docs', section: 'Documentation'},
],
});
expect(notes).to.is.string;
safeSnapshot(notes);
});
it('should handle BREAKING CHANGE notes', async () => {
const commits = [
{
sha: 'sha2',
message: 'fix: some bugfix',
files: ['path1/file1.rb'],
type: 'fix',
scope: null,
bareMessage: 'some bugfix',
notes: [{title: 'BREAKING CHANGE', text: 'some bugfix'}],
references: [],
breaking: true,
},
];
const changelogNotes = new DefaultChangelogNotes();
const notes = await changelogNotes.buildNotes(commits, notesOptions);
expect(notes).to.is.string;
safeSnapshot(notes);
});
it('should ignore RELEASE AS notes', async () => {
const commits = [
{
sha: 'sha2',
message: 'fix!: some bugfix',
files: ['path1/file1.rb'],
type: 'fix',
scope: null,
bareMessage: 'some bugfix',
notes: [{title: 'BREAKING CHANGE', text: 'some bugfix'}],
references: [],
breaking: true,
},
];
const changelogNotes = new DefaultChangelogNotes();
const notes = await changelogNotes.buildNotes(commits, notesOptions);
expect(notes).to.is.string;
safeSnapshot(notes);
});
describe('with commit parsing', () => {
it('should handle a breaking change', async () => {
const commits = [buildMockCommit('fix!: some bugfix')];
const changelogNotes = new DefaultChangelogNotes();
const notes = await changelogNotes.buildNotes(
parseConventionalCommits(commits),
notesOptions
);
expect(notes).to.is.string;
safeSnapshot(notes);
});
it('should handle a breaking change with reference', async () => {
const commits = [buildMockCommit('fix!: some bugfix (#1234)')];
const changelogNotes = new DefaultChangelogNotes();
const notes = await changelogNotes.buildNotes(
parseConventionalCommits(commits),
notesOptions
);
expect(notes).to.is.string;
safeSnapshot(notes);
});
it('should parse multiple commit messages from a single commit', async () => {
const commits = [buildCommitFromFixture('multiple-messages')];
const changelogNotes = new DefaultChangelogNotes();
const notes = await changelogNotes.buildNotes(
parseConventionalCommits(commits),
notesOptions
);
expect(notes).to.is.string;
safeSnapshot(notes);
});
it('should handle BREAKING CHANGE body', async () => {
const commits = [buildCommitFromFixture('breaking-body')];
const changelogNotes = new DefaultChangelogNotes();
const notes = await changelogNotes.buildNotes(
parseConventionalCommits(commits),
notesOptions
);
expect(notes).to.is.string;
safeSnapshot(notes);
});
it('should handle bug links', async () => {
const commits = [buildCommitFromFixture('bug-link')];
const changelogNotes = new DefaultChangelogNotes();
const notes = await changelogNotes.buildNotes(
parseConventionalCommits(commits),
notesOptions
);
expect(notes).to.is.string;
safeSnapshot(notes);
});
it('should handle inline bug links', async () => {
const commits = [buildMockCommit('fix: some bugfix (#1234)')];
const changelogNotes = new DefaultChangelogNotes();
const notes = await changelogNotes.buildNotes(
parseConventionalCommits(commits),
notesOptions
);
expect(notes).to.is.string;
safeSnapshot(notes);
});
it('should handle git trailers', async () => {
const commits = [buildCommitFromFixture('git-trailers-with-breaking')];
const changelogNotes = new DefaultChangelogNotes();
const notes = await changelogNotes.buildNotes(
parseConventionalCommits(commits),
notesOptions
);
expect(notes).to.is.string;
safeSnapshot(notes);
});
it('should handle meta commits', async () => {
const commits = [buildCommitFromFixture('meta')];
const changelogNotes = new DefaultChangelogNotes();
const notes = await changelogNotes.buildNotes(
parseConventionalCommits(commits),
notesOptions
);
expect(notes).to.is.string;
safeSnapshot(notes);
});
it('should handle multi-line breaking changes', async () => {
const commits = [buildCommitFromFixture('multi-line-breaking-body')];
const changelogNotes = new DefaultChangelogNotes();
const notes = await changelogNotes.buildNotes(
parseConventionalCommits(commits),
notesOptions
);
expect(notes).to.is.string;
safeSnapshot(notes);
});
it('should handle multi-line breaking change, if prefixed with list', async () => {
const commits = [
buildCommitFromFixture('multi-line-breaking-body-list'),
];
const changelogNotes = new DefaultChangelogNotes();
const notes = await changelogNotes.buildNotes(
parseConventionalCommits(commits),
notesOptions
);
expect(notes).to.is.string;
safeSnapshot(notes);
});
it('should not include content two newlines after BREAKING CHANGE', async () => {
const commits = [buildCommitFromFixture('breaking-body-content-after')];
const changelogNotes = new DefaultChangelogNotes();
const notes = await changelogNotes.buildNotes(
parseConventionalCommits(commits),
notesOptions
);
expect(notes).to.is.string;
safeSnapshot(notes);
});
it('handles Release-As footers', async () => {
const commits = [buildCommitFromFixture('release-as')];
const changelogNotes = new DefaultChangelogNotes();
const notes = await changelogNotes.buildNotes(
parseConventionalCommits(commits),
notesOptions
);
expect(notes).to.is.string;
safeSnapshot(notes);
});
it('should allow customizing sections', async () => {
const commits = [buildMockCommit('chore: some chore')];
const changelogNotes = new DefaultChangelogNotes();
const notes = await changelogNotes.buildNotes(
parseConventionalCommits(commits),
{
...notesOptions,
changelogSections: [
{type: 'chore', section: 'Miscellaneous Chores'},
],
}
);
expect(notes).to.is.string;
safeSnapshot(notes);
});
it('should handle html tags', async () => {
const commits = [
buildMockCommit('feat: render all imagesets as <picture>'),
];
const changelogNotes = new DefaultChangelogNotes();
const notes = await changelogNotes.buildNotes(
parseConventionalCommits(commits),
notesOptions
);
expect(notes).to.is.string;
safeSnapshot(notes);
});
// it('ignores reverted commits', async () => {
// const commits = [buildCommitFromFixture('multiple-messages')];
// const changelogNotes = new DefaultChangelogNotes();
// const notes = await changelogNotes.buildNotes(parseConventionalCommits(commits), notesOptions);
// expect(notes).to.is.string;
// safeSnapshot(notes);
// });
});
});
});