From 977935fd5eb1da6b0c2b5b39b9cd4b43e78df22e Mon Sep 17 00:00:00 2001 From: Will Hohyon Ryu Date: Thu, 7 Mar 2024 19:06:50 -0800 Subject: [PATCH] chore: fix formatting issues in main.ts file --- src/main.ts | 107 ++++++++++++++++++++++++++-------------------------- 1 file changed, 53 insertions(+), 54 deletions(-) diff --git a/src/main.ts b/src/main.ts index 60e1a83..721550c 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,8 +1,8 @@ -import { readFileSync } from "fs"; +import {readFileSync} from "fs"; import * as core from "@actions/core"; import OpenAI from "openai"; -import { Octokit } from "@octokit/rest"; -import parseDiff, { Chunk, File } from "parse-diff"; +import {Octokit} from "@octokit/rest"; +import parseDiff, {Chunk, File} from "parse-diff"; import minimatch from "minimatch"; import {parseJsonForChatGPTResponse} from "./parseJsonForChatGPTResponse"; @@ -10,11 +10,11 @@ const GITHUB_TOKEN: string = core.getInput("GITHUB_TOKEN"); const OPENAI_API_KEY: string = core.getInput("OPENAI_API_KEY"); const OPENAI_API_MODEL: string = core.getInput("OPENAI_API_MODEL"); -const octokit = new Octokit({ auth: GITHUB_TOKEN }); +const octokit = new Octokit({auth: GITHUB_TOKEN}); const openai = new OpenAI({ - apiKey: OPENAI_API_KEY, -}); + apiKey: OPENAI_API_KEY, + }); interface PRDetails { owner: string; @@ -25,14 +25,14 @@ interface PRDetails { } async function getPRDetails(): Promise { - const { repository, number } = JSON.parse( + const {repository, number} = JSON.parse( readFileSync(process.env.GITHUB_EVENT_PATH || "", "utf8") ); const prResponse = await octokit.pulls.get({ - owner: repository.owner.login, - repo: repository.name, - pull_number: number, - }); + owner: repository.owner.login, + repo: repository.name, + pull_number: number, + }); return { owner: repository.owner.login, repo: repository.name, @@ -48,11 +48,11 @@ async function getDiff( pull_number: number ): Promise { const response = await octokit.pulls.get({ - owner, - repo, - pull_number, - mediaType: { format: "diff" }, - }); + owner, + repo, + pull_number, + mediaType: {format: "diff"}, + }); // @ts-expect-error - response.data is a string return response.data; } @@ -108,9 +108,9 @@ Git diff to review: \`\`\`diff ${chunk.content} ${chunk.changes - // @ts-expect-error - ln and ln2 exists where needed - .map((c) => `${c.ln ? c.ln : c.ln2} ${c.content}`) - .join("\n")} + // @ts-expect-error - ln and ln2 exists where needed + .map((c) => `${c.ln ? c.ln : c.ln2} ${c.content}`) + .join("\n")} \`\`\` `; } @@ -128,27 +128,26 @@ async function getAIResponse(prompt: string): Promise ): Promise { await octokit.pulls.createReview({ - owner, - repo, - pull_number, - comments, - event: "COMMENT", - }); + owner, + repo, + pull_number, + comments, + event: "COMMENT", + }); } async function main() { @@ -204,14 +203,14 @@ async function main() { const newHeadSha = eventData.after; const response = await octokit.repos.compareCommits({ - headers: { - accept: "application/vnd.github.v3.diff", - }, - owner: prDetails.owner, - repo: prDetails.repo, - base: newBaseSha, - head: newHeadSha, - }); + headers: { + accept: "application/vnd.github.v3.diff", + }, + owner: prDetails.owner, + repo: prDetails.repo, + base: newBaseSha, + head: newHeadSha, + }); diff = String(response.data); } else { @@ -233,7 +232,7 @@ async function main() { const filteredDiff = parsedDiff.filter((file) => { return !excludePatterns.some((pattern) => - minimatch(file.to ?? "", pattern) + minimatch(file.to ?? "", pattern) ); });