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 } from "./helpers";
import { branchLink, emojiPrefix, tagLink, type T, buildMessage, repoBaseUrl } from "./helpers";
export function formatCreate(
payload: Record<string, unknown>,
@ -11,6 +11,8 @@ export function formatCreate(
): NeutralMessage {
const refType = (payload.ref_type as string) ?? "branch";
const ref = (payload.ref as string) ?? t("common.unknown");
const baseUrl = repoBaseUrl(payload, repo);
const refText = refType === "tag" ? tagLink(baseUrl, ref) : branchLink(baseUrl, ref);
const emoji = refType === "tag" ? "🏷️" : "🌿";
const em = (e: string): string => emojiPrefix(e, showEmoji);
@ -25,7 +27,7 @@ export function formatCreate(
fields.push({
name: t("fields.name"),
value: `\`${ref}\``,
value: refText,
inline: true,
});
@ -44,7 +46,7 @@ export function formatCreate(
repo: repo ?? t("common.repository"),
emoji: em(emoji),
type: refType,
ref,
ref: refText,
}),
color: GITHUB_COLORS.create,
fields,
@ -63,6 +65,8 @@ export function formatDelete(
): NeutralMessage {
const refType = (payload.ref_type as string) ?? "branch";
const ref = (payload.ref as string) ?? t("common.unknown");
const baseUrl = repoBaseUrl(payload, repo);
const refText = refType === "tag" ? tagLink(baseUrl, ref) : branchLink(baseUrl, ref);
const emoji = refType === "tag" ? "🏷️" : "🌿";
const em = (e: string): string => emojiPrefix(e, showEmoji);
@ -74,7 +78,7 @@ export function formatDelete(
repo: repo ?? t("common.repository"),
emoji: em(emoji),
type: refType,
ref,
ref: refText,
}),
color: GITHUB_COLORS.delete,
},