-
Notifications
You must be signed in to change notification settings - Fork 26
/
displaycommits.js
339 lines (283 loc) · 10.5 KB
/
displaycommits.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
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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
/**
* @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md.
*/
'use strict';
const expect = require( 'chai' ).expect;
const sinon = require( 'sinon' );
const proxyquire = require( 'proxyquire' );
describe( 'dev-env/release-tools/utils', () => {
let displayCommits, sandbox, stubs;
beforeEach( () => {
sandbox = sinon.createSandbox();
stubs = {
logger: {
info: sandbox.spy(),
warning: sandbox.spy(),
error: sandbox.spy()
}
};
displayCommits = proxyquire( '../../../lib/release-tools/utils/displaycommits', {
'@ckeditor/ckeditor5-dev-utils': {
logger() {
return stubs.logger;
}
}
} );
} );
afterEach( () => {
sandbox.restore();
} );
describe( 'displayCommits()', () => {
it( 'prints if there is no commit to display', () => {
displayCommits( [] );
expect( stubs.logger.info.calledOnce ).to.equal( true );
expect( stubs.logger.info.firstCall.args[ 0 ] ).includes( 'No commits to display.' );
} );
it( 'attaches valid "external" commit to the changelog (as Array)', () => {
const commit = {
hash: '684997d',
header: 'Fix: Simple fix.',
type: 'Bug fixes',
rawType: 'Fix',
subject: 'Simple fix.',
body: null,
footer: null,
notes: []
};
displayCommits( [ commit ] );
expect( stubs.logger.info.calledOnce ).to.equal( true );
expect( stubs.logger.info.firstCall.args[ 0 ].includes( 'Fix: Simple fix.' ) ).to.equal( true );
expect( stubs.logger.info.firstCall.args[ 0 ].includes( 'INCLUDED' ) ).to.equal( true );
} );
it( 'attaches valid "external" commit to the changelog (as Set)', () => {
const commit = {
hash: '684997d',
header: 'Fix: Simple fix.',
type: 'Bug fixes',
rawType: 'Fix',
subject: 'Simple fix.',
body: null,
footer: null,
notes: []
};
displayCommits( new Set( [ commit ] ) );
expect( stubs.logger.info.calledOnce ).to.equal( true );
expect( stubs.logger.info.firstCall.args[ 0 ].includes( 'Fix: Simple fix.' ) ).to.equal( true );
expect( stubs.logger.info.firstCall.args[ 0 ].includes( 'INCLUDED' ) ).to.equal( true );
} );
it( 'truncates too long commit\'s subject', () => {
const commit = {
hash: '684997d',
header: 'Fix: Reference site about Lorem Ipsum, giving information on its origins, as well as ' +
'a random Lipsum generator.',
type: 'Bug fixes',
rawType: 'Fix',
subject: 'Reference site about Lorem Ipsum, giving information on its origins, as well as ' +
'a random Lipsum generator.',
body: null,
footer: null,
notes: []
};
displayCommits( [ commit ] );
expect( stubs.logger.info.calledOnce ).to.equal( true );
expect( stubs.logger.info.firstCall.args[ 0 ].includes(
'Fix: Reference site about Lorem Ipsum, giving information on its origins, as well as a random Lip...'
) ).to.equal( true );
expect( stubs.logger.info.firstCall.args[ 0 ].includes( 'INCLUDED' ) ).to.equal( true );
} );
it( 'does not attach valid "internal" commit to the changelog', () => {
const commit = {
hash: '684997d',
header: 'Docs: README.',
type: 'Docs',
rawType: 'Docs',
subject: 'README.',
body: null,
footer: null,
notes: []
};
displayCommits( [ commit ] );
expect( stubs.logger.info.calledOnce ).to.equal( true );
expect( stubs.logger.info.firstCall.args[ 0 ].includes( 'Docs: README.' ) ).to.equal( true );
expect( stubs.logger.info.firstCall.args[ 0 ].includes( 'SKIPPED' ) ).to.equal( true );
} );
it( 'does not attach invalid commit to the changelog', () => {
const commit = {
hash: '684997d',
header: 'Invalid commit.',
type: null,
subject: null,
body: null,
footer: null,
notes: []
};
displayCommits( [ commit ] );
expect( stubs.logger.info.calledOnce ).to.equal( true );
expect( stubs.logger.info.firstCall.args[ 0 ].includes( 'Invalid commit.' ) ).to.equal( true );
expect( stubs.logger.info.firstCall.args[ 0 ].includes( 'INVALID' ) ).to.equal( true );
} );
it( 'attaches additional subject for merge commits to the commit list', () => {
const commit = {
merge: 'Merge pull request #75 from ckeditor/t/64',
hash: 'dea3501',
header: 'Feature: Introduced a brand new release tools with a new set of requirements.',
type: 'Feature',
rawType: 'Feature',
subject: 'Introduced a brand new release tools with a new set of requirements.',
body: null,
footer: null,
mentions: [],
notes: []
};
displayCommits( [ commit ] );
expect( stubs.logger.info.calledOnce ).to.equal( true );
expect( stubs.logger.info.firstCall.args[ 0 ] ).to.be.a( 'string' );
const logMessageAsArray = stubs.logger.info.firstCall.args[ 0 ].split( '\n' );
expect( logMessageAsArray[ 0 ].includes(
'Feature: Introduced a brand new release tools with a new set of requirements.'
) ).to.equal( true );
expect( logMessageAsArray[ 0 ].includes( 'INCLUDED' ) ).to.equal( true );
expect( logMessageAsArray[ 1 ].includes( 'Merge pull request #75 from ckeditor/t/64' ) ).to.equal( true );
} );
it( 'displays proper log if commit does not contain the second line', () => {
const commit = {
type: null,
subject: null,
merge: 'Merge branch \'master\' of github.com:ckeditor/ckeditor5-dev',
header: 'Merge branch \'master\' of github.com:ckeditor/ckeditor5-dev',
body: null,
footer: null,
notes: [],
references: [],
mentions: [],
revert: null,
rawType: undefined,
files: [],
scope: undefined,
isPublicCommit: false,
hash: 'a'.repeat( 40 ),
repositoryUrl: 'https://github.com/ckeditor/ckeditor5-dev'
};
displayCommits( [ commit ] );
// The merge commit displays two lines:
// Prefix: Changes.
// Merge ...
// If the merge commit does not contain the second line, it should display only the one.
expect( stubs.logger.info.firstCall.args[ 0 ].split( '\n' ) ).length( 1 );
} );
it( 'attaches breaking changes notes to displayed message', () => {
const commit = {
hash: '684997d',
header: 'Feature: Simple foo.',
type: 'Feature',
rawType: 'Feature',
subject: 'Simple foo.',
body: null,
footer: null,
notes: [
{
title: 'MAJOR BREAKING CHANGES',
text: '1 - Reference site about Lorem Ipsum, giving information on its origins, as well as ' +
'a random Lipsum generator.'
},
{
title: 'MAJOR BREAKING CHANGES',
text: '2 - Reference site about Lorem Ipsum, giving information on its origins, as well as ' +
'a random Lipsum generator.'
},
{
title: 'MINOR BREAKING CHANGES',
text: '3 - Reference site about Lorem Ipsum, giving information on its origins, as well as ' +
'a random Lipsum generator.'
}
]
};
displayCommits( [ commit ] );
const message = stubs.logger.info.firstCall.args[ 0 ].split( '\n' );
/* eslint-disable max-len */
expect( message[ 0 ].includes( 'Feature: Simple foo.' ) ).to.equal( true );
expect( message[ 1 ].includes( 'MAJOR BREAKING CHANGES: 1 - Reference site about Lorem Ipsum, giving information on its origins, as...' ) ).to.equal( true );
expect( message[ 2 ].includes( 'MAJOR BREAKING CHANGES: 2 - Reference site about Lorem Ipsum, giving information on its origins, as...' ) ).to.equal( true );
expect( message[ 3 ].includes( 'MINOR BREAKING CHANGES: 3 - Reference site about Lorem Ipsum, giving information on its origins, as...' ) ).to.equal( true );
/* eslint-enable max-len */
} );
describe( 'options.attachLinkToCommit', () => {
it( 'adds a link to displayed commit', () => {
const commit = {
hash: '684997d',
header: 'Fix: Simple fix.',
type: 'Bug fixes',
subject: 'Simple fix.',
body: null,
footer: null,
notes: [],
rawType: 'Fix',
repositoryUrl: 'https://github.com/ckeditor/ckeditor5-foo'
};
displayCommits( [ commit ], { attachLinkToCommit: true } );
expect( stubs.logger.info.calledOnce ).to.equal( true );
const logMessage = stubs.logger.info.firstCall.args[ 0 ].split( '\n' );
expect( logMessage[ 0 ].includes( 'Fix: Simple fix.' ) ).to.equal( true );
expect( logMessage[ 0 ].includes( 'INCLUDED' ) ).to.equal( true );
expect( logMessage[ 1 ].includes( 'https://github.com/ckeditor/ckeditor5-foo/commit/684997d' ) ).to.equal( true );
} );
} );
describe( 'options.indentLevel', () => {
it( 'is equal to 1 by default', () => {
const commit = {
hash: '684997d',
header: 'Fix: Simple fix.',
type: 'Bug fixes',
subject: 'Simple fix.',
body: null,
footer: null,
notes: [],
rawType: 'Fix'
};
displayCommits( [ commit ] );
expect( stubs.logger.info.calledOnce ).to.equal( true );
const logMessage = stubs.logger.info.firstCall.args[ 0 ];
expect( logMessage.substring( 0, 3 ) ).to.equal( ' ' );
} );
it( 'indents second line properly', () => {
const commit = {
hash: '684997d',
merge: 'Merge pull request #75 from ckeditor/t/64',
header: 'Feature: Introduced a brand new release tools with a new set of requirements.',
type: 'Feature',
subject: 'Introduced a brand new release tools with a new set of requirements.',
body: null,
footer: null,
notes: [],
rawType: 'Fix'
};
displayCommits( [ commit ] );
expect( stubs.logger.info.calledOnce ).to.equal( true );
const [ firstLine, secondLine ] = stubs.logger.info.firstCall.args[ 0 ].split( '\n' );
expect( firstLine.substring( 0, 3 ) ).to.equal( ' '.repeat( 3 ) );
expect( secondLine.substring( 0, 13 ) ).to.equal( ' '.repeat( 13 ) );
} );
it( 'works with "options.attachLinkToCommit"', () => {
const commit = {
hash: '684997d',
merge: 'Merge pull request #75 from ckeditor/t/64',
header: 'Feature: Introduced a brand new release tools with a new set of requirements.',
type: 'Feature',
subject: 'Introduced a brand new release tools with a new set of requirements.',
body: null,
footer: null,
notes: [],
rawType: 'Fix',
repositoryUrl: 'https://github.com/ckeditor/ckeditor5-foo'
};
displayCommits( [ commit ], { attachLinkToCommit: true, indentLevel: 2 } );
expect( stubs.logger.info.calledOnce ).to.equal( true );
const [ firstLine, secondLine, thirdLine ] = stubs.logger.info.firstCall.args[ 0 ].split( '\n' );
expect( firstLine.substring( 0, 6 ) ).to.equal( ' '.repeat( 6 ) );
expect( secondLine.substring( 0, 16 ) ).to.equal( ' '.repeat( 16 ) );
expect( thirdLine.substring( 0, 16 ) ).to.equal( ' '.repeat( 16 ) );
} );
} );
} );
} );