feat: support check_suite webhook events

This commit is contained in:
RhenCloud 2026-08-03 06:58:47 +08:00
parent 7179a35457
commit fb9550b94d
No known key found for this signature in database
GPG key ID: A574A617378C4E0B
6 changed files with 115 additions and 2 deletions

View file

@ -2,6 +2,85 @@ import type { NeutralMessage, NeutralAuthor } from "../types";
import { GITHUB_COLORS, WORKFLOW_CONCLUSION_EMOJI } from "./colors";
import { emojiPrefix, type T, buildMessage } from "./helpers";
export function formatCheckSuite(
payload: Record<string, unknown>,
repo: string | undefined,
author: NeutralAuthor,
t: T,
showEmoji: boolean,
): NeutralMessage {
const suite = payload.check_suite as {
head_branch?: string;
head_sha?: string;
conclusion?: string;
status?: string;
app?: { name?: string };
html_url?: string;
};
const status =
suite.status === "queued"
? "queued"
: suite.status === "in_progress"
? "running"
: (suite.conclusion ?? "pending");
const emoji = WORKFLOW_CONCLUSION_EMOJI[status] ?? "⏳";
const em = (e: string): string => emojiPrefix(e, showEmoji);
const colorKey =
status === "success"
? "check_run_success"
: status === "failure"
? "check_run_failure"
: "check_run_other";
const fields: Array<{ name: string; value: string; inline?: boolean }> = [];
fields.push({
name: t("fields.status"),
value: `${em(emoji)}${status}`,
inline: true,
});
if (suite.app?.name) {
fields.push({
name: t("fields.service"),
value: suite.app.name,
inline: true,
});
}
if (suite.head_branch) {
fields.push({
name: t("fields.branch"),
value: suite.head_branch,
inline: true,
});
}
if (suite.head_sha) {
fields.push({
name: t("fields.commit"),
value: suite.head_sha.slice(0, 7),
inline: true,
});
}
return buildMessage(
{
author,
title: t("events.check_suite.title", {
repo: repo ?? t("common.repository"),
conclusion: status,
}),
url: suite.html_url,
color: GITHUB_COLORS[colorKey],
fields,
},
t,
repo,
);
}
export function formatCheckRun(
payload: Record<string, unknown>,
repo: string | undefined,