mirror of
https://github.com/Elysola/WebHooker.git
synced 2026-11-20 17:13:49 +00:00
fix(push): handle unresolved bot authors
This commit is contained in:
4 files changed
+34
-3
No files matched your search
@@ -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
|
||||
|
||||
|
||||
@@ -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` 时,会显示提交中的作者名称而不添加链接。
|
||||
|
||||
## 表情
|
||||
|
||||
|
||||
@@ -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}\``;
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in new issue
Block a user