From df8bc59c223374222dd80ea4a0442447cce8358c Mon Sep 17 00:00:00 2001 From: whilefoo Date: Sun, 19 Nov 2023 23:47:21 +0100 Subject: [PATCH] fix: initialize only once --- src/bindings/event.ts | 8 ++++---- src/handlers/processors.ts | 4 +--- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/bindings/event.ts b/src/bindings/event.ts index 73a2ab637..e09c6d186 100644 --- a/src/bindings/event.ts +++ b/src/bindings/event.ts @@ -33,11 +33,11 @@ type AllHandlers = PreActionHandler | MainActionHandler | PostActionHandler; const validatePayload = ajv.compile(PayloadSchema); -export async function bindEvents(eventContext: ProbotContext) { - const runtime = Runtime.getState(); - runtime.adapters = createAdapters(); - runtime.logger = runtime.adapters.supabase.logs; +const runtime = Runtime.getState(); +runtime.adapters = createAdapters(); +runtime.logger = runtime.adapters.supabase.logs; +export async function bindEvents(eventContext: ProbotContext) { const payload = eventContext.payload as Payload; const eventName = payload?.action ? `${eventContext.name}.${payload?.action}` : eventContext.name; // some events wont have actions as this grows diff --git a/src/handlers/processors.ts b/src/handlers/processors.ts index 0b15f7284..52c002804 100644 --- a/src/handlers/processors.ts +++ b/src/handlers/processors.ts @@ -19,8 +19,6 @@ import Runtime from "../bindings/bot-runtime"; * TODO: all MUST receive `Context` as the only parameter */ -const runtime = Runtime.getState(); - export const processors: Record = { [GitHubEvent.ISSUES_OPENED]: { pre: [], @@ -29,7 +27,7 @@ export const processors: Record = { }, [GitHubEvent.ISSUES_REOPENED]: { pre: [], - action: [async () => runtime.logger.debug(null, "TODO: replace ISSUES_REOPENED handler")], + action: [async () => Runtime.getState().logger.debug(null, "TODO: replace ISSUES_REOPENED handler")], post: [], }, [GitHubEvent.ISSUES_LABELED]: {