Skip to content

Commit 78f6452

Browse files
panvaaduh95
authored andcommitted
fix(ncu-ci): only filter main branch when it's the only one
Hide the target annotation only when main is the sole recorded target. Keep it visible alongside other targets after a PR is retargeted. Signed-off-by: Filip Skokan <panva.ip@gmail.com> Assisted-by: Codex
1 parent 7b0bc8e commit 78f6452

2 files changed

Lines changed: 16 additions & 12 deletions

File tree

‎lib/ci/failure_aggregator.js‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,14 @@ function formatTargetBranches(pr, markdown = false) {
2828
if (!parsePRFromURL(pr.source)) {
2929
return '';
3030
}
31-
const branches = pr.targetBranches
32-
.filter(branch => branch !== 'main')
33-
.map(branch => markdown
34-
? branch.replace(/[&<>"'\\`*_[\]{}()!|~]/g, char => `&#${char.charCodeAt(0)};`)
35-
: branch);
36-
return branches.length ? ` (target: ${branches.join(', ')})` : '';
31+
if (pr.targetBranches.length === 1 && pr.targetBranches[0] === 'main') {
32+
return '';
33+
}
34+
const branches = markdown
35+
? pr.targetBranches.map(branch =>
36+
branch.replace(/[&<>"'\\`*_[\]{}()!|~]/g, char => `&#${char.charCodeAt(0)};`))
37+
: pr.targetBranches;
38+
return ` (target: ${branches.join(', ')})`;
3739
}
3840

3941
export class FailureAggregator {

‎test/unit/ci_failure_aggregator.test.js‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ describe('Failure aggregation target branches', () => {
4646
const markdown = aggregator.formatAsMarkdown();
4747
assert.ok(markdown.includes('| Failed PR | 2 (' +
4848
`[nodejs/node#2](${failures[3].upstream}) (target: v22.x), ` +
49-
`[nodejs/node#1](${failures[0].upstream}) (target: v24.x)) |`));
49+
`[nodejs/node#1](${failures[0].upstream}) (target: main, v24.x)) |`));
5050
assert.ok(markdown.includes(`| First CI | ${failures[3].upstream} |`));
5151
assert.ok(markdown.includes(`| Last CI | ${failures[0].upstream} |`));
5252
assert.ok(markdown.includes('Health summary\n'));
@@ -55,7 +55,7 @@ describe('Failure aggregation target branches', () => {
5555

5656
aggregator.display();
5757
assert.deepEqual(cli._calls.table.filter(([key]) => key === 'Failed PR'), [
58-
['Failed PR', '2 (nodejs/node#2 (target: v22.x), nodejs/node#1 (target: v24.x))'],
58+
['Failed PR', '2 (nodejs/node#2 (target: v22.x), nodejs/node#1 (target: main, v24.x))'],
5959
['Failed PR', '1 (nodejs/node#3)']
6060
]);
6161
});
@@ -66,16 +66,18 @@ describe('Failure aggregation target branches', () => {
6666
failure(1, 104), failure(1, 103, 'main'), failure(1, 102), failure(2, 101)
6767
]);
6868
const markdown = aggregator.formatAsMarkdown();
69-
assert.equal(markdown.includes('target: unknown, main'), false);
69+
assert.ok(markdown.includes('(target: unknown, main)'));
7070
assert.ok(markdown.includes('(target: unknown)'));
7171
aggregator.display();
7272
assert.deepEqual(cli._calls.table.find(([key]) => key === 'Failed PR'),
73-
['Failed PR', '2 (nodejs/node#2 (target: unknown), nodejs/node#1 (target: unknown))']);
73+
['Failed PR', '2 (nodejs/node#2 (target: unknown), nodejs/node#1 (target: unknown, main))']);
7474
});
7575

76-
it('hides main targets and abbreviates PR labels without changing CI links', () => {
76+
it('hides sole main targets and abbreviates PR labels without changing CI links', () => {
7777
const cli = new TestCLI();
78-
const failures = [failure(1, 102, 'main'), failure(2, 101, 'main')];
78+
const failures = [
79+
failure(1, 102, 'main'), failure(2, 101, 'main'), failure(1, 100, 'main')
80+
];
7981
failures[1].source = 'https://github.com/nodejs-private/node-private/pull/2/';
8082
const aggregator = new FailureAggregator(cli, [health, ...failures]);
8183
const markdown = aggregator.formatAsMarkdown();

0 commit comments

Comments
 (0)