diff --git a/src/main.ts b/src/main.ts index 13677ae4..b9a9ef6c 100644 --- a/src/main.ts +++ b/src/main.ts @@ -4,6 +4,8 @@ import OpenAI from "openai"; import { Octokit } from "@octokit/rest"; import parseDiff, { Chunk, File } from "parse-diff"; import minimatch from "minimatch"; +import { parse } from "path"; +import { APIPromise } from "openai/core"; const GITHUB_TOKEN: string = core.getInput("GITHUB_TOKEN"); const OPENAI_API_KEY: string = core.getInput("OPENAI_API_KEY"); @@ -61,7 +63,15 @@ async function analyzeCode( prDetails: PRDetails ): Promise> { const comments: Array<{ body: string; path: string; line: number }> = []; - + if (parsedDiff.length > 10) { + // Too many files to review + comments.push({ + body: "This pull request has too many files to review (more than 10). Please split it into smaller pull requests. This is for cost purposes.", + path: "", + line: 0, + }); + return comments; + } for (const file of parsedDiff) { if (file.to === "/dev/null") continue; // Ignore deleted files for (const chunk of file.chunks) { @@ -79,9 +89,10 @@ async function analyzeCode( } function createPrompt(file: File, chunk: Chunk, prDetails: PRDetails): string { - return `Your task is to review pull requests. Instructions: + return `You are an expert Nextjs developer. Your task is to review pull requests. Instructions: - Provide the response in following JSON format: {"reviews": [{"lineNumber": , "reviewComment": ""}]} - Do not give positive comments or compliments. +- Only comment about javascript code. Do not comment about css classes. - Provide comments and suggestions ONLY if there is something to improve, otherwise "reviews" should be an empty array. - Write the comment in GitHub Markdown format. - Use the given description only for the overall context and only comment the code. @@ -123,13 +134,12 @@ async function getAIResponse(prompt: string): Promise