mirror of
https://github.com/Elysola/WebHooker.git
synced 2026-11-21 01:23:40 +00:00
fix(push): show differing commit author
This commit is contained in:
4 files changed
+63
-2
No files matched your search
@@ -23,6 +23,8 @@ 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.
|
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)`).
|
||||||
|
|
||||||
## Emoji
|
## Emoji
|
||||||
|
|
||||||
Event-specific emoji are added by the formatters; per-group `Group.emoji` (default true) strips them all when disabled. Milestone progress bars are exempt. See [Message Language](./i18n).
|
Event-specific emoji are added by the formatters; per-group `Group.emoji` (default true) strips them all when disabled. Milestone progress bars are exempt. See [Message Language](./i18n).
|
||||||
|
|||||||
@@ -23,6 +23,8 @@
|
|||||||
|
|
||||||
提交哈希、分支与标签渲染为带超链接的行内代码(如 ``[`abc123d`](https://…/commit/abc123def456)``),仓库基地址不可用时回退为纯行内代码。
|
提交哈希、分支与标签渲染为带超链接的行内代码(如 ``[`abc123d`](https://…/commit/abc123def456)``),仓库基地址不可用时回退为纯行内代码。
|
||||||
|
|
||||||
|
对于 push 事件,若提交作者的 GitHub 用户名与推送者不同,提交行末尾会附上作者链接(如 `- [octocat](https://github.com/octocat)`)。
|
||||||
|
|
||||||
## 表情
|
## 表情
|
||||||
|
|
||||||
事件专属表情由格式化器添加;分组级 `Group.emoji`(默认开启)关闭后会全部去除。里程碑进度条不受影响。见[消息语言](./i18n)。
|
事件专属表情由格式化器添加;分组级 `Group.emoji`(默认开启)关闭后会全部去除。里程碑进度条不受影响。见[消息语言](./i18n)。
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ export function formatPush(
|
|||||||
const commits = (payload.commits ?? []) as Array<{
|
const commits = (payload.commits ?? []) as Array<{
|
||||||
id?: string;
|
id?: string;
|
||||||
message?: string;
|
message?: string;
|
||||||
author?: { name?: string; email?: string };
|
author?: { name?: string; email?: string; username?: string };
|
||||||
added?: string[];
|
added?: string[];
|
||||||
removed?: string[];
|
removed?: string[];
|
||||||
modified?: string[];
|
modified?: string[];
|
||||||
@@ -34,6 +34,7 @@ export function formatPush(
|
|||||||
const forced = payload.forced as boolean | undefined;
|
const forced = payload.forced as boolean | undefined;
|
||||||
const created = payload.created as boolean | undefined;
|
const created = payload.created as boolean | undefined;
|
||||||
const deleted = payload.deleted as boolean | undefined;
|
const deleted = payload.deleted as boolean | undefined;
|
||||||
|
const pusher = (payload.pusher as { name?: string } | undefined)?.name;
|
||||||
const em = (e: string): string => emojiPrefix(e, showEmoji);
|
const em = (e: string): string => emojiPrefix(e, showEmoji);
|
||||||
|
|
||||||
// A branch/tag deletion pushed via `git push --delete` arrives as a push
|
// A branch/tag deletion pushed via `git push --delete` arrives as a push
|
||||||
@@ -93,8 +94,12 @@ export function formatPush(
|
|||||||
const commitsToShow = count <= 5 ? commits : commits.slice(0, 3);
|
const commitsToShow = count <= 5 ? commits : commits.slice(0, 3);
|
||||||
for (const c of commitsToShow) {
|
for (const c of commitsToShow) {
|
||||||
const shortId = c.id?.slice(0, 7) ?? "???????";
|
const shortId = c.id?.slice(0, 7) ?? "???????";
|
||||||
const msg =
|
let msg =
|
||||||
(c.message?.split("\n")[0] ?? "").slice(0, MAX_COMMIT_SUBJECT) || t("common.no_message");
|
(c.message?.split("\n")[0] ?? "").slice(0, MAX_COMMIT_SUBJECT) || t("common.no_message");
|
||||||
|
const commitAuthor = c.author?.username;
|
||||||
|
if (commitAuthor && commitAuthor.toLowerCase() !== pusher?.toLowerCase()) {
|
||||||
|
msg += ` - [${commitAuthor}](https://github.com/${encodeURIComponent(commitAuthor)})`;
|
||||||
|
}
|
||||||
const url = baseUrl && c.id ? `${baseUrl}/commit/${c.id}` : null;
|
const url = baseUrl && c.id ? `${baseUrl}/commit/${c.id}` : null;
|
||||||
const hash = url ? `[\`${shortId}\`](${url})` : `\`${shortId}\``;
|
const hash = url ? `[\`${shortId}\`](${url})` : `\`${shortId}\``;
|
||||||
descLines.push(`${hash} ${msg}`);
|
descLines.push(`${hash} ${msg}`);
|
||||||
|
|||||||
@@ -47,6 +47,58 @@ describe("message title spec", () => {
|
|||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("adds a commit author link when it differs from the pusher", () => {
|
||||||
|
const msg = formatEvent(
|
||||||
|
route,
|
||||||
|
event("push", {
|
||||||
|
ref: "refs/heads/main",
|
||||||
|
commits: [
|
||||||
|
{
|
||||||
|
id: "abcd1234ef",
|
||||||
|
message: "fix stuff",
|
||||||
|
author: { username: "commit-author" },
|
||||||
|
added: [],
|
||||||
|
removed: [],
|
||||||
|
modified: [],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
pusher: { name: "merge-bot" },
|
||||||
|
repository: repo,
|
||||||
|
sender,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(msg.description).toBe(
|
||||||
|
"[`abcd123`](https://github.com/acme/widget/commit/abcd1234ef) fix stuff - [commit-author](https://github.com/commit-author)",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("does not add a commit author link when it matches the pusher", () => {
|
||||||
|
const msg = formatEvent(
|
||||||
|
route,
|
||||||
|
event("push", {
|
||||||
|
ref: "refs/heads/main",
|
||||||
|
commits: [
|
||||||
|
{
|
||||||
|
id: "abcd1234ef",
|
||||||
|
message: "fix stuff",
|
||||||
|
author: { username: "octocat" },
|
||||||
|
added: [],
|
||||||
|
removed: [],
|
||||||
|
modified: [],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
pusher: { name: "OctoCat" },
|
||||||
|
repository: repo,
|
||||||
|
sender,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(msg.description).toBe(
|
||||||
|
"[`abcd123`](https://github.com/acme/widget/commit/abcd1234ef) fix stuff",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
it("pull_request title is repo#number: title", () => {
|
it("pull_request title is repo#number: title", () => {
|
||||||
const msg = formatEvent(
|
const msg = formatEvent(
|
||||||
route,
|
route,
|
||||||
|
|||||||
Reference in new issue
Block a user