From 0a970a5eb015796a1717fe0c5f6e533ff62a59c4 Mon Sep 17 00:00:00 2001 From: inoway46 Date: Wed, 18 Nov 2026 17:16:49 +0900 Subject: [PATCH] feat(ncu-ci): link failed PRs to GitHub in reports The "Failed PR" row of the Markdown report labels each entry as a PR (owner/repo#number) but links to its node-test-pull-request run. Readers without access to ci.nodejs.org cannot open that link, so they have no direct way to get to the PR that failed. Link each label to the PR on GitHub and keep the CI run as a separate "CI" link next to it, together with the target branches. Sources that are not PRs keep linking to their CI run. Signed-off-by: inoway46 Assisted-by: Claude Code --- lib/ci/failure_aggregator.js | 35 ++++++++++++++++++++----- test/unit/ci_failure_aggregator.test.js | 20 ++++++++------ 2 files changed, 40 insertions(+), 15 deletions(-) diff --git a/lib/ci/failure_aggregator.js b/lib/ci/failure_aggregator.js index 7905b5a5..1453a9ee 100644 --- a/lib/ci/failure_aggregator.js +++ b/lib/ci/failure_aggregator.js @@ -24,10 +24,7 @@ function formatSource(source) { return parsed ? `${parsed.owner}/${parsed.repo}#${parsed.prid}` : source; } -function formatTargetBranches(pr, markdown = false) { - if (!parsePRFromURL(pr.source)) { - return ''; - } +function formatTargetList(pr, markdown = false) { if (pr.targetBranches.length === 1 && pr.targetBranches[0] === 'main') { return ''; } @@ -35,7 +32,32 @@ function formatTargetBranches(pr, markdown = false) { ? pr.targetBranches.map(branch => branch.replace(/[&<>"'\\`*_[\]{}()!|~]/g, char => `&#${char.charCodeAt(0)};`)) : pr.targetBranches; - return ` (target: ${branches.join(', ')})`; + return `target: ${branches.join(', ')}`; +} + +function formatTargetBranches(pr) { + if (!parsePRFromURL(pr.source)) { + return ''; + } + const targets = formatTargetList(pr); + return targets ? ` (${targets})` : ''; +} + +// Link PRs to GitHub, which everyone can view, and keep the CI run as a +// separate link since ci.nodejs.org requires signing in. +function formatMarkdownSource(pr) { + const parsed = parsePRFromURL(pr.source); + if (!parsed) { + return `[${pr.source}](${pr.upstream})`; + } + const { owner, repo, prid } = parsed; + const prUrl = `https://github.com/${owner}/${repo}/pull/${prid}`; + const notes = [`[CI](${pr.upstream})`]; + const targets = formatTargetList(pr, true); + if (targets) { + notes.push(targets); + } + return `[${owner}/${repo}#${prid}](${prUrl}) (${notes.join(', ')})`; } export class FailureAggregator { @@ -123,8 +145,7 @@ export class FailureAggregator { output += markdownRow('Reason', `${reason}`); output += markdownRow('-', ':-'); output += markdownRow('Type', type); - const source = prs.map(f => - `[${formatSource(f.source)}](${f.upstream})${formatTargetBranches(f, true)}`); + const source = prs.map(formatMarkdownSource); output += markdownRow( 'Failed PR', `${source.length} (${source.join(', ')})` ); diff --git a/test/unit/ci_failure_aggregator.test.js b/test/unit/ci_failure_aggregator.test.js index 1f07f699..6b7aedbc 100644 --- a/test/unit/ci_failure_aggregator.test.js +++ b/test/unit/ci_failure_aggregator.test.js @@ -57,8 +57,10 @@ describe('Failure aggregation target branches', () => { const markdown = aggregator.formatAsMarkdown(); assert.ok(markdown.includes('| Failed PR | 2 (' + - `[nodejs/node#2](${failures[3].upstream}) (target: v22.x), ` + - `[nodejs/node#1](${failures[0].upstream}) (target: main, v24.x)) |`)); + '[nodejs/node#2](https://github.com/nodejs/node/pull/2) ' + + `([CI](${failures[3].upstream}), target: v22.x), ` + + '[nodejs/node#1](https://github.com/nodejs/node/pull/1) ' + + `([CI](${failures[0].upstream}), target: main, v24.x)) |`)); assert.ok(markdown.includes(`| First CI | ${failures[3].upstream} |`)); assert.ok(markdown.includes(`| Last CI | ${failures[0].upstream} |`)); assert.ok(markdown.includes('Health summary\n')); @@ -78,14 +80,14 @@ describe('Failure aggregation target branches', () => { failure(1, 104), failure(1, 103, 'main'), failure(1, 102), failure(2, 101) ]); const markdown = aggregator.formatAsMarkdown(); - assert.ok(markdown.includes('(target: unknown, main)')); - assert.ok(markdown.includes('(target: unknown)')); + assert.ok(markdown.includes(', target: unknown, main)')); + assert.ok(markdown.includes(', target: unknown)')); aggregator.display(); assert.deepEqual(cli._calls.table.find(([key]) => key === 'Failed PR'), ['Failed PR', '2 (nodejs/node#2 (target: unknown), nodejs/node#1 (target: unknown, main))']); }); - it('hides sole main targets and abbreviates PR labels without changing CI links', () => { + it('hides sole main targets and links PRs alongside their CI runs', () => { const cli = new TestCLI(); const failures = [ failure(1, 102, 'main'), failure(2, 101, 'main'), failure(1, 100, 'main') @@ -94,8 +96,10 @@ describe('Failure aggregation target branches', () => { const aggregator = new FailureAggregator(cli, [health, ...failures]); const markdown = aggregator.formatAsMarkdown(); assert.ok(markdown.includes('| Failed PR | 2 (' + - `[nodejs-private/node-private#2](${failures[1].upstream}), ` + - `[nodejs/node#1](${failures[0].upstream})) |`)); + '[nodejs-private/node-private#2](https://github.com/nodejs-private/node-private/pull/2) ' + + `([CI](${failures[1].upstream})), ` + + '[nodejs/node#1](https://github.com/nodejs/node/pull/1) ' + + `([CI](${failures[0].upstream}))) |`)); assert.equal(markdown.includes('target:'), false); aggregator.display(); assert.deepEqual(cli._calls.table.find(([key]) => key === 'Failed PR'), @@ -110,7 +114,7 @@ describe('Failure aggregation target branches', () => { ]); const markdown = aggregator.formatAsMarkdown(); const escaped = 'feature/a|b`c&<d>_e_(f)'; - assert.ok(markdown.includes(`(target: ${escaped})`)); + assert.ok(markdown.includes(`, target: ${escaped})`)); assert.equal(markdown.includes(branch), false); aggregator.display(); assert.ok(cli._calls.table.find(([key]) => key === 'Failed PR')[1].includes(branch));