From 49a58764fa93afec50f63450bcab5584dac5debf Mon Sep 17 00:00:00 2001 From: mslxl Date: Tue, 28 Oct 2025 20:14:44 +0800 Subject: [PATCH] fix(route/github): Fix URL link error in events (#20386) * fix(route/github): Fix url of PR event not links to HTML page * fix(route/github): Fix repo info be replaced in push event * style: auto format --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- lib/routes/github/eventapi.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/routes/github/eventapi.ts b/lib/routes/github/eventapi.ts index 3b8e7ecd0e..20a0dec6a5 100644 --- a/lib/routes/github/eventapi.ts +++ b/lib/routes/github/eventapi.ts @@ -34,7 +34,7 @@ function formatEventItem(event: any) { description = `Pushed ${commitCount}to ${branch} in ${repo.name}`; if (payload.commits) { - link = payload.commits.at(-1).url.replace('api.github.com/repos/', 'github.com/').replace('/commits/', '/commit/'); + link = payload.commits.at(-1).url.replace(/https:\/\/api\.github\.com\/repos\/([^/]+)\/([^/]+)\/commits\/(\d+)/, 'https://github.com/$1/$2/commit/$3'); description += `
Latest commit: ${payload.commits.at(-1).message}`; } else { link = `https://github.com/${repo.name}/commit/${payload.head}`; @@ -43,8 +43,13 @@ function formatEventItem(event: any) { } case 'PullRequestEvent': title = `${actor.login} ${payload.action} a pull request in ${repo.name}`; - description = `PR: ${payload.pull_request?.url || 'Unknown'}`; - link = payload.pull_request?.url || `https://github.com/${repo.name}`; + if (payload.pull_request) { + link = payload.pull_request.url.replace(/https:\/\/api\.github\.com\/repos\/([^/]+)\/([^/]+)\/pulls\/(\d+)/, 'https://github.com/$1/$2/pull/$3'); + description = `PR: ${link}`; + } else { + link = `https://github.com/${repo.name}`; + description = `PR: Unknown`; + } break; case 'PullRequestReviewCommentEvent': title = `${actor.login} commented on a pull request review in ${repo.name}`;