mirror of
https://github.com/Elysola/WebHooker.git
synced 2026-11-20 17:13:49 +00:00
fix(dispatch): hoist workflow jobs memoization above route loop
The workflow_jobsPromise declaration sat after the route dispatch loop, so processRoute hit a temporal dead zone ReferenceError for workflow_run events; Promise.allSettled swallowed it and no message was sent. Move the memoized enrichment above the loop and add a regression test that dispatches a workflow_run event with jobs enrichment.
This commit is contained in:
2 files changed
+79
-17
No files matched your search
+18
-17
@@ -68,6 +68,24 @@ export async function dispatchEvent(
|
||||
|
||||
const attempts: DispatchAttempt[] = [];
|
||||
const sendLogs: SendRecord[] = [];
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
const tasks: Promise<void>[] = [];
|
||||
for (const route of config.routes) {
|
||||
if (!accepted(route)) continue;
|
||||
@@ -164,23 +182,6 @@ 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;
|
||||
|
||||
Reference in new issue
Block a user