Skip to content

Commit

Permalink
refactor: update getPayload parameter and import usage
Browse files Browse the repository at this point in the history
Revised getPayload to require a boolean for useOpenAi and adjusted imports and payload creation.
  • Loading branch information
gentlementlegen committed Nov 10, 2024
1 parent dfd04f5 commit bf09a15
Show file tree
Hide file tree
Showing 5 changed files with 221 additions and 227 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"format:cspell": "cspell **/*",
"knip": "knip",
"prepare": "husky install",
"dev": "bun --watch src/index.ts"
"dev": "bun --watch src/index.ts",
"server": "bun --watch src/web/api/index.ts"
},
"keywords": [
"typescript",
Expand Down
21 changes: 11 additions & 10 deletions src/web/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Processor } from "../../parser/processor";
import { parseGitHubUrl } from "../../start";
import envConfigSchema, { EnvConfig } from "../../types/env-type";
import { PluginSettings, pluginSettingsSchema, SupportedEvents } from "../../types/plugin-input";
import { getPayload } from "./payload";

const baseApp = createPlugin<PluginSettings, EnvConfig, SupportedEvents>(
async (context) => {
Expand All @@ -35,16 +36,17 @@ const baseApp = createPlugin<PluginSettings, EnvConfig, SupportedEvents>(
const app = {
fetch: async (request: Request, env: object, ctx: ExecutionContext) => {
if (request.method === "POST" && new URL(request.url).pathname === "/") {
console.log("Pre-processing POST / request");
// read config file
// create JSON body from FE received body
// disable open ai routes accordingly?

// Clone the request since we need to read it twice
const clonedRequest = request.clone();
try {
const body = await clonedRequest.json();
console.log("Request body:", body);
const originalBody = await request.json();
const modifiedBody = getPayload(originalBody.ownerRepo, originalBody.issueId, originalBody.useOpenAi);
const modifiedRequest = new Request(request.url, {
method: request.method,
headers: request.headers,
body: JSON.stringify(modifiedBody),
});
return baseApp.fetch(modifiedRequest, env, ctx);
} catch (error) {
console.error(error);
return new Response("Invalid JSON", { status: 400 });
Expand All @@ -62,7 +64,7 @@ app.use(
"/*",
serveStatic({
root: "./",
rewriteRequestPath: (path) => `./dist${path}`,
rewriteRequestPath: (path) => `./src/web/dist${path}`,
})
);

Expand All @@ -89,7 +91,7 @@ app.post("/openai/*", async (c) => {

const commentsObject = comments.reduce(
(acc, comment) => {
acc[comment.id] = 0.8;
acc[comment.id] = 0.83;
return acc;
},
{} as Record<string, number>
Expand All @@ -105,7 +107,6 @@ app.get("/openai/*", () => {
});

const port = 3000;
console.log(`Server is running on port ${port}`);

export default {
fetch: app.fetch,
Expand Down
Loading

0 comments on commit bf09a15

Please sign in to comment.