mirror of
https://github.com/ReCloudStudio/WebHooker.git
synced 2026-09-22 16:11:29 +00:00
feat: add formatters for workflow_job, status, deployment, ping
This commit is contained in:
parent
fc2e2c2efa
commit
1fc3991332
6 changed files with 292 additions and 6 deletions
|
|
@ -81,6 +81,77 @@ export function formatCheckSuite(
|
|||
);
|
||||
}
|
||||
|
||||
export function formatStatus(
|
||||
payload: Record<string, unknown>,
|
||||
repo: string | undefined,
|
||||
author: NeutralAuthor,
|
||||
t: T,
|
||||
showEmoji: boolean,
|
||||
): NeutralMessage {
|
||||
const state = (payload.state as string) ?? "pending";
|
||||
const context = (payload.context as string) ?? "";
|
||||
const description = payload.description as string | undefined;
|
||||
const targetUrl = payload.target_url as string | undefined;
|
||||
const sha = payload.sha as string | undefined;
|
||||
|
||||
const emoji = state === "success" ? "✅" : state === "failure" || state === "error" ? "❌" : "⏳";
|
||||
const em = (e: string): string => emojiPrefix(e, showEmoji);
|
||||
const colorKey =
|
||||
state === "success"
|
||||
? "check_run_success"
|
||||
: state === "failure" || state === "error"
|
||||
? "check_run_failure"
|
||||
: "check_run_other";
|
||||
|
||||
const fields: Array<{ name: string; value: string; inline?: boolean }> = [];
|
||||
|
||||
fields.push({
|
||||
name: t("fields.status"),
|
||||
value: `${em(emoji)}${state}`,
|
||||
inline: true,
|
||||
});
|
||||
|
||||
if (context) {
|
||||
fields.push({
|
||||
name: t("fields.context"),
|
||||
value: context,
|
||||
inline: true,
|
||||
});
|
||||
}
|
||||
|
||||
if (sha) {
|
||||
fields.push({
|
||||
name: t("fields.commit"),
|
||||
value: `\`${sha.slice(0, 7)}\``,
|
||||
inline: true,
|
||||
});
|
||||
}
|
||||
|
||||
if (description) {
|
||||
fields.push({
|
||||
name: t("fields.description"),
|
||||
value: description,
|
||||
inline: false,
|
||||
});
|
||||
}
|
||||
|
||||
return buildMessage(
|
||||
{
|
||||
author,
|
||||
title: t("events.status.title", {
|
||||
repo: repo ?? t("common.repository"),
|
||||
context: context || t("common.unknown"),
|
||||
state,
|
||||
}),
|
||||
url: targetUrl,
|
||||
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