mirror of
https://github.com/ReCloudStudio/WebHooker.git
synced 2026-09-23 00:21:28 +00:00
feat: support check_suite webhook events
This commit is contained in:
parent
7179a35457
commit
fb9550b94d
6 changed files with 115 additions and 2 deletions
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue