style(formatters): render branch/commit/tag refs as inline code with hyperlinks

Unify all branch, commit hash and tag references across formatters to the push commit style (inline code + link). Adds commitLink/branchLink/tagLink helpers in formatters/helpers.ts, links branches to /tree/, tags to /releases/tag/, and PR head branches to the fork repo. Drops the backticks from the en/zh locale templates around {ref}/{sha} since the formatters now inject pre-linked values.
This commit is contained in:
RhenCloud 2026-08-13 06:37:45 +08:00
parent 3029b3468f
commit bf76b9342f
No known key found for this signature in database
GPG key ID: A574A617378C4E0B
12 changed files with 110 additions and 45 deletions

View file

@ -1,6 +1,6 @@
import type { NeutralMessage, NeutralAuthor } from "../types";
import { GITHUB_COLORS } from "./colors";
import { emojiPrefix, type T, buildMessage, repoBaseUrl } from "./helpers";
import { branchLink, emojiPrefix, tagLink, type T, buildMessage, repoBaseUrl } from "./helpers";
export function formatPush(
payload: Record<string, unknown>,
@ -9,7 +9,9 @@ export function formatPush(
t: T,
showEmoji: boolean,
): NeutralMessage {
const ref = (payload.ref as string)?.replace("refs/heads/", "").replace("refs/tags/", "tag: ");
const rawRef = (payload.ref as string) ?? "";
const isTagPush = rawRef.startsWith("refs/tags/");
const ref = rawRef.replace("refs/heads/", "").replace("refs/tags/", "tag: ");
const commits = (payload.commits ?? []) as Array<{
id?: string;
message?: string;
@ -35,7 +37,11 @@ export function formatPush(
}
descriptionParts.push(
t("events.push.commits_pushed", { count, s: count !== 1 ? "s" : "", ref: ref ?? "" }),
t("events.push.commits_pushed", {
count,
s: count !== 1 ? "s" : "",
ref: isTagPush ? tagLink(baseUrl, rawRef, ref) : branchLink(baseUrl, rawRef, ref),
}),
);
if (compareUrl) {