-
Notifications
You must be signed in to change notification settings - Fork 791
Expand file tree
/
Copy pathfolderRepositoryManager.test.ts
More file actions
512 lines (405 loc) · 25.6 KB
/
Copy pathfolderRepositoryManager.test.ts
File metadata and controls
512 lines (405 loc) · 25.6 KB
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
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { default as assert } from 'assert';
import { createSandbox, SinonSandbox } from 'sinon';
import { FolderRepositoryManager, ReposManagerState, titleAndBodyFrom } from '../../github/folderRepositoryManager';
import { MockRepository } from '../mocks/mockRepository';
import { MockTelemetry } from '../mocks/mockTelemetry';
import { MockCommandRegistry } from '../mocks/mockCommandRegistry';
import { PullRequestModel } from '../../github/pullRequestModel';
import { GitHubRemote, Remote } from '../../common/remote';
import { Protocol } from '../../common/protocol';
import { GitHubRepository } from '../../github/githubRepository';
import { PullRequestBuilder } from '../builders/rest/pullRequestBuilder';
import { convertRESTPullRequestToRawPullRequest } from '../../github/utils';
import { GitApiImpl } from '../../api/api1';
import { CredentialStore } from '../../github/credentials';
import { MockExtensionContext } from '../mocks/mockExtensionContext';
import { Uri } from 'vscode';
import { AuthProvider, GitHubServerType } from '../../common/authentication';
import { CreatePullRequestHelper } from '../../view/createPullRequestHelper';
import { RepositoriesManager } from '../../github/repositoriesManager';
import { MockThemeWatcher } from '../mocks/mockThemeWatcher';
import { PullRequestReviewCommon, ReviewContext } from '../../github/pullRequestReviewCommon';
import { IRequestMessage } from '../../common/webview';
import { PullRequestMergeability } from '../../github/interface';
import { PullRequest } from '../../github/views';
describe('PullRequestManager', function () {
let sinon: SinonSandbox;
let manager: FolderRepositoryManager;
let telemetry: MockTelemetry;
let mockThemeWatcher: MockThemeWatcher;
let repository: MockRepository;
beforeEach(function () {
sinon = createSandbox();
MockCommandRegistry.install(sinon);
telemetry = new MockTelemetry();
mockThemeWatcher = new MockThemeWatcher();
repository = new MockRepository();
const context = new MockExtensionContext();
const credentialStore = new CredentialStore(telemetry, context);
const repositoriesManager = new RepositoriesManager(credentialStore, telemetry);
manager = new FolderRepositoryManager(0, context, repository, telemetry, new GitApiImpl(repositoriesManager), credentialStore, new CreatePullRequestHelper(), mockThemeWatcher);
});
afterEach(function () {
sinon.restore();
});
describe('updateRepositories', function () {
it('requires authentication for an unknown remote with an existing GitHub.com session', async function () {
const url = 'ssh://git@ghe.example.com/org/repo.git';
const remote = new Remote('origin', url, new Protocol(url));
sinon.stub(manager, 'computeAllGitHubRemotes').resolves([]);
sinon.stub(manager, 'computeAllUnknownRemotes').resolves([remote]);
sinon.stub(manager.credentialStore, 'isAuthenticated').callsFake(provider => provider === AuthProvider.github);
await manager.updateRepositories();
assert.strictEqual(manager.state, ReposManagerState.NeedsAuthentication);
});
});
describe('activePullRequest', function () {
it('gets and sets the active pull request', function () {
assert.strictEqual(manager.activePullRequest, undefined);
const changeFired = sinon.spy();
manager.onDidChangeActivePullRequest(changeFired);
const url = 'https://github.com/aaa/bbb.git';
const protocol = new Protocol(url);
const remote = new GitHubRemote('origin', url, protocol, GitHubServerType.GitHubDotCom);
const rootUri = Uri.file('C:\\users\\test\\repo');
const repository = new GitHubRepository(1, remote, rootUri, manager.credentialStore, telemetry);
const prItem = convertRESTPullRequestToRawPullRequest(new PullRequestBuilder().build(), repository);
const pr = new PullRequestModel(manager.credentialStore, telemetry, repository, remote, prItem);
manager.activePullRequest = pr;
assert(changeFired.called);
assert.deepStrictEqual(manager.activePullRequest, pr);
});
});
describe('tryMergeBaseIntoHead', function () {
it('updates a conflict-free pull request that is not checked out using GraphQL', async function () {
const url = 'https://github.com/aaa/bbb.git';
const remote = new GitHubRemote('origin', url, new Protocol(url), GitHubServerType.GitHubDotCom);
const repository = new GitHubRepository(1, remote, Uri.file('C:\\users\\test\\repo'), manager.credentialStore, telemetry);
const prItem = convertRESTPullRequestToRawPullRequest(new PullRequestBuilder().build(), repository);
const pr = new PullRequestModel(manager.credentialStore, telemetry, repository, remote, prItem);
sinon.stub(manager, 'isHeadUpToDateWithBase').resolves(false);
const updateBranchWithGraphQL = sinon.stub(pr, 'updateBranchWithGraphQL').resolves(true);
const updateBranch = sinon.stub(pr, 'updateBranch').resolves(true);
const result = await manager.tryMergeBaseIntoHead(pr, true);
assert.strictEqual(result, true);
assert.strictEqual(updateBranchWithGraphQL.calledOnce, true);
assert.strictEqual(updateBranch.notCalled, true);
});
});
describe('updateBranch', function () {
it('reports that the branch is up to date after a successful update', async function () {
const url = 'https://github.com/aaa/bbb.git';
const remote = new GitHubRemote('origin', url, new Protocol(url), GitHubServerType.GitHubDotCom);
const repository = new GitHubRepository(1, remote, Uri.file('C:\\users\\test\\repo'), manager.credentialStore, telemetry);
const prItem = convertRESTPullRequestToRawPullRequest(new PullRequestBuilder().build(), repository);
const pr = new PullRequestModel(manager.credentialStore, telemetry, repository, remote, prItem);
sinon.stub(manager, 'tryMergeBaseIntoHead').resolves(true);
sinon.stub(pr, 'getMergeability').resolves({ mergeability: PullRequestMergeability.Mergeable });
let reply: Partial<PullRequest> | undefined;
const context: ReviewContext = {
item: pr,
folderRepositoryManager: manager,
existingReviewers: [],
postMessage: sinon.stub().resolves(),
replyMessage: (_message, response) => reply = response,
throwError: sinon.stub(),
getTimeline: sinon.stub().resolves([]),
};
const message: IRequestMessage<string> = { req: '1', command: 'pr.update-branch', args: '' };
await PullRequestReviewCommon.updateBranch(context, message, sinon.stub().resolves());
assert.strictEqual(reply?.canUpdateBranch, false);
assert.strictEqual(reply?.mergeable, PullRequestMergeability.Mergeable);
});
});
describe('deleteBranches', function () {
const noopProgress = { report: () => { } };
it('removes leftover branch config after deleting a branch', async function () {
await repository.createBranch('feature', false, 'commit-hash');
await repository.setConfig('branch.feature.github-pr-base-branch', 'owner#repo#main');
await repository.setConfig('branch.feature.vscode-merge-base', 'origin/main');
await repository.setConfig('branch.feature.remote', 'origin');
await repository.setConfig('branch.feature.merge', 'refs/heads/feature');
await repository.setConfig('branch.feature.github-pr-owner-number', 'owner#repo#1');
await repository.setConfig('branch.feature.github-pr-owner-number', 'owner#repo#1');
await repository.setConfig('branch.feature.github-pr-owner-number', 'owner#repo#1');
await repository.setConfig('branch.feature.github-pr-owner-number', 'owner#repo#1');
repository.preserveConfigOnNextBranchDelete = true;
const nonExistant = new Set<string>();
await (manager as any).deleteBranches([{ label: 'feature' }], nonExistant, noopProgress, 1, 0, []);
const configs = await repository.getConfigs();
assert.strictEqual(configs.filter(c => c.key.startsWith('branch.feature.')).length, 0);
assert.strictEqual(nonExistant.has('feature'), false);
});
it('removes leftover branch config for a branch that no longer exists', async function () {
// The branch ref is already gone, but stale [branch "gone"] config remains.
await repository.setConfig('branch.gone.remote', 'origin');
await repository.setConfig('branch.gone.merge', 'refs/heads/gone');
await repository.setConfig('branch.gone.github-pr-owner-number', 'owner#repo#2');
await repository.setConfig('branch.gone.github-pr-owner-number', 'owner#repo#2');
await repository.setConfig('branch.gone.github-pr-owner-number', 'owner#repo#2');
await repository.setConfig('branch.gone.github-pr-owner-number', 'owner#repo#2');
const nonExistant = new Set<string>();
await (manager as any).deleteBranches([{ label: 'gone' }], nonExistant, noopProgress, 1, 0, []);
const configs = await repository.getConfigs();
assert.strictEqual(configs.filter(c => c.key.startsWith('branch.gone.')).length, 0);
assert.strictEqual(nonExistant.has('gone'), true);
});
});
describe('deleteRemotes', function () {
it('continues deleting remotes after one fails', async function () {
await repository.addRemote('locked', 'https://github.com/owner/locked');
await repository.addRemote('deletable', 'https://github.com/owner/deletable');
const removeRemote = repository.removeRemote.bind(repository);
sinon.stub(repository, 'removeRemote').callsFake(async name => {
if (name === 'locked') {
throw new Error('Repository is locked');
}
await removeRemote(name);
});
const failures = await (manager as any).deleteRemotes([{ label: 'locked' }, { label: 'deletable' }]);
assert.strictEqual(failures.length, 1);
assert.strictEqual(failures[0].label, 'locked');
assert.deepStrictEqual(repository.state.remotes.map(remote => remote.name), ['locked']);
});
});
});
describe('titleAndBodyFrom', function () {
it('separates title and body', async function () {
const message = Promise.resolve('title\n\ndescription 1\n\ndescription 2\n');
const result = await titleAndBodyFrom(message);
assert.strictEqual(result?.title, 'title');
assert.strictEqual(result?.body, 'description 1\n\ndescription 2');
});
it('returns only title with no body', async function () {
const message = Promise.resolve('title');
const result = await titleAndBodyFrom(message);
assert.strictEqual(result?.title, 'title');
assert.strictEqual(result?.body, '');
});
it('returns only title when body contains only whitespace', async function () {
const message = Promise.resolve('title\n\n');
const result = await titleAndBodyFrom(message);
assert.strictEqual(result?.title, 'title');
assert.strictEqual(result?.body, '');
});
it('unwraps wrapped lines in body', async function () {
const message = Promise.resolve('title\n\nThis is a long line that has been wrapped at 72 characters\nto fit the conventional commit message format.');
const result = await titleAndBodyFrom(message);
assert.strictEqual(result?.title, 'title');
assert.strictEqual(result?.body, 'This is a long line that has been wrapped at 72 characters to fit the conventional commit message format.');
});
it('preserves blank lines as paragraph breaks', async function () {
const message = Promise.resolve('title\n\nFirst paragraph that is wrapped\nacross multiple lines.\n\nSecond paragraph that is also wrapped\nacross multiple lines.');
const result = await titleAndBodyFrom(message);
assert.strictEqual(result?.title, 'title');
assert.strictEqual(result?.body, 'First paragraph that is wrapped across multiple lines.\n\nSecond paragraph that is also wrapped across multiple lines.');
});
it('preserves list items', async function () {
const message = Promise.resolve('title\n\n- First item\n- Second item\n- Third item');
const result = await titleAndBodyFrom(message);
assert.strictEqual(result?.title, 'title');
assert.strictEqual(result?.body, '- First item\n- Second item\n- Third item');
});
it('preserves numbered list items', async function () {
const message = Promise.resolve('title\n\n1. First item\n2. Second item\n3. Third item');
const result = await titleAndBodyFrom(message);
assert.strictEqual(result?.title, 'title');
assert.strictEqual(result?.body, '1. First item\n2. Second item\n3. Third item');
});
it('preserves indented lines', async function () {
const message = Promise.resolve('title\n\nNormal paragraph.\n\n Indented code block\n More code');
const result = await titleAndBodyFrom(message);
assert.strictEqual(result?.title, 'title');
assert.strictEqual(result?.body, 'Normal paragraph.\n\n Indented code block\n More code');
});
it('unwraps but preserves asterisk list items', async function () {
const message = Promise.resolve('title\n\n* First item\n* Second item');
const result = await titleAndBodyFrom(message);
assert.strictEqual(result?.title, 'title');
assert.strictEqual(result?.body, '* First item\n* Second item');
});
it('handles mixed content with wrapped paragraphs and lists', async function () {
const message = Promise.resolve('title\n\nThis is a paragraph that has been wrapped\nat 72 characters.\n\n- Item 1\n- Item 2\n\nAnother wrapped paragraph\nthat continues here.');
const result = await titleAndBodyFrom(message);
assert.strictEqual(result?.title, 'title');
assert.strictEqual(result?.body, 'This is a paragraph that has been wrapped at 72 characters.\n\n- Item 1\n- Item 2\n\nAnother wrapped paragraph that continues here.');
});
it('preserves lines with special characters at the start', async function () {
const message = Promise.resolve('title\n\n> Quote line 1\n> Quote line 2');
const result = await titleAndBodyFrom(message);
assert.strictEqual(result?.title, 'title');
assert.strictEqual(result?.body, '> Quote line 1\n> Quote line 2');
});
it('handles wrapped lines with punctuation', async function () {
const message = Promise.resolve('title\n\nThis is a sentence.\nThis is another sentence on a new line.');
const result = await titleAndBodyFrom(message);
assert.strictEqual(result?.title, 'title');
assert.strictEqual(result?.body, 'This is a sentence. This is another sentence on a new line.');
});
it('preserves fenced code blocks', async function () {
const message = Promise.resolve('title\n\nSome text before.\n\n```\ncode line 1\ncode line 2\n```\n\nSome text after.');
const result = await titleAndBodyFrom(message);
assert.strictEqual(result?.title, 'title');
assert.strictEqual(result?.body, 'Some text before.\n\n```\ncode line 1\ncode line 2\n```\n\nSome text after.');
});
it('preserves fenced code blocks with language', async function () {
const message = Promise.resolve('title\n\nSome text.\n\n```javascript\nconst x = 1;\nconst y = 2;\n```\n\nMore text.');
const result = await titleAndBodyFrom(message);
assert.strictEqual(result?.title, 'title');
assert.strictEqual(result?.body, 'Some text.\n\n```javascript\nconst x = 1;\nconst y = 2;\n```\n\nMore text.');
});
it('preserves nested list items with proper indentation', async function () {
const message = Promise.resolve('title\n\n- Item 1\n - Nested item 1.1\n - Nested item 1.2\n- Item 2');
const result = await titleAndBodyFrom(message);
assert.strictEqual(result?.title, 'title');
assert.strictEqual(result?.body, '- Item 1\n - Nested item 1.1\n - Nested item 1.2\n- Item 2');
});
it('unwraps list item continuations', async function () {
const message = Promise.resolve('title\n\n- This is a list item that is long\n and continues on the next line\n- Second item');
const result = await titleAndBodyFrom(message);
assert.strictEqual(result?.title, 'title');
assert.strictEqual(result?.body, '- This is a list item that is long and continues on the next line\n- Second item');
});
it('preserves indented code blocks but not list continuations', async function () {
const message = Promise.resolve('title\n\nRegular paragraph.\n\n This is code\n More code\n\nAnother paragraph.');
const result = await titleAndBodyFrom(message);
assert.strictEqual(result?.title, 'title');
assert.strictEqual(result?.body, 'Regular paragraph.\n\n This is code\n More code\n\nAnother paragraph.');
});
it('unwraps regular text and list item continuations', async function () {
const message = Promise.resolve('title\n\nThis is wrapped text\nthat should be joined.\n\n- List item with\n continuation\n- Another item');
const result = await titleAndBodyFrom(message);
assert.strictEqual(result?.title, 'title');
assert.strictEqual(result?.body, 'This is wrapped text that should be joined.\n\n- List item with continuation\n- Another item');
});
it('handles complex nested lists with wrapped paragraphs', async function () {
const message = Promise.resolve('title\n\nWrapped paragraph\nacross lines.\n\n- Item 1\n - Nested item\n More nested content\n- Item 2\n\nAnother wrapped paragraph\nhere.');
const result = await titleAndBodyFrom(message);
assert.strictEqual(result?.title, 'title');
assert.strictEqual(result?.body, 'Wrapped paragraph across lines.\n\n- Item 1\n - Nested item More nested content\n- Item 2\n\nAnother wrapped paragraph here.');
});
it('handles nested lists', async function () {
const message = Promise.resolve('title\n\n* This is a list item with two lines\n that have a line break between them\n * This is a nested list item that also has\n two lines that should have been merged');
const result = await titleAndBodyFrom(message);
assert.strictEqual(result?.title, 'title');
assert.strictEqual(result?.body, '* This is a list item with two lines that have a line break between them\n * This is a nested list item that also has two lines that should have been merged');
});
it('handles basic numeric list continuation', async function () {
const message = Promise.resolve('title\n\n1. Basic numeric list\n continuation.\n Third line');
const result = await titleAndBodyFrom(message);
assert.strictEqual(result?.title, 'title');
assert.strictEqual(result?.body, '1. Basic numeric list continuation. Third line');
});
it('handles additional spaces OK for continuation', async function () {
const message = Promise.resolve('title\n\n2. Additional spaces are\n OK for a continuation (unless it\'s 4 spaces which would be a code block).\n Third line');
const result = await titleAndBodyFrom(message);
assert.strictEqual(result?.title, 'title');
assert.strictEqual(result?.body, '2. Additional spaces are OK for a continuation (unless it\'s 4 spaces which would be a code block). Third line');
});
it('handles asterisk list with extra spaces', async function () {
const message = Promise.resolve('title\n\n* Additional spaces are\n OK for a continuation (unless it\'s 4 spaces which would be a code block).\n Third line');
const result = await titleAndBodyFrom(message);
assert.strictEqual(result?.title, 'title');
assert.strictEqual(result?.body, '* Additional spaces are OK for a continuation (unless it\'s 4 spaces which would be a code block). Third line');
});
it('handles multi-digit numbers (10.)', async function () {
const message = Promise.resolve('title\n\n10. Multi-digit numbers should also\n work for a continuation.\n Third line');
const result = await titleAndBodyFrom(message);
assert.strictEqual(result?.title, 'title');
assert.strictEqual(result?.body, '10. Multi-digit numbers should also work for a continuation. Third line');
});
it('handles multi-paragraph list - numbered', async function () {
const message = Promise.resolve('title\n\n11. Multi-paragraph lists are also supported.\n\n Second paragraph in the same list item.\n Third line');
const result = await titleAndBodyFrom(message);
assert.strictEqual(result?.title, 'title');
assert.strictEqual(result?.body, '11. Multi-paragraph lists are also supported.\n\n Second paragraph in the same list item. Third line');
});
it('handles multi-paragraph list - asterisk', async function () {
const message = Promise.resolve('title\n\n* Multi-paragraph lists are also supported.\n\n Second paragraph in the same list item.\n Third line');
const result = await titleAndBodyFrom(message);
assert.strictEqual(result?.title, 'title');
assert.strictEqual(result?.body, '* Multi-paragraph lists are also supported.\n\n Second paragraph in the same list item. Third line');
});
it('handles item with code block - numbered', async function () {
const message = Promise.resolve('title\n\n1. Item with code:\n\n ```\n code line\n code line\n ```');
const result = await titleAndBodyFrom(message);
assert.strictEqual(result?.title, 'title');
assert.strictEqual(result?.body, '1. Item with code:\n\n ```\n code line\n code line\n ```');
});
it('handles item with code block - asterisk', async function () {
const message = Promise.resolve('title\n\n* Item with code:\n\n ```\n code line\n code line\n ```');
const result = await titleAndBodyFrom(message);
assert.strictEqual(result?.title, 'title');
assert.strictEqual(result?.body, '* Item with code:\n\n ```\n code line\n code line\n ```');
});
it('handles fewer spaces OK - numbered (1 space)', async function () {
const message = Promise.resolve('title\n\n1. Fewer spaces are also OK\n for a list continuation (as long as there\'s at least one space)');
const result = await titleAndBodyFrom(message);
assert.strictEqual(result?.title, 'title');
assert.strictEqual(result?.body, '1. Fewer spaces are also OK for a list continuation (as long as there\'s at least one space)');
});
it('handles fewer spaces OK - asterisk (1 space)', async function () {
const message = Promise.resolve('title\n\n* Fewer spaces are also OK\n for a list continuation (as long as there\'s at least one space)');
const result = await titleAndBodyFrom(message);
assert.strictEqual(result?.title, 'title');
assert.strictEqual(result?.body, '* Fewer spaces are also OK for a list continuation (as long as there\'s at least one space)');
});
it('handles nested numbered lists', async function () {
const message = Promise.resolve('title\n\n1. First level item\n continuation of first level\n 1. Nested numbered item\n with continuation');
const result = await titleAndBodyFrom(message);
assert.strictEqual(result?.title, 'title');
assert.strictEqual(result?.body, '1. First level item continuation of first level\n 1. Nested numbered item with continuation');
});
it('handles nested multi-digit numbered lists', async function () {
const message = Promise.resolve('title\n\n10. First level item with\n multi-line content\n 10. Nested with multi-digit\n number and continuation');
const result = await titleAndBodyFrom(message);
assert.strictEqual(result?.title, 'title');
assert.strictEqual(result?.body, '10. First level item with multi-line content\n 10. Nested with multi-digit number and continuation');
});
it('handles nested multi-paragraph lists', async function () {
const message = Promise.resolve('title\n\n* Outer item\n\n Second paragraph of outer\n with continuation\n * Inner item\n\n Second paragraph of inner\n with continuation');
const result = await titleAndBodyFrom(message);
assert.strictEqual(result?.title, 'title');
assert.strictEqual(result?.body, '* Outer item\n\n Second paragraph of outer with continuation\n * Inner item\n\n Second paragraph of inner with continuation');
});
it('handles first list item needs to be unwrapped', async function () {
const message = Promise.resolve('This is a test\n\n- A fslilenfilnf flen felslnf lsefl fnels Leknef\nLkdfnle lfkenSlefn Lnkef LefnLienf LIfnels\n- B\n- C');
const result = await titleAndBodyFrom(message);
assert.strictEqual(result?.title, 'This is a test');
assert.strictEqual(result?.body, '- A fslilenfilnf flen felslnf lsefl fnels Leknef Lkdfnle lfkenSlefn Lnkef LefnLienf LIfnels\n- B\n- C');
});
it('strips Co-authored-by trailer lines from body', async function () {
const message = Promise.resolve('title\n\nSome description.\n\nCo-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>');
const result = await titleAndBodyFrom(message);
assert.strictEqual(result?.title, 'title');
assert.strictEqual(result?.body, 'Some description.');
});
it('strips multiple Co-authored-by trailer lines', async function () {
const message = Promise.resolve('title\n\nSome description.\n\nCo-authored-by: Alice <alice@example.com>\nCo-authored-by: Bob <bob@example.com>');
const result = await titleAndBodyFrom(message);
assert.strictEqual(result?.title, 'title');
assert.strictEqual(result?.body, 'Some description.');
});
it('strips Co-authored-by case-insensitively', async function () {
const message = Promise.resolve('title\n\nSome description.\n\nco-authored-by: Alice <alice@example.com>');
const result = await titleAndBodyFrom(message);
assert.strictEqual(result?.title, 'title');
assert.strictEqual(result?.body, 'Some description.');
});
it('preserves other trailers when stripping Co-authored-by', async function () {
const message = Promise.resolve('title\n\nSome description.\n\nSigned-off-by: Alice <alice@example.com>\nCo-authored-by: Bob <bob@example.com>');
const result = await titleAndBodyFrom(message);
assert.strictEqual(result?.title, 'title');
assert.strictEqual(result?.body, 'Some description.\n\nSigned-off-by: Alice <alice@example.com>');
});
it('returns empty body when only Co-authored-by trailers are present', async function () {
const message = Promise.resolve('title\n\nCo-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>');
const result = await titleAndBodyFrom(message);
assert.strictEqual(result?.title, 'title');
assert.strictEqual(result?.body, '');
});
});