Skip to content

Commit f4bd00a

Browse files
committed
feat: hide default-branch target and shorten URLs
1 parent a7e84b3 commit f4bd00a

2 files changed

Lines changed: 35 additions & 16 deletions

File tree

‎lib/ci/failure_aggregator.js‎

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,21 @@ function uniqBy(array, key) {
1919
return array.filter((item) => !seen.has(item[key]) && seen.add(item[key]));
2020
}
2121

22+
function formatSource(source) {
23+
const parsed = parsePRFromURL(source);
24+
return parsed ? `${parsed.owner}/${parsed.repo}#${parsed.prid}` : source;
25+
}
26+
2227
function formatTargetBranches(pr, markdown = false) {
2328
if (!parsePRFromURL(pr.source)) {
2429
return '';
2530
}
26-
const branches = pr.targetBranches.map(branch => markdown
27-
? branch.replace(/[&<>"'\\`*_[\]{}()!|~]/g, char => `&#${char.charCodeAt(0)};`)
28-
: branch);
29-
return ` (target: ${branches.join(', ')})`;
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(', ')})` : '';
3037
}
3138

3239
export class FailureAggregator {
@@ -111,7 +118,8 @@ export class FailureAggregator {
111118
output += markdownRow('Reason', `<code>${reason}</code>`);
112119
output += markdownRow('-', ':-');
113120
output += markdownRow('Type', type);
114-
const source = prs.map(f => `[${f.source}](${f.upstream})${formatTargetBranches(f, true)}`);
121+
const source = prs.map(f =>
122+
`[${formatSource(f.source)}](${f.upstream})${formatTargetBranches(f, true)}`);
115123
output += markdownRow(
116124
'Failed PR', `${source.length} (${source.join(', ')})`
117125
);
@@ -151,11 +159,7 @@ export class FailureAggregator {
151159
const { reason, type, prs, failures, machines } = item;
152160
cli.table('Reason', reason);
153161
cli.table('Type', type);
154-
const source = prs
155-
.map(f => {
156-
const parsed = parsePRFromURL(f.source);
157-
return parsed ? `#${parsed.prid}${formatTargetBranches(f)}` : f.source;
158-
});
162+
const source = prs.map(f => `${formatSource(f.source)}${formatTargetBranches(f)}`);
159163
cli.table('Failed PR', `${source.length} (${source.join(', ')})`);
160164
cli.table('Appeared', machines.map(m => m.hostname).join(', '));
161165
if (prs.length > 1) {

‎test/unit/ci_failure_aggregator.test.js‎

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ describe('Failure aggregation target branches', () => {
4545

4646
const markdown = aggregator.formatAsMarkdown();
4747
assert.ok(markdown.includes('| Failed PR | 2 (' +
48-
`[${failures[3].source}](${failures[3].upstream}) (target: v22.x), ` +
49-
`[${failures[0].source}](${failures[0].upstream}) (target: main, v24.x)) |`));
48+
`[nodejs/node#2](${failures[3].upstream}) (target: v22.x), ` +
49+
`[nodejs/node#1](${failures[0].upstream}) (target: 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,8 +55,8 @@ describe('Failure aggregation target branches', () => {
5555

5656
aggregator.display();
5757
assert.deepEqual(cli._calls.table.filter(([key]) => key === 'Failed PR'), [
58-
['Failed PR', '2 (#2 (target: v22.x), #1 (target: main, v24.x))'],
59-
['Failed PR', '1 (#3 (target: main))']
58+
['Failed PR', '2 (nodejs/node#2 (target: v22.x), nodejs/node#1 (target: v24.x))'],
59+
['Failed PR', '1 (nodejs/node#3)']
6060
]);
6161
});
6262

@@ -66,11 +66,26 @@ 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.ok(markdown.includes('(target: unknown, main)'));
69+
assert.equal(markdown.includes('target: unknown, main'), false);
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 (#2 (target: unknown), #1 (target: unknown, main))']);
73+
['Failed PR', '2 (nodejs/node#2 (target: unknown), nodejs/node#1 (target: unknown))']);
74+
});
75+
76+
it('hides main targets and abbreviates PR labels without changing CI links', () => {
77+
const cli = new TestCLI();
78+
const failures = [failure(1, 102, 'main'), failure(2, 101, 'main')];
79+
failures[1].source = 'https://github.com/nodejs-private/node-private/pull/2/';
80+
const aggregator = new FailureAggregator(cli, [health, ...failures]);
81+
const markdown = aggregator.formatAsMarkdown();
82+
assert.ok(markdown.includes('| Failed PR | 2 (' +
83+
`[nodejs-private/node-private#2](${failures[1].upstream}), ` +
84+
`[nodejs/node#1](${failures[0].upstream})) |`));
85+
assert.equal(markdown.includes('target:'), false);
86+
aggregator.display();
87+
assert.deepEqual(cli._calls.table.find(([key]) => key === 'Failed PR'),
88+
['Failed PR', '2 (nodejs-private/node-private#2, nodejs/node#1)']);
7489
});
7590

7691
it('escapes Markdown and HTML in branch names while preserving terminal text', () => {

0 commit comments

Comments
 (0)