feat(formatter): show queued/running status for workflow and check runs

This commit is contained in:
RhenCloud 2026-08-03 01:53:10 +08:00
parent 809f89400b
commit 9bb9cb1444
No known key found for this signature in database
GPG key ID: A574A617378C4E0B
2 changed files with 74 additions and 13 deletions

View file

@ -102,6 +102,54 @@ describe("message title spec", () => {
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", () => {
const msg = formatEvent(
route,

View file

@ -63,6 +63,8 @@ const WORKFLOW_CONCLUSION_EMOJI: Record<string, string> = {
action_required: "⚠️",
neutral: "",
stale: "♻️",
queued: "⏳",
running: "🔄",
};
function emojiPrefix(emoji: string, show: boolean): string {
@ -514,13 +516,19 @@ function formatWorkflowRun(
jobs?: Array<{ name?: string; conclusion?: string }>;
};
const conclusion = workflow.conclusion ?? "pending";
const emoji = WORKFLOW_CONCLUSION_EMOJI[conclusion] ?? "⏳";
const action = payload.action as string | undefined;
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 colorKey =
conclusion === "success"
status === "success"
? "workflow_run_success"
: conclusion === "failure"
: status === "failure"
? "workflow_run_failure"
: "workflow_run_other";
@ -528,7 +536,7 @@ function formatWorkflowRun(
fields.push({
name: t("fields.status"),
value: `${em(emoji)}${conclusion}`,
value: `${em(emoji)}${status}`,
inline: true,
});
@ -576,7 +584,7 @@ function formatWorkflowRun(
title: t("events.workflow_run.title", {
repo: repo ?? t("common.repository"),
name: workflow.name ?? "Workflow",
conclusion,
conclusion: status,
}),
url: workflow.html_url,
color: GITHUB_COLORS[colorKey],
@ -808,13 +816,18 @@ function formatCheckRun(
output?: { title?: string; summary?: string };
};
const conclusion = checkRun.conclusion ?? "pending";
const emoji = WORKFLOW_CONCLUSION_EMOJI[conclusion] ?? "⏳";
const status =
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 colorKey =
conclusion === "success"
status === "success"
? "check_run_success"
: conclusion === "failure"
: status === "failure"
? "check_run_failure"
: "check_run_other";
@ -822,7 +835,7 @@ function formatCheckRun(
fields.push({
name: t("fields.status"),
value: `${em(emoji)}${conclusion}`,
value: `${em(emoji)}${status}`,
inline: true,
});
@ -841,7 +854,7 @@ function formatCheckRun(
title: t("events.check_run.title", {
repo: repo ?? t("common.repository"),
name: checkRun.name ?? "Check Run",
conclusion,
conclusion: status,
}),
url: checkRun.html_url,
color: GITHUB_COLORS[colorKey],
@ -1052,7 +1065,7 @@ function formatDeploymentStatus(
fields.push({
name: t("fields.status"),
value: `${em(emoji)}${state}`,
value: `${em(emoji)}${status}`,
inline: true,
});