Skip to content

Commit

Permalink
fix: add useCache option to payload processing
Browse files Browse the repository at this point in the history
Extended payload generation function to support useCache flag.
  • Loading branch information
gentlementlegen committed Nov 19, 2024
1 parent 1944449 commit b01dc77
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
11 changes: 8 additions & 3 deletions src/web/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import { IssueActivityCache } from "../db/issue-activity-cache";

const baseApp = createPlugin<PluginSettings, EnvConfig, SupportedEvents>(
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);
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/web/api/payload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions src/web/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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", {
Expand Down

0 comments on commit b01dc77

Please sign in to comment.