From 8dcc03938522ef233c95a73e38ab967c0b2229be Mon Sep 17 00:00:00 2001 From: jdriscoll98 <41447166+jdriscoll98@users.noreply.github.com> Date: Fri, 26 Jul 2024 12:00:35 -0700 Subject: [PATCH 1/9] Update main.ts Always enforce json mode --- src/main.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main.ts b/src/main.ts index 13677ae..540fe5a 100644 --- a/src/main.ts +++ b/src/main.ts @@ -127,9 +127,7 @@ async function getAIResponse(prompt: string): Promise Date: Fri, 26 Jul 2024 12:25:41 -0700 Subject: [PATCH 2/9] add check for finsih reason --- src/main.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main.ts b/src/main.ts index 540fe5a..0990c3d 100644 --- a/src/main.ts +++ b/src/main.ts @@ -136,6 +136,12 @@ async function getAIResponse(prompt: string): Promise Date: Fri, 26 Jul 2024 12:31:42 -0700 Subject: [PATCH 3/9] 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 Date: Sat, 27 Jul 2024 09:00:01 -0700 Subject: [PATCH 4/9] log the response --- src/main.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main.ts b/src/main.ts index 4031491..beef8cb 100644 --- a/src/main.ts +++ b/src/main.ts @@ -5,6 +5,7 @@ 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"); @@ -132,11 +133,12 @@ async function getAIResponse(prompt: string): Promise Date: Sat, 27 Jul 2024 09:04:28 -0700 Subject: [PATCH 5/9] Fix edge case for json comment --- src/main.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main.ts b/src/main.ts index beef8cb..43cbe46 100644 --- a/src/main.ts +++ b/src/main.ts @@ -156,7 +156,11 @@ async function getAIResponse(prompt: string): Promise Date: Mon, 29 Jul 2024 14:47:45 -0400 Subject: [PATCH 6/9] update prompt --- src/main.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main.ts b/src/main.ts index 43cbe46..60bf45b 100644 --- a/src/main.ts +++ b/src/main.ts @@ -89,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. +- Do not comment about CSS. Focus on logic, performance, code quality and nextjs best practices. - 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. From 82951185df5c717d4822714344e905bb8955336e Mon Sep 17 00:00:00 2001 From: Jack Driscoll Date: Tue, 30 Jul 2024 12:24:49 -0400 Subject: [PATCH 7/9] tweak prompt --- src/main.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.ts b/src/main.ts index 60bf45b..fc13c92 100644 --- a/src/main.ts +++ b/src/main.ts @@ -92,7 +92,7 @@ function createPrompt(file: File, chunk: Chunk, prDetails: PRDetails): string { 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. -- Do not comment about CSS. Focus on logic, performance, code quality and nextjs best practices. +- Only comment about react and nextjs best practices. IMPORTANT: Ignore CSS. - 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. From 64f567475d83055fde3e305bac2ea01ef5636e26 Mon Sep 17 00:00:00 2001 From: Jack Driscoll Date: Tue, 30 Jul 2024 12:37:40 -0400 Subject: [PATCH 8/9] tweak prompt --- src/main.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.ts b/src/main.ts index fc13c92..b3dd161 100644 --- a/src/main.ts +++ b/src/main.ts @@ -92,7 +92,7 @@ function createPrompt(file: File, chunk: Chunk, prDetails: PRDetails): string { 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 react and nextjs best practices. IMPORTANT: Ignore CSS. +- Only comment about javascript code. IMPORTANT: Do not comment on CSS or inline styles. - 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. From b44283c6edb97ac4cd1215892ec25304e1c77b0d Mon Sep 17 00:00:00 2001 From: Jack Driscoll Date: Tue, 30 Jul 2024 20:41:07 -0400 Subject: [PATCH 9/9] tweak prompt --- src/main.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.ts b/src/main.ts index b3dd161..b9a9ef6 100644 --- a/src/main.ts +++ b/src/main.ts @@ -92,7 +92,7 @@ function createPrompt(file: File, chunk: Chunk, prDetails: PRDetails): string { 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. IMPORTANT: Do not comment on CSS or inline styles. +- 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.