mirror of
https://github.com/freeedcom/ai-codereviewer.git
synced 2025-04-20 17:46:47 +00:00
add check for # of files
This commit is contained in:
parent
a31be9e5d6
commit
77fb26337f
1 changed files with 14 additions and 3 deletions
17
src/main.ts
17
src/main.ts
|
@ -4,6 +4,7 @@ import OpenAI from "openai";
|
||||||
import { Octokit } from "@octokit/rest";
|
import { Octokit } from "@octokit/rest";
|
||||||
import parseDiff, { Chunk, File } from "parse-diff";
|
import parseDiff, { Chunk, File } from "parse-diff";
|
||||||
import minimatch from "minimatch";
|
import minimatch from "minimatch";
|
||||||
|
import { parse } from "path";
|
||||||
|
|
||||||
const GITHUB_TOKEN: string = core.getInput("GITHUB_TOKEN");
|
const GITHUB_TOKEN: string = core.getInput("GITHUB_TOKEN");
|
||||||
const OPENAI_API_KEY: string = core.getInput("OPENAI_API_KEY");
|
const OPENAI_API_KEY: string = core.getInput("OPENAI_API_KEY");
|
||||||
|
@ -61,7 +62,15 @@ async function analyzeCode(
|
||||||
prDetails: PRDetails
|
prDetails: PRDetails
|
||||||
): Promise<Array<{ body: string; path: string; line: number }>> {
|
): Promise<Array<{ body: string; path: string; line: number }>> {
|
||||||
const comments: Array<{ body: string; path: string; line: number }> = [];
|
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) {
|
for (const file of parsedDiff) {
|
||||||
if (file.to === "/dev/null") continue; // Ignore deleted files
|
if (file.to === "/dev/null") continue; // Ignore deleted files
|
||||||
for (const chunk of file.chunks) {
|
for (const chunk of file.chunks) {
|
||||||
|
@ -137,8 +146,10 @@ async function getAIResponse(prompt: string): Promise<Array<{
|
||||||
});
|
});
|
||||||
|
|
||||||
const finish_response = response.choices[0].finish_reason;
|
const finish_response = response.choices[0].finish_reason;
|
||||||
if (finish_response === 'length') {
|
if (finish_response === "length") {
|
||||||
console.log('The maximum context length has been exceeded. Please reduce the length of the code snippets.');
|
console.log(
|
||||||
|
"The maximum context length has been exceeded. Please reduce the length of the code snippets."
|
||||||
|
);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue