From aeec1eda5dfb5f37da4f955f519c0866033cfad8 Mon Sep 17 00:00:00 2001 From: Neko Aria <23137034+NekoAria@users.noreply.github.com> Date: Fri, 10 Oct 2025 20:15:53 +0800 Subject: [PATCH] fix(route/github): handle missing commits in PushEvent payload (#20262) Co-authored-by: NekoAria --- lib/routes/github/private-feed.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/routes/github/private-feed.ts b/lib/routes/github/private-feed.ts index e0427e9e2..fcb4d3fbf 100644 --- a/lib/routes/github/private-feed.ts +++ b/lib/routes/github/private-feed.ts @@ -114,9 +114,15 @@ function formatEventItem(event: any) { case 'PushEvent': { title = `${actor.login} pushed to ${repo.name}`; const branch = payload.ref ? payload.ref.replace('refs/heads/', '') : 'unknown'; - description = `Pushed ${payload.size || 0} commit(s) to ${branch} in ${repo.name}`; - link = payload.commits.at(-1).url.replace('api.github.com/repos/', 'github.com/').replace('/commits/', '/commit/'); - description += `
Latest commit: ${payload.commits.at(-1).message}`; + const commitCount = payload.size ? `${payload.size} commit(s) ` : ''; + 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/'); + description += `
Latest commit: ${payload.commits.at(-1).message}`; + } else { + link = `https://github.com/${repo.name}/commit/${payload.head}`; + } break; } case 'PullRequestEvent':