mirror of
https://github.com/Elysola/WebHooker.git
synced 2026-11-20 17:13:49 +00:00
feat(workflow): render workflow_run jobs as colored diff block
List each job on its own line with a status emoji and, for completed jobs, the duration. Discord colors the diff fence: '+' green for success, '-' red for other finished conclusions, plain for running/queued/pending. Telegram/Feishu collapse it to inline code. Sync AGENTS.md, README(s), docs guide and supported-events tables.
This commit is contained in:
9 files changed
+109
-12
No files matched your search
@@ -197,6 +197,11 @@ tests/__snapshots__/ # formatter snapshot golden files (toMatchSnapshot)
|
||||
the locale files. Emoji is controlled per group through the `Group.emoji` toggle (default true);
|
||||
`showEmoji=false` must strip every emoji from titles, descriptions, fields and links.
|
||||
- Milestone progress bars (🟢🟡🟠⬜) are data visualization and are exempt from the emoji toggle.
|
||||
- `workflow_run` messages render a **Jobs** field as a Discord `diff` fenced code block
|
||||
(`server/lib/formatters/workflow.ts`): one line per job, `${marker} ${name} ${emoji}${status}` plus
|
||||
` · {duration}` for completed jobs. `+` (green) for `success`, `-` (red) for other non-pending
|
||||
conclusions, a plain space for running/queued/pending; job names clamp to 200 chars and the field
|
||||
to the platform field limit. Drivers without diff support (Telegram, Feishu) collapse it to inline code.
|
||||
- Commit hashes, branches and tags render as inline code wrapped in a hyperlink
|
||||
(`commitLink`/`branchLink`/`tagLink` helpers in `server/lib/formatters/helpers.ts`, e.g.
|
||||
``[`abc123d`](https://.../commit/abc123def456)``, ``[`main`](https://.../tree/main)``),
|
||||
|
||||
@@ -13,7 +13,7 @@ GitHub / Gitea webhook → Discord / Telegram / Feishu dispatcher. Receives webh
|
||||
- Combine filters into a boolean AST (`all` / `any` / `not` nodes) via the route editor's visual builder; reuse named filter fragments and dry-run any filter against a pasted JSON payload without storing it
|
||||
- Rich messages with color coding, author avatars, fields, and timestamps — rendered as Discord embeds and Telegram HTML
|
||||
- Route to Discord channels/threads, Telegram chats/topics, and Feishu group chats (multi-target routes)
|
||||
- `workflow_run` / `check_run` progress is edited **in place** (single message updated as the run advances) on Discord, Telegram, and Feishu — `check_run` tracks by check name + commit SHA so deployments that issue a fresh run id per phase (e.g. Cloudflare Pages) still edit the same message
|
||||
- `workflow_run` / `check_run` progress is edited **in place** (single message updated as the run advances) on Discord, Telegram, and Feishu — `check_run` tracks by check name + commit SHA so deployments that issue a fresh run id per phase (e.g. Cloudflare Pages) still edit the same message; `workflow_run` embeds a colored per-job code block (🟢 success, 🔴 failure, running/queued inline)
|
||||
- **Per-group webhook log channel** — point a group at a Discord channel/thread, Telegram chat/topic, or Feishu chat and every webhook the group's routes dispatch is summarized there (✅/❌ per route × target)
|
||||
- GitHub OAuth for user actions (comment, edit comment, delete comment, merge, close, react)
|
||||
- **Web UI config console** (`/admin`) — manage routes and groups with GitHub OAuth + admin whitelist, view send logs
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ GitHub / Gitea webhook → Discord / Telegram / 飞书 分发服务。通过 Clo
|
||||
- 在路由编辑器的可视化构建器中把过滤器组合成布尔 AST(`all` / `any` / `not` 节点);可复用命名过滤器片段,并可对粘贴的 JSON 载荷做无存储的试匹配
|
||||
- 富消息:颜色编码、作者头像、字段、时间戳——渲染为 Discord embed 与 Telegram HTML
|
||||
- 路由到 Discord 频道/子区、Telegram 群组/话题与飞书群聊(一条路由可多目标)
|
||||
- `workflow_run` / `check_run` 进度**原地编辑**同一条消息(运行推进时更新),Discord、Telegram 与飞书均支持 —— `check_run` 以 check 名 + commit SHA 追踪,因此每个阶段都换新 run id 的部署(如 Cloudflare Pages)仍会编辑同一条消息
|
||||
- `workflow_run` / `check_run` 进度**原地编辑**同一条消息(运行推进时更新),Discord、Telegram 与飞书均支持 —— `check_run` 以 check 名 + commit SHA 追踪,因此每个阶段都换新 run id 的部署(如 Cloudflare Pages)仍会编辑同一条消息;`workflow_run` 内嵌带颜色的逐作业代码块(🟢 成功、🔴 失败、运行中/排队中不着色)
|
||||
- **分组级 Webhook 日志频道** —— 为分组指定一个 Discord 频道/子区、Telegram 群组/话题或飞书群聊,该分组路由每次分发 webhook 都会向其中发送摘要(每条「路由 × 目标」一行,✅/❌ 结果)
|
||||
- GitHub OAuth 用户授权(评论、编辑评论、删除评论、合并、关闭、反应)
|
||||
- **Web 配置控制台**(`/admin`)— 通过 GitHub OAuth + 管理员白名单管理路由与分组、查看发送日志
|
||||
|
||||
@@ -10,7 +10,7 @@ WebHooker supports 28 GitHub webhook event types, each with a dedicated formatte
|
||||
| `pull_request` | PR opened/closed/merged/edited | PR title, branch, diff stats, labels |
|
||||
| `issues` | Issue opened/closed/edited | Issue title, labels, assignees |
|
||||
| `issue_comment` | Comment on issue or PR | Comment body, issue reference |
|
||||
| `workflow_run` | CI/CD workflow phase updated | Workflow status, conclusion, duration; phases update a single message in place |
|
||||
| `workflow_run` | CI/CD workflow phase updated | Workflow status, conclusion, duration, colored per-job breakdown; phases update a single message in place |
|
||||
| `workflow_job` | CI job phase updated | Job name, status, conclusion, workflow |
|
||||
| `status` | Commit status updated | Commit status, context, state, commit link |
|
||||
| `deployment` | Deployment created | Environment, ref, task |
|
||||
|
||||
@@ -34,3 +34,16 @@ With `Group.forgeSources` (a list of `{ host, type, name? }` entries) the messag
|
||||
## In-Place Updates
|
||||
|
||||
`workflow_run` and `check_run` messages are sent once and edited in place as the run progresses (queued → running → success/failure) — no duplicate messages. Tracking uses KV `msg:*` with a stable `updateKey` per run: `workflow_run` keys on the workflow id, while `check_run` keys on the check name + commit SHA (falling back to the run id) so deployments that emit a fresh run id per phase — e.g. Cloudflare Pages — still edit the same message.
|
||||
|
||||
## Workflow Jobs
|
||||
|
||||
`workflow_run` messages include a **Jobs** field listing every job in the run as a colored diff code block (Discord):
|
||||
|
||||
```
|
||||
+ build ✅ success · 1m 23s
|
||||
deploy 🔄 running
|
||||
lint ⏳ queued
|
||||
- test ❌ failure · 0m 45s
|
||||
```
|
||||
|
||||
Each line is `{name} {emoji}{status}` plus the job duration when it has completed. Successful jobs are prefixed with `+` (green), failed/other finished jobs with `-` (red), and running/queued/pending jobs use a plain space (no color). The job name is clamped to 200 chars and the whole field to the platform field limit. Drivers without diff support (Telegram, Feishu) render the block as a single inline code span.
|
||||
@@ -10,7 +10,7 @@ WebHooker 支持 28 种 GitHub webhook 事件类型,每种都有专用的格
|
||||
| `pull_request` | PR 打开/关闭/合并/编辑 | PR 标题、分支、差异统计、标签 |
|
||||
| `issues` | 议题打开/关闭/编辑 | 议题标题、标签、指派人 |
|
||||
| `issue_comment` | 议题或 PR 的评论 | 评论内容、议题引用 |
|
||||
| `workflow_run` | CI/CD 工作流阶段更新 | 工作流状态、结论、耗时;各阶段原地更新同一条消息 |
|
||||
| `workflow_run` | CI/CD 工作流阶段更新 | 工作流状态、结论、耗时、带颜色的逐作业明细;各阶段原地更新同一条消息 |
|
||||
| `workflow_job` | CI 作业阶段更新 | 作业名、状态、结论、工作流 |
|
||||
| `status` | 提交状态更新 | 提交状态、上下文、状态值、提交链接 |
|
||||
| `deployment` | 部署已创建 | 环境、引用、任务 |
|
||||
|
||||
@@ -34,3 +34,16 @@
|
||||
## 原地更新
|
||||
|
||||
`workflow_run` 与 `check_run` 消息只发送一次,随运行进度原地编辑(queued → running → success/failure),不会重复发消息。追踪使用 KV `msg:*` 与每次运行的稳定 `updateKey`:`workflow_run` 以 workflow id 为键,`check_run` 则以 check 名 + commit SHA 为键(回退到 run id),因此每个阶段都换新 run id 的部署(例如 Cloudflare Pages)仍会编辑同一条消息。
|
||||
|
||||
## Workflow 作业
|
||||
|
||||
`workflow_run` 消息包含一个 **Jobs** 字段,以带颜色的 diff 代码块列出该次运行的全部作业(Discord):
|
||||
|
||||
```
|
||||
+ build ✅ success · 1m 23s
|
||||
deploy 🔄 running
|
||||
lint ⏳ queued
|
||||
- test ❌ failure · 0m 45s
|
||||
```
|
||||
|
||||
每行格式为 `{作业名} {emoji}{状态}`,作业完成后追加耗时。成功的作业以 `+` 前缀(绿色),失败/其他已结束的作业以 `-` 前缀(红色),运行中/排队中/待定的作业使用普通空格(无颜色)。作业名截断至 200 字符,整个字段截断至平台字段上限。不支持 diff 的驱动(Telegram、飞书)会把该代码块渲染为单个行内代码片段。
|
||||
@@ -95,6 +95,15 @@ export function formatWorkflowJob(
|
||||
);
|
||||
}
|
||||
|
||||
function jobDuration(startedAt?: string, completedAt?: string): string | undefined {
|
||||
if (!startedAt || !completedAt) return undefined;
|
||||
const secs = Math.max(0, Math.round((Date.parse(completedAt) - Date.parse(startedAt)) / 1000));
|
||||
if (!Number.isFinite(secs)) return undefined;
|
||||
const mins = Math.floor(secs / 60);
|
||||
const rem = secs % 60;
|
||||
return `${mins}m ${rem}s`;
|
||||
}
|
||||
|
||||
export function formatWorkflowRun(
|
||||
payload: Record<string, unknown>,
|
||||
repo: string | undefined,
|
||||
@@ -112,7 +121,13 @@ export function formatWorkflowRun(
|
||||
created_at?: string;
|
||||
updated_at?: string;
|
||||
elapsed_seconds?: number;
|
||||
jobs?: Array<{ name?: string; conclusion?: string }>;
|
||||
jobs?: Array<{
|
||||
name?: string;
|
||||
status?: string;
|
||||
conclusion?: string | null;
|
||||
started_at?: string;
|
||||
completed_at?: string;
|
||||
}>;
|
||||
};
|
||||
|
||||
const action = payload.action as string | undefined;
|
||||
@@ -132,13 +147,30 @@ export function formatWorkflowRun(
|
||||
|
||||
if (workflow.jobs?.length) {
|
||||
// Many-jobs workflows must stay under the Discord field value limit.
|
||||
const jobLines = workflow.jobs.map(
|
||||
(j) =>
|
||||
`${em(WORKFLOW_CONCLUSION_EMOJI[j.conclusion ?? ""] ?? "⏳")}${cap(j.name ?? "", 200)}`,
|
||||
);
|
||||
// Discord colors `diff` blocks: `+` lines green, `-` lines red, and
|
||||
// plain (space-prefixed) lines default gray/white — used for running.
|
||||
const jobLines = workflow.jobs.map((j) => {
|
||||
const status =
|
||||
j.status === "in_progress"
|
||||
? "running"
|
||||
: j.status === "queued"
|
||||
? "queued"
|
||||
: j.conclusion ?? "pending";
|
||||
const emoji = WORKFLOW_CONCLUSION_EMOJI[status] ?? "⏳";
|
||||
const marker =
|
||||
status === "success"
|
||||
? "+"
|
||||
: status === "running" || status === "queued" || status === "pending"
|
||||
? " "
|
||||
: "-";
|
||||
const done =
|
||||
status !== "running" && status !== "queued" && status !== "pending";
|
||||
const duration = done ? jobDuration(j.started_at, j.completed_at) : undefined;
|
||||
return `${marker} ${cap(j.name ?? "", 200)} ${em(emoji)}${status}${duration ? ` · ${duration}` : ""}`;
|
||||
});
|
||||
fields.push({
|
||||
name: t("fields.job"),
|
||||
value: cap(jobLines.join("\n"), MAX_FIELD_VALUE),
|
||||
value: cap(`\`\`\`diff\n${jobLines.join("\n")}\n\`\`\``, MAX_FIELD_VALUE),
|
||||
inline: false,
|
||||
});
|
||||
}
|
||||
|
||||
+36
-2
@@ -114,7 +114,7 @@ describe("message title spec", () => {
|
||||
expect(msg.title).toBe(
|
||||
"acme/widget: [CI — success](https://github.com/acme/widget/actions/runs/42)",
|
||||
);
|
||||
expect(msg.fields![1].value).toBe("✅ build");
|
||||
expect(msg.fields![1].value).toBe("```diff\n+ build ✅ success\n```");
|
||||
});
|
||||
|
||||
it("workflow_run distinguishes queued and running from pending", () => {
|
||||
@@ -154,6 +154,40 @@ describe("message title spec", () => {
|
||||
expect(running.fields![0].value).toBe("🔄 running");
|
||||
});
|
||||
|
||||
it("workflow_run jobs render as a colored diff block with durations", () => {
|
||||
const msg = formatEvent(
|
||||
route,
|
||||
event("workflow_run", {
|
||||
action: "completed",
|
||||
workflow_run: {
|
||||
name: "CI",
|
||||
conclusion: "success",
|
||||
html_url: "https://github.com/acme/widget/actions/runs/42",
|
||||
run_number: 42,
|
||||
jobs: [
|
||||
{ name: "build", status: "completed", conclusion: "success", started_at: "2024-01-01T00:00:00Z", completed_at: "2024-01-01T00:01:23Z" },
|
||||
{ name: "deploy", status: "in_progress", conclusion: null },
|
||||
{ name: "lint", status: "queued", conclusion: null },
|
||||
{ name: "test", status: "completed", conclusion: "failure", started_at: "2024-01-01T00:00:00Z", completed_at: "2024-01-01T00:00:45Z" },
|
||||
],
|
||||
},
|
||||
repository: repo,
|
||||
sender,
|
||||
}),
|
||||
);
|
||||
const jobField = msg.fields!.find((f) => f.name === "Job");
|
||||
expect(jobField!.value).toBe(
|
||||
[
|
||||
"```diff",
|
||||
"+ build ✅ success · 1m 23s",
|
||||
" deploy 🔄 running",
|
||||
" lint ⏳ queued",
|
||||
"- test ❌ failure · 0m 45s",
|
||||
"```",
|
||||
].join("\n"),
|
||||
);
|
||||
});
|
||||
|
||||
it("check_run uses status for queued and running", () => {
|
||||
const checkRun = {
|
||||
id: 42,
|
||||
@@ -430,7 +464,7 @@ describe("group emoji toggle", () => {
|
||||
false,
|
||||
);
|
||||
expect(msg.fields![0].value).toBe("failure");
|
||||
expect(msg.fields![1].value).toBe("build");
|
||||
expect(msg.fields![1].value).toBe("```diff\n- build failure\n```");
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user