mirror of
https://github.com/Elysola/WebHooker.git
synced 2026-11-21 01:23:40 +00:00
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:
12 files changed
+223
-23
No files matched your search
@@ -0,0 +1,35 @@
|
||||
import { createAppJwt } from "./oauth";
|
||||
|
||||
export const GITHUB_API_VERSION = "2022-11-28";
|
||||
|
||||
/**
|
||||
* Mint a short-lived installation access token for a GitHub App installation.
|
||||
* Returns undefined when the App credentials are missing or the exchange
|
||||
* fails. Best-effort: callers must not depend on it.
|
||||
*/
|
||||
export async function getInstallationToken(
|
||||
appId: string | undefined,
|
||||
privateKey: string | undefined,
|
||||
installationId: number | undefined,
|
||||
): Promise<string | undefined> {
|
||||
if (!appId || !privateKey || !installationId) return undefined;
|
||||
try {
|
||||
const jwt = await createAppJwt(appId, privateKey);
|
||||
const res = await fetch(
|
||||
`https://api.github.com/app/installations/${installationId}/access_tokens`,
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
Authorization: `Bearer ${jwt}`,
|
||||
Accept: "application/vnd.github+json",
|
||||
"X-GitHub-Api-Version": GITHUB_API_VERSION,
|
||||
},
|
||||
},
|
||||
);
|
||||
if (!res.ok) return undefined;
|
||||
const { token } = (await res.json()) as { token?: string };
|
||||
return token ?? undefined;
|
||||
} catch {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user