mirror of
https://github.com/Elysola/WebHooker.git
synced 2026-11-21 01:23:40 +00:00
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:
20 files changed
+425
-136
No files matched your search
@@ -1,6 +1,18 @@
|
||||
import type { NeutralMessage, NeutralAuthor } from "../types";
|
||||
import { GITHUB_COLORS, WORKFLOW_CONCLUSION_EMOJI } from "./colors";
|
||||
import { emojiPrefix, type T, buildMessage, branchLink, commitLink, repoBaseUrl } from "./helpers";
|
||||
import {
|
||||
branchLink,
|
||||
cap,
|
||||
commitLink,
|
||||
emojiPrefix,
|
||||
MAX_FIELD_VALUE,
|
||||
statusColorKey,
|
||||
type T,
|
||||
buildMessage,
|
||||
repoBaseUrl,
|
||||
workflowRunStatus,
|
||||
workflowStatus,
|
||||
} from "./helpers";
|
||||
|
||||
export function formatWorkflowJob(
|
||||
payload: Record<string, unknown>,
|
||||
@@ -20,21 +32,11 @@ export function formatWorkflowJob(
|
||||
run_id?: number;
|
||||
};
|
||||
|
||||
const status =
|
||||
job.status === "queued"
|
||||
? "queued"
|
||||
: job.status === "in_progress"
|
||||
? "running"
|
||||
: (job.conclusion ?? "pending");
|
||||
const status = workflowStatus(job.status, job.conclusion ?? undefined);
|
||||
const emoji = WORKFLOW_CONCLUSION_EMOJI[status] ?? "⏳";
|
||||
const em = (e: string): string => emojiPrefix(e, showEmoji);
|
||||
const baseUrl = repoBaseUrl(payload, repo);
|
||||
const colorKey =
|
||||
status === "success"
|
||||
? "workflow_run_success"
|
||||
: status === "failure"
|
||||
? "workflow_run_failure"
|
||||
: "workflow_run_other";
|
||||
const colorKey = statusColorKey("workflow_run", status);
|
||||
|
||||
const fields: Array<{ name: string; value: string; inline?: boolean }> = [];
|
||||
|
||||
@@ -114,21 +116,11 @@ export function formatWorkflowRun(
|
||||
};
|
||||
|
||||
const action = payload.action as string | undefined;
|
||||
const status =
|
||||
action === "in_progress"
|
||||
? "running"
|
||||
: action === "requested"
|
||||
? "queued"
|
||||
: (workflow.conclusion ?? "pending");
|
||||
const status = workflowRunStatus(action, workflow.conclusion);
|
||||
const emoji = WORKFLOW_CONCLUSION_EMOJI[status] ?? "⏳";
|
||||
const em = (e: string): string => emojiPrefix(e, showEmoji);
|
||||
const baseUrl = repoBaseUrl(payload, repo);
|
||||
const colorKey =
|
||||
status === "success"
|
||||
? "workflow_run_success"
|
||||
: status === "failure"
|
||||
? "workflow_run_failure"
|
||||
: "workflow_run_other";
|
||||
const colorKey = statusColorKey("workflow_run", status);
|
||||
|
||||
const fields: Array<{ name: string; value: string; inline?: boolean }> = [];
|
||||
|
||||
@@ -139,12 +131,13 @@ export function formatWorkflowRun(
|
||||
});
|
||||
|
||||
if (workflow.jobs?.length) {
|
||||
// Many-jobs workflows must stay under the Discord field value limit.
|
||||
const jobLines = workflow.jobs.map(
|
||||
(j) => `${em(WORKFLOW_CONCLUSION_EMOJI[j.conclusion ?? ""] ?? "⏳")}${j.name ?? ""}`,
|
||||
(j) => `${em(WORKFLOW_CONCLUSION_EMOJI[j.conclusion ?? ""] ?? "⏳")}${cap(j.name ?? "", 200)}`,
|
||||
);
|
||||
fields.push({
|
||||
name: t("fields.job"),
|
||||
value: jobLines.join("\n"),
|
||||
value: cap(jobLines.join("\n"), MAX_FIELD_VALUE),
|
||||
inline: false,
|
||||
});
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user