mirror of
https://github.com/ReCloudStudio/WebHooker.git
synced 2026-09-22 16:11:29 +00:00
- 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'
56 lines
1.8 KiB
TypeScript
56 lines
1.8 KiB
TypeScript
import type { NeutralMessage, NeutralAuthor } from "../types";
|
|
import { GITHUB_COLORS } from "./colors";
|
|
import { commitLink, emojiPrefix, type T, buildMessage, repoBaseUrl } from "./helpers";
|
|
|
|
export function formatCommitComment(
|
|
payload: Record<string, unknown>,
|
|
repo: string | undefined,
|
|
author: NeutralAuthor,
|
|
t: T,
|
|
showEmoji: boolean,
|
|
): NeutralMessage {
|
|
const action = (payload.action as string) ?? "created";
|
|
const comment = payload.comment as {
|
|
body?: string;
|
|
commit_id?: string;
|
|
html_url?: string;
|
|
};
|
|
|
|
const al = t("actions." + action) ?? action;
|
|
const em = (e: string): string => emojiPrefix(e, showEmoji);
|
|
const commentBody = comment.body?.slice(0, 500) ?? "";
|
|
const truncated = comment.body && comment.body.length > 500;
|
|
const baseUrl = repoBaseUrl(payload, repo);
|
|
const shortSha = comment.commit_id?.slice(0, 7) ?? "???????";
|
|
const shaLink = comment.commit_id ? commitLink(baseUrl, comment.commit_id, shortSha) : undefined;
|
|
|
|
const fields: Array<{ name: string; value: string; inline?: boolean }> = [];
|
|
|
|
if (comment.commit_id) {
|
|
fields.push({
|
|
name: t("fields.commit"),
|
|
value: shaLink!,
|
|
inline: true,
|
|
});
|
|
}
|
|
|
|
return buildMessage(
|
|
{
|
|
author,
|
|
title: shaLink
|
|
? t("events.commit_comment.title", {
|
|
repo: repo ?? t("common.repository"),
|
|
sha: shaLink,
|
|
})
|
|
: t("events.commit_comment.title_plain", {
|
|
repo: repo ?? t("common.repository"),
|
|
}),
|
|
url: comment.html_url,
|
|
color: GITHUB_COLORS.commit_comment,
|
|
description: `${t("events.commit_comment.action_comment", { emoji: em("💬"), action: al })}\n\n> ${commentBody}${truncated ? "..." : ""}`,
|
|
fields: fields.length > 0 ? fields : undefined,
|
|
},
|
|
t,
|
|
repo,
|
|
);
|
|
}
|