From 77fb26337fe25dd76b338dcd667019c206f08716 Mon Sep 17 00:00:00 2001 From: Jack Driscoll Date: Fri, 26 Jul 2024 12:31:42 -0700 Subject: [PATCH] add check for # of files --- src/main.ts | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/main.ts b/src/main.ts index 0990c3d..4031491 100644 --- a/src/main.ts +++ b/src/main.ts @@ -4,6 +4,7 @@ import OpenAI from "openai"; import { Octokit } from "@octokit/rest"; import parseDiff, { Chunk, File } from "parse-diff"; import minimatch from "minimatch"; +import { parse } from "path"; const GITHUB_TOKEN: string = core.getInput("GITHUB_TOKEN"); const OPENAI_API_KEY: string = core.getInput("OPENAI_API_KEY"); @@ -61,7 +62,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) { @@ -137,8 +146,10 @@ async function getAIResponse(prompt: string): Promise