fix(formatters): dedupe push count line, link workflow run name to actions

This commit is contained in:
RhenCloud 2026-08-13 19:37:20 +08:00
parent dfb65ef70d
commit cf65111e4e
No known key found for this signature in database
GPG key ID: A574A617378C4E0B
5 changed files with 16 additions and 18 deletions

View file

@ -58,14 +58,6 @@ export function formatPush(
descriptionParts.push(em("🆕") + t("events.push.branch_created")); descriptionParts.push(em("🆕") + t("events.push.branch_created"));
} }
descriptionParts.push(
t("events.push.commits_pushed", {
count,
s: count !== 1 ? "s" : "",
ref: isTagPush ? tagLink(baseUrl, rawRef, ref) : branchLink(baseUrl, rawRef, ref),
}),
);
if (compareUrl) { if (compareUrl) {
descriptionParts.push(t("events.push.view_comparison", { url: compareUrl })); descriptionParts.push(t("events.push.view_comparison", { url: compareUrl }));
} }
@ -119,6 +111,7 @@ export function formatPush(
count, count,
s: count !== 1 ? "s" : "", s: count !== 1 ? "s" : "",
repo: repo ?? t("common.repository"), repo: repo ?? t("common.repository"),
ref: isTagPush ? tagLink(baseUrl, rawRef, ref) : branchLink(baseUrl, rawRef, ref),
}), }),
url: compareUrl, url: compareUrl,
color: GITHUB_COLORS.push, color: GITHUB_COLORS.push,

View file

@ -175,13 +175,16 @@ export function formatWorkflowRun(
}); });
} }
const runLabel = workflow.html_url
? `[${workflow.name ?? "Workflow"}${status}](${workflow.html_url})`
: `${workflow.name ?? "Workflow"}${status}`;
return buildMessage( return buildMessage(
{ {
author, author,
title: t("events.workflow_run.title", { title: t("events.workflow_run.title", {
repo: repo ?? t("common.repository"), repo: repo ?? t("common.repository"),
name: workflow.name ?? "Workflow", run: runLabel,
conclusion: status,
}), }),
url: workflow.html_url, url: workflow.html_url,
color: GITHUB_COLORS[colorKey], color: GITHUB_COLORS[colorKey],

View file

@ -88,12 +88,11 @@ export const en = {
push: { push: {
force_push: "**Force push**", force_push: "**Force push**",
branch_created: "Branch created", branch_created: "Branch created",
commits_pushed: "**{count}** commit{s} pushed to {ref}",
view_comparison: "[View comparison]({url})", view_comparison: "[View comparison]({url})",
added: "+{count} added", added: "+{count} added",
removed: "-{count} removed", removed: "-{count} removed",
modified: "~{count} modified", modified: "~{count} modified",
title: "{repo}: Pushed {count} commit{s}", title: "{repo}: Pushed {count} commit{s} to {ref}",
}, },
pr: { pr: {
action_pr: "{emoji}**{action}** pull request", action_pr: "{emoji}**{action}** pull request",
@ -108,7 +107,7 @@ export const en = {
action_comment: "{emoji}**{action}** comment", action_comment: "{emoji}**{action}** comment",
}, },
workflow_run: { workflow_run: {
title: "{repo}: {name} — {conclusion}", title: "{repo}: {run}",
}, },
workflow_job: { workflow_job: {
title: "{repo}: Job {name} — {conclusion}", title: "{repo}: Job {name} — {conclusion}",

View file

@ -108,7 +108,7 @@ export const zh = {
action_comment: "{emoji}**{action}** 评论", action_comment: "{emoji}**{action}** 评论",
}, },
workflow_run: { workflow_run: {
title: "{repo}: {name} — {conclusion}", title: "{repo}: {run}",
}, },
workflow_job: { workflow_job: {
title: "{repo}: 作业 {name} — {conclusion}", title: "{repo}: 作业 {name} — {conclusion}",

View file

@ -31,7 +31,10 @@ describe("message title spec", () => {
sender, sender,
}), }),
); );
expect(msg.title).toBe("acme/widget: Pushed 1 commit"); expect(msg.title).toBe(
"acme/widget: Pushed 1 commit to [`main`](https://github.com/acme/widget/tree/main)",
);
expect(msg.description).toBe("[View comparison](https://github.com/acme/widget/compare/abc...def)");
}); });
it("pull_request title is repo#number: title", () => { it("pull_request title is repo#number: title", () => {
@ -98,7 +101,7 @@ describe("message title spec", () => {
sender, sender,
}), }),
); );
expect(msg.title).toBe("acme/widget: CI — success"); expect(msg.title).toBe("acme/widget: [CI — success](https://github.com/acme/widget/actions/runs/42)");
expect(msg.fields![1].value).toBe("✅ build"); expect(msg.fields![1].value).toBe("✅ build");
}); });
@ -119,7 +122,7 @@ describe("message title spec", () => {
sender, sender,
}), }),
); );
expect(queued.title).toBe("acme/widget: CI — queued"); expect(queued.title).toBe("acme/widget: [CI — queued](https://github.com/acme/widget/actions/runs/42)");
expect(queued.fields![0].value).toBe("⏳ queued"); expect(queued.fields![0].value).toBe("⏳ queued");
const running = formatEvent( const running = formatEvent(
@ -131,7 +134,7 @@ describe("message title spec", () => {
sender, sender,
}), }),
); );
expect(running.title).toBe("acme/widget: CI — running"); expect(running.title).toBe("acme/widget: [CI — running](https://github.com/acme/widget/actions/runs/42)");
expect(running.fields![0].value).toBe("🔄 running"); expect(running.fields![0].value).toBe("🔄 running");
}); });