fix(formatters): localize PR buttons, cap oversized content, dedupe status logic

- PR merge/close button labels now follow the group language (actions.merge/close)
  instead of hardcoded Chinese
- clamp content to Discord embed limits (title 256, description 4096, field value
  1024, 25 fields) in formatters plus a render-layer safety net; Telegram gets a
  tag-safe 4096-char cap (capHtml closes dangling tags)
- raise commit subject truncation from 72 to 200 chars (MAX_COMMIT_SUBJECT)
- extract workflowStatus/workflowRunStatus/statusColorKey helpers shared by
  check_run/check_suite/workflow_run/workflow_job
- dedupe deployment ref/sha fields via addDeploymentRefFields
- commit_comment without a commit id uses title_plain (no dangling ???????)
- tag pushes now report 'Tag created'; zh push title includes the {ref}
- sender profile link derives from the repo's forge origin instead of github.com
- group webhook log emoji injected via emojiPrefix, removed from locale files
- dispatchEvent accepts preloaded groups (single KV read per webhook)
- webhook 401 logs distinguish 'secret not configured' from 'invalid signature'
This commit is contained in:
RhenCloud 2026-08-14 07:41:19 +08:00
parent e59b10f739
commit a5324fb0ea
No known key found for this signature in database
GPG key ID: A574A617378C4E0B
20 changed files with 425 additions and 136 deletions

View file

@ -10,6 +10,30 @@ import {
repoBaseUrl,
} from "./helpers";
/** Shared "branch/tag + commit" fields for deployment events. */
function addDeploymentRefFields(
fields: Array<{ name: string; value: string; inline?: boolean }>,
deployment: { ref?: string; sha?: string },
baseUrl: string | undefined,
t: T,
): void {
if (deployment.ref) {
const isTag = deployment.ref.startsWith("refs/tags/");
fields.push({
name: t("fields.branch_tag"),
value: isTag ? tagLink(baseUrl, deployment.ref) : branchLink(baseUrl, deployment.ref),
inline: true,
});
}
if (deployment.sha) {
fields.push({
name: t("fields.commit"),
value: commitLink(baseUrl, deployment.sha, deployment.sha.slice(0, 7)),
inline: true,
});
}
}
export function formatDeployment(
payload: Record<string, unknown>,
repo: string | undefined,
@ -29,7 +53,6 @@ export function formatDeployment(
const emoji = "🚀";
const em = (e: string): string => emojiPrefix(e, showEmoji);
const env = deployment.environment ?? t("common.unknown");
const shortSha = deployment.sha?.slice(0, 7) ?? "???????";
const baseUrl = repoBaseUrl(payload, repo);
const fields: Array<{ name: string; value: string; inline?: boolean }> = [];
@ -45,22 +68,7 @@ export function formatDeployment(
inline: true,
});
if (deployment.ref) {
const isTag = deployment.ref.startsWith("refs/tags/");
fields.push({
name: t("fields.branch_tag"),
value: isTag ? tagLink(baseUrl, deployment.ref) : branchLink(baseUrl, deployment.ref),
inline: true,
});
}
if (deployment.sha) {
fields.push({
name: t("fields.commit"),
value: commitLink(baseUrl, deployment.sha, shortSha),
inline: true,
});
}
addDeploymentRefFields(fields, deployment, baseUrl, t);
if (deployment.description) {
fields.push({
@ -116,7 +124,6 @@ export function formatDeploymentStatus(
const emoji = state === "success" ? "✅" : state === "failure" ? "❌" : "⏳";
const em = (e: string): string => emojiPrefix(e, showEmoji);
const env = status.environment ?? deployment.environment ?? t("common.unknown");
const shortSha = deployment.sha?.slice(0, 7) ?? "???????";
const baseUrl = repoBaseUrl(payload, repo);
const fields: Array<{ name: string; value: string; inline?: boolean }> = [];
@ -133,22 +140,7 @@ export function formatDeploymentStatus(
inline: true,
});
if (deployment.ref) {
const isTag = deployment.ref.startsWith("refs/tags/");
fields.push({
name: t("fields.branch_tag"),
value: isTag ? tagLink(baseUrl, deployment.ref) : branchLink(baseUrl, deployment.ref),
inline: true,
});
}
if (deployment.sha) {
fields.push({
name: t("fields.commit"),
value: commitLink(baseUrl, deployment.sha, shortSha),
inline: true,
});
}
addDeploymentRefFields(fields, deployment, baseUrl, t);
if (status.environment_url) {
fields.push({