feat(github): fetch workflow_run jobs via jobs_url enrichment

The workflow_run webhook payload carries no jobs array, only jobs_url,
so the Jobs field never populated for real GitHub events. Fetch the job
list from the GitHub API once per delivery (lazy, memoized across
routes) and inject it into the payload before formatting.

- app-token.ts: shared getInstallationToken (App JWT -> installation
  token) + GITHUB_API_VERSION; check-run.ts now reuses it
- workflow-jobs.ts: getWorkflowRunJobs, App token when configured else
  unauthenticated (public repos), per_page=100, best-effort
- docs: GitHub App needs Actions: read; note API enrichment in the
  message-format and supported-events guides (en + zh)
This commit is contained in:
RhenCloud committed 2026-09-26 15:33:06 +08:00
1 parent ae36c22fda
commit 04352c3a19
12 files changed
+223 -23

No files matched your search

+22
View File
@@ -18,6 +18,7 @@ import { getDriver } from "../drivers";
import type { SendResult } from "../drivers/types";
import type { DispatchFailure, DispatchSummary } from "../queue/delivery";
import { getCheckSuiteBuildLogUrl } from "../github/check-run";
import { getWorkflowRunJobs } from "../github/workflow-jobs";
/** One dispatch attempt (route × target), collected for the group webhook log. */
interface DispatchAttempt {
@@ -163,10 +164,31 @@ export async function dispatchEvent(
}
}
let workflowJobsPromise: Promise<void> | undefined;
function ensureWorkflowJobs(): Promise<void> {
if (event.event !== "workflow_run") return Promise.resolve();
workflowJobsPromise ??= (async (): Promise<void> => {
const run = event.payload.workflow_run as
| { jobs_url?: string; jobs?: unknown[] }
| undefined;
if (!run?.jobs_url || run.jobs?.length) return;
const jobs = await getWorkflowRunJobs(
run.jobs_url,
env.GITHUB_APP_ID,
env.GITHUB_PRIVATE_KEY,
event.installationId,
);
if (jobs) run.jobs = jobs;
})();
return workflowJobsPromise;
}
async function processRoute(route: Route): Promise<void> {
const targets = route.targets && route.targets.length > 0 ? route.targets : [];
if (targets.length === 0) return;
await ensureWorkflowJobs();
const group = route.groupId ? groupById.get(route.groupId) : undefined;
const tr = trMap.get(group?.lang ?? "en")!;
const showEmoji = group?.emoji !== false;