diff --git a/docs/guide/message-format.md b/docs/guide/message-format.md index 9cf60e6..18f7b86 100644 --- a/docs/guide/message-format.md +++ b/docs/guide/message-format.md @@ -23,7 +23,7 @@ Messages whose title has no colon separator (a `:` followed by a space) keep the Commit hashes, branches, and tags render as inline code wrapped in a hyperlink (e.g. ``[`abc123d`](https://…/commit/abc123def456)``), falling back to plain inline code when the repo base URL is unavailable. -For push events, when a commit author's GitHub username differs from the pusher, the commit line ends with a link to that author (e.g. `- [octocat](https://github.com/octocat)`). +For push events, when a commit author's GitHub username differs from the pusher, the commit line ends with a link to that author (e.g. `- [octocat](https://github.com/octocat)`). When GitHub cannot resolve a bot account and returns `invalid-email-address`, the commit's author name is shown without a link. ## Emoji diff --git a/docs/zh/guide/message-format.md b/docs/zh/guide/message-format.md index 7dda9a8..371f72f 100644 --- a/docs/zh/guide/message-format.md +++ b/docs/zh/guide/message-format.md @@ -23,7 +23,7 @@ 提交哈希、分支与标签渲染为带超链接的行内代码(如 ``[`abc123d`](https://…/commit/abc123def456)``),仓库基地址不可用时回退为纯行内代码。 -对于 push 事件,若提交作者的 GitHub 用户名与推送者不同,提交行末尾会附上作者链接(如 `- [octocat](https://github.com/octocat)`)。 +对于 push 事件,若提交作者的 GitHub 用户名与推送者不同,提交行末尾会附上作者链接(如 `- [octocat](https://github.com/octocat)`)。GitHub 无法解析机器人账户并返回 `invalid-email-address` 时,会显示提交中的作者名称而不添加链接。 ## 表情 diff --git a/server/lib/formatters/push.ts b/server/lib/formatters/push.ts index 8e753f3..1e6837a 100644 --- a/server/lib/formatters/push.ts +++ b/server/lib/formatters/push.ts @@ -97,8 +97,13 @@ export function formatPush( let msg = (c.message?.split("\n")[0] ?? "").slice(0, MAX_COMMIT_SUBJECT) || t("common.no_message"); const commitAuthor = c.author?.username; + const commitAuthorName = c.author?.name; if (commitAuthor && commitAuthor.toLowerCase() !== pusher?.toLowerCase()) { - msg += ` - [${commitAuthor}](https://github.com/${encodeURIComponent(commitAuthor)})`; + if (commitAuthor === "invalid-email-address") { + if (commitAuthorName) msg += ` - ${commitAuthorName}`; + } else { + msg += ` - [${commitAuthor}](https://github.com/${encodeURIComponent(commitAuthor)})`; + } } const url = baseUrl && c.id ? `${baseUrl}/commit/${c.id}` : null; const hash = url ? `[\`${shortId}\`](${url})` : `\`${shortId}\``; diff --git a/tests/formatter.test.ts b/tests/formatter.test.ts index d897df0..b5e9e65 100644 --- a/tests/formatter.test.ts +++ b/tests/formatter.test.ts @@ -99,6 +99,32 @@ describe("message title spec", () => { ); }); + it("uses the author name when GitHub cannot resolve a bot username", () => { + const msg = formatEvent( + route, + event("push", { + ref: "refs/heads/main", + commits: [ + { + id: "abcd1234ef", + message: "fix stuff", + author: { name: "dependabot[bot]", username: "invalid-email-address" }, + added: [], + removed: [], + modified: [], + }, + ], + pusher: { name: "merge-bot" }, + repository: repo, + sender, + }), + ); + + expect(msg.description).toBe( + "[`abcd123`](https://github.com/acme/widget/commit/abcd1234ef) fix stuff - dependabot[bot]", + ); + }); + it("pull_request title is repo#number: title", () => { const msg = formatEvent( route,