From b01dc778efb61b0c0514be2f5a16577d6a69ee95 Mon Sep 17 00:00:00 2001 From: gentlementlegen Date: Tue, 19 Nov 2024 22:31:47 +0900 Subject: [PATCH] fix: add useCache option to payload processing Extended payload generation function to support useCache flag. --- src/web/api/index.ts | 11 ++++++++--- src/web/api/payload.ts | 4 ++-- src/web/main.tsx | 2 ++ 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/web/api/index.ts b/src/web/api/index.ts index 57d9feb7..383eab95 100644 --- a/src/web/api/index.ts +++ b/src/web/api/index.ts @@ -13,9 +13,9 @@ import { IssueActivityCache } from "../db/issue-activity-cache"; const baseApp = createPlugin( async (context) => { - const { payload } = context; + const { payload, env } = context; const issue = parseGitHubUrl(payload.issue.html_url); - const activity = new IssueActivityCache(context, issue, true); + const activity = new IssueActivityCache(context, issue, "USE_CACHE" in env); await activity.init(); const processor = new Processor(context); await processor.run(activity); @@ -37,7 +37,12 @@ const app = { if (request.method === "POST" && new URL(request.url).pathname === "/") { try { const originalBody = await request.json(); - const modifiedBody = await getPayload(originalBody.ownerRepo, originalBody.issueId, originalBody.useOpenAi); + const modifiedBody = await getPayload( + originalBody.ownerRepo, + originalBody.issueId, + originalBody.useOpenAi, + originalBody.useCache + ); const modifiedRequest = new Request(request.url, { method: request.method, headers: request.headers, diff --git a/src/web/api/payload.ts b/src/web/api/payload.ts index c3d2f70c..d3ec9608 100644 --- a/src/web/api/payload.ts +++ b/src/web/api/payload.ts @@ -2,7 +2,7 @@ import { promises as fs } from "node:fs"; import path from "node:path"; import YAML from "yaml"; -export async function getPayload(ownerRepo: string, issueId: number, useOpenAi: boolean) { +export async function getPayload(ownerRepo: string, issueId: number, useOpenAi: boolean, useCache: boolean) { const filePath = path.resolve(__dirname, "../.ubiquity-os.config.yml"); const fileContent = await fs.readFile(filePath, "utf8"); const cfgFile = YAML.parse(fileContent); @@ -19,7 +19,7 @@ export async function getPayload(ownerRepo: string, issueId: number, useOpenAi: signature: "", eventName: "issues.closed", action: "closed", - env: process.env, + env: { ...process.env, ...(useCache && { USE_CACHE: useCache }) }, settings: { ...cfgFile, evmPrivateEncrypted: cfgFile.evmPrivateEncrypted ?? process.env.EVM_PRIVATE_ENCRYPTED, diff --git a/src/web/main.tsx b/src/web/main.tsx index dbd23f45..f491f9cf 100644 --- a/src/web/main.tsx +++ b/src/web/main.tsx @@ -13,10 +13,12 @@ function Form() { const ownerRepo = `${event.target?.owner.value}/${event.target?.repo.value}`; const issueId = event.target?.issue_id.value; const useOpenAi = event.target?.openai.checked; + const useCache = event.target?.cache.checked; const payload = { ownerRepo, issueId, useOpenAi, + useCache, }; try { const result = await fetch("http://localhost:3000", {