mirror of
https://github.com/ReCloudStudio/WebHooker.git
synced 2026-09-22 16:11:29 +00:00
feat(formatter): show queued/running status for workflow and check runs
This commit is contained in:
parent
809f89400b
commit
9bb9cb1444
2 changed files with 74 additions and 13 deletions
|
|
@ -102,6 +102,54 @@ describe("message title spec", () => {
|
||||||
expect(msg.embeds![0].fields![1].value).toBe("✅ build");
|
expect(msg.embeds![0].fields![1].value).toBe("✅ build");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("workflow_run distinguishes queued and running from pending", () => {
|
||||||
|
const run = {
|
||||||
|
name: "CI",
|
||||||
|
conclusion: null as string | null,
|
||||||
|
html_url: "https://github.com/acme/widget/actions/runs/42",
|
||||||
|
head_branch: "main",
|
||||||
|
run_number: 42,
|
||||||
|
};
|
||||||
|
const queued = formatEvent(
|
||||||
|
route,
|
||||||
|
event("workflow_run", {
|
||||||
|
action: "requested",
|
||||||
|
workflow_run: run,
|
||||||
|
repository: repo,
|
||||||
|
sender,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
expect(queued.embeds![0].title).toBe("acme/widget: CI — queued");
|
||||||
|
expect(queued.embeds![0].fields![0].value).toBe("⏳ queued");
|
||||||
|
|
||||||
|
const running = formatEvent(
|
||||||
|
route,
|
||||||
|
event("workflow_run", {
|
||||||
|
action: "in_progress",
|
||||||
|
workflow_run: run,
|
||||||
|
repository: repo,
|
||||||
|
sender,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
expect(running.embeds![0].title).toBe("acme/widget: CI — running");
|
||||||
|
expect(running.embeds![0].fields![0].value).toBe("🔄 running");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("check_run uses status for queued and running", () => {
|
||||||
|
const checkRun = {
|
||||||
|
name: "Lint",
|
||||||
|
html_url: "https://github.com/acme/widget/runs/1",
|
||||||
|
conclusion: null as string | null,
|
||||||
|
status: "in_progress",
|
||||||
|
};
|
||||||
|
const msg = formatEvent(
|
||||||
|
route,
|
||||||
|
event("check_run", { check_run: checkRun, repository: repo, sender }),
|
||||||
|
);
|
||||||
|
expect(msg.embeds![0].title).toBe("acme/widget: Lint — running");
|
||||||
|
expect(msg.embeds![0].fields![0].value).toBe("🔄 running");
|
||||||
|
});
|
||||||
|
|
||||||
it("unknown events fall back to repo: event: action", () => {
|
it("unknown events fall back to repo: event: action", () => {
|
||||||
const msg = formatEvent(
|
const msg = formatEvent(
|
||||||
route,
|
route,
|
||||||
|
|
|
||||||
|
|
@ -63,6 +63,8 @@ const WORKFLOW_CONCLUSION_EMOJI: Record<string, string> = {
|
||||||
action_required: "⚠️",
|
action_required: "⚠️",
|
||||||
neutral: "➖",
|
neutral: "➖",
|
||||||
stale: "♻️",
|
stale: "♻️",
|
||||||
|
queued: "⏳",
|
||||||
|
running: "🔄",
|
||||||
};
|
};
|
||||||
|
|
||||||
function emojiPrefix(emoji: string, show: boolean): string {
|
function emojiPrefix(emoji: string, show: boolean): string {
|
||||||
|
|
@ -514,13 +516,19 @@ function formatWorkflowRun(
|
||||||
jobs?: Array<{ name?: string; conclusion?: string }>;
|
jobs?: Array<{ name?: string; conclusion?: string }>;
|
||||||
};
|
};
|
||||||
|
|
||||||
const conclusion = workflow.conclusion ?? "pending";
|
const action = payload.action as string | undefined;
|
||||||
const emoji = WORKFLOW_CONCLUSION_EMOJI[conclusion] ?? "⏳";
|
const status =
|
||||||
|
action === "in_progress"
|
||||||
|
? "running"
|
||||||
|
: action === "requested"
|
||||||
|
? "queued"
|
||||||
|
: (workflow.conclusion ?? "pending");
|
||||||
|
const emoji = WORKFLOW_CONCLUSION_EMOJI[status] ?? "⏳";
|
||||||
const em = (e: string): string => emojiPrefix(e, showEmoji);
|
const em = (e: string): string => emojiPrefix(e, showEmoji);
|
||||||
const colorKey =
|
const colorKey =
|
||||||
conclusion === "success"
|
status === "success"
|
||||||
? "workflow_run_success"
|
? "workflow_run_success"
|
||||||
: conclusion === "failure"
|
: status === "failure"
|
||||||
? "workflow_run_failure"
|
? "workflow_run_failure"
|
||||||
: "workflow_run_other";
|
: "workflow_run_other";
|
||||||
|
|
||||||
|
|
@ -528,7 +536,7 @@ function formatWorkflowRun(
|
||||||
|
|
||||||
fields.push({
|
fields.push({
|
||||||
name: t("fields.status"),
|
name: t("fields.status"),
|
||||||
value: `${em(emoji)}${conclusion}`,
|
value: `${em(emoji)}${status}`,
|
||||||
inline: true,
|
inline: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -576,7 +584,7 @@ function formatWorkflowRun(
|
||||||
title: t("events.workflow_run.title", {
|
title: t("events.workflow_run.title", {
|
||||||
repo: repo ?? t("common.repository"),
|
repo: repo ?? t("common.repository"),
|
||||||
name: workflow.name ?? "Workflow",
|
name: workflow.name ?? "Workflow",
|
||||||
conclusion,
|
conclusion: status,
|
||||||
}),
|
}),
|
||||||
url: workflow.html_url,
|
url: workflow.html_url,
|
||||||
color: GITHUB_COLORS[colorKey],
|
color: GITHUB_COLORS[colorKey],
|
||||||
|
|
@ -808,13 +816,18 @@ function formatCheckRun(
|
||||||
output?: { title?: string; summary?: string };
|
output?: { title?: string; summary?: string };
|
||||||
};
|
};
|
||||||
|
|
||||||
const conclusion = checkRun.conclusion ?? "pending";
|
const status =
|
||||||
const emoji = WORKFLOW_CONCLUSION_EMOJI[conclusion] ?? "⏳";
|
checkRun.status === "queued"
|
||||||
|
? "queued"
|
||||||
|
: checkRun.status === "in_progress"
|
||||||
|
? "running"
|
||||||
|
: (checkRun.conclusion ?? "pending");
|
||||||
|
const emoji = WORKFLOW_CONCLUSION_EMOJI[status] ?? "⏳";
|
||||||
const em = (e: string): string => emojiPrefix(e, showEmoji);
|
const em = (e: string): string => emojiPrefix(e, showEmoji);
|
||||||
const colorKey =
|
const colorKey =
|
||||||
conclusion === "success"
|
status === "success"
|
||||||
? "check_run_success"
|
? "check_run_success"
|
||||||
: conclusion === "failure"
|
: status === "failure"
|
||||||
? "check_run_failure"
|
? "check_run_failure"
|
||||||
: "check_run_other";
|
: "check_run_other";
|
||||||
|
|
||||||
|
|
@ -822,7 +835,7 @@ function formatCheckRun(
|
||||||
|
|
||||||
fields.push({
|
fields.push({
|
||||||
name: t("fields.status"),
|
name: t("fields.status"),
|
||||||
value: `${em(emoji)}${conclusion}`,
|
value: `${em(emoji)}${status}`,
|
||||||
inline: true,
|
inline: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -841,7 +854,7 @@ function formatCheckRun(
|
||||||
title: t("events.check_run.title", {
|
title: t("events.check_run.title", {
|
||||||
repo: repo ?? t("common.repository"),
|
repo: repo ?? t("common.repository"),
|
||||||
name: checkRun.name ?? "Check Run",
|
name: checkRun.name ?? "Check Run",
|
||||||
conclusion,
|
conclusion: status,
|
||||||
}),
|
}),
|
||||||
url: checkRun.html_url,
|
url: checkRun.html_url,
|
||||||
color: GITHUB_COLORS[colorKey],
|
color: GITHUB_COLORS[colorKey],
|
||||||
|
|
@ -1052,7 +1065,7 @@ function formatDeploymentStatus(
|
||||||
|
|
||||||
fields.push({
|
fields.push({
|
||||||
name: t("fields.status"),
|
name: t("fields.status"),
|
||||||
value: `${em(emoji)}${state}`,
|
value: `${em(emoji)}${status}`,
|
||||||
inline: true,
|
inline: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue