fix(route/github): handle missing commits in PushEvent payload (#20262)

Co-authored-by: NekoAria <NekoAria@users.noreply.github.com>
This commit is contained in:
Neko Aria
2025-10-10 20:15:53 +08:00
committed by GitHub
co-authored by NekoAria
parent bd67b3c3d7
commit aeec1eda5d
+9 -3
View File
@@ -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 += `<br><strong>Latest commit:</strong> ${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 += `<br><strong>Latest commit:</strong> ${payload.commits.at(-1).message}`;
} else {
link = `https://github.com/${repo.name}/commit/${payload.head}`;
}
break;
}
case 'PullRequestEvent':