From c4acd167f7a298864176518c9cd912b871287eb6 Mon Sep 17 00:00:00 2001 From: stekman08 <38240615+stekman08@users.noreply.github.com> Date: Wed, 13 Sep 2023 08:36:09 +0200 Subject: [PATCH 1/8] Add option to ignore formatting --- GPTPullRequestReview/src/index.ts | 3 ++- GPTPullRequestReview/task.json | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/GPTPullRequestReview/src/index.ts b/GPTPullRequestReview/src/index.ts index 39c3e1d..20a031c 100644 --- a/GPTPullRequestReview/src/index.ts +++ b/GPTPullRequestReview/src/index.ts @@ -17,6 +17,7 @@ async function run() { const supportSelfSignedCertificate = tl.getBoolInput('support_self_signed_certificate'); const apiKey = tl.getInput('api_key', true); const aoiEndpoint = tl.getInput('aoi_endpoint'); + const ignoreFormatting = tl.getBoolInput('ignore_formatting'); if (apiKey == undefined) { tl.setResult(tl.TaskResult.Failed, 'No Api Key provided!'); @@ -47,7 +48,7 @@ async function run() { await deleteExistingComments(httpsAgent); for (const fileName of filesNames) { - await reviewFile(targetBranch, fileName, httpsAgent, apiKey, openai, aoiEndpoint) + await reviewFile(targetBranch, fileName, httpsAgent, apiKey, openai, aoiEndpoint, ignoreFormatting) } tl.setResult(tl.TaskResult.Succeeded, "Pull Request reviewed."); diff --git a/GPTPullRequestReview/task.json b/GPTPullRequestReview/task.json index 46f1636..4884a09 100644 --- a/GPTPullRequestReview/task.json +++ b/GPTPullRequestReview/task.json @@ -54,6 +54,14 @@ "defaultValue": "false", "required": false, "helpMarkDown": "Select this option to support self-signed certificate." + }, + { + "name": "ignore_formatting", + "type": "boolean", + "label": "Ignore formatting and spacing", + "defaultValue": "false", + "required": false, + "helpMarkDown": "Select this option to ignore formatting and spacing (e.g. if you already have a .editorconfig)" } ], "execution": { From 299d4b54caae553f2988ff0d7634e976c40a3f58 Mon Sep 17 00:00:00 2001 From: stekman08 <38240615+stekman08@users.noreply.github.com> Date: Wed, 13 Sep 2023 08:36:51 +0200 Subject: [PATCH 2/8] Handle ignore formatting & improve prompt --- GPTPullRequestReview/src/review.ts | 21 ++++++++++++--------- yarn.lock | 4 ++++ 2 files changed, 16 insertions(+), 9 deletions(-) create mode 100644 yarn.lock diff --git a/GPTPullRequestReview/src/review.ts b/GPTPullRequestReview/src/review.ts index f072e48..0a340d8 100644 --- a/GPTPullRequestReview/src/review.ts +++ b/GPTPullRequestReview/src/review.ts @@ -5,20 +5,23 @@ import { addCommentToPR } from './pr'; import { Agent } from 'https'; import * as tl from "azure-pipelines-task-lib/task"; -export async function reviewFile(targetBranch: string, fileName: string, httpsAgent: Agent, apiKey: string, openai: OpenAIApi | undefined, aoiEndpoint: string | undefined) { +export async function reviewFile(targetBranch: string, fileName: string, httpsAgent: Agent, apiKey: string, openai: OpenAIApi | undefined, aoiEndpoint: string | undefined, ignoreFormatting: boolean | undefined) { console.log(`Start reviewing ${fileName} ...`); const defaultOpenAIModel = 'gpt-3.5-turbo'; const patch = await git.diff([targetBranch, '--', fileName]); + const minor = ignoreFormatting ? 'Minor (stylistic issues)' : 'Ignore styling, formatting and spaces'; + const instructions = `As a PR reviewer, your role is key for code quality. \ + Patches come with a 'Subject' as the commit message and code diffs in unidiff format. \ + Only focus on changed lines. Classify feedback as: \ + a) Critical (syntax, logic errors), \ + b) Major (inefficiency, standard violations), \ + c) ${minor}. \ + Offer actionable, specific comments in the PR review. \ + If no issues, state 'No feedback.' \ + Adhere to these guidelines to maintain code quality.`; - const instructions = `Act as a code reviewer of a Pull Request, providing feedback on possible bugs and clean code issues. - You are provided with the Pull Request changes in a patch format. - Each patch entry has the commit message in the Subject line followed by the code changes (diffs) in a unidiff format. - - As a code reviewer, your task is: - - Review only added, edited or deleted lines. - - If there's no bugs and the changes are correct, write only 'No feedback.' - - If there's bug or uncorrect code changes, don't write 'No feedback.'`; + console.log(instructions); try { let choices: any; diff --git a/yarn.lock b/yarn.lock new file mode 100644 index 0000000..fb57ccd --- /dev/null +++ b/yarn.lock @@ -0,0 +1,4 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + From 74114f92dfc025c076f47228fd3f8423d06c63db Mon Sep 17 00:00:00 2001 From: stekman08 <38240615+stekman08@users.noreply.github.com> Date: Wed, 13 Sep 2023 18:52:38 +0200 Subject: [PATCH 3/8] add EOF --- GPTPullRequestReview/src/index.ts | 2 +- GPTPullRequestReview/src/review.ts | 2 +- GPTPullRequestReview/task.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/GPTPullRequestReview/src/index.ts b/GPTPullRequestReview/src/index.ts index 20a031c..3d560ff 100644 --- a/GPTPullRequestReview/src/index.ts +++ b/GPTPullRequestReview/src/index.ts @@ -58,4 +58,4 @@ async function run() { } } -run(); \ No newline at end of file +run(); diff --git a/GPTPullRequestReview/src/review.ts b/GPTPullRequestReview/src/review.ts index 0a340d8..bd431ab 100644 --- a/GPTPullRequestReview/src/review.ts +++ b/GPTPullRequestReview/src/review.ts @@ -80,4 +80,4 @@ export async function reviewFile(targetBranch: string, fileName: string, httpsAg console.log(error.message); } } -} \ No newline at end of file +} diff --git a/GPTPullRequestReview/task.json b/GPTPullRequestReview/task.json index 4884a09..da43967 100644 --- a/GPTPullRequestReview/task.json +++ b/GPTPullRequestReview/task.json @@ -69,4 +69,4 @@ "target": "dist/index.js" } } -} \ No newline at end of file +} From eb0253a817d1b8d7f11ed4c4144d2b2b60e81c9c Mon Sep 17 00:00:00 2001 From: stekman08 <38240615+stekman08@users.noreply.github.com> Date: Wed, 13 Sep 2023 18:53:56 +0200 Subject: [PATCH 4/8] a -> an --- GPTPullRequestReview/task.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GPTPullRequestReview/task.json b/GPTPullRequestReview/task.json index da43967..133f94c 100644 --- a/GPTPullRequestReview/task.json +++ b/GPTPullRequestReview/task.json @@ -61,7 +61,7 @@ "label": "Ignore formatting and spacing", "defaultValue": "false", "required": false, - "helpMarkDown": "Select this option to ignore formatting and spacing (e.g. if you already have a .editorconfig)" + "helpMarkDown": "Select this option to ignore formatting and spacing (e.g. if you already have an .editorconfig)" } ], "execution": { From 9ccdc05d49fbb97b4fa7518d50ca37f2aa41e78d Mon Sep 17 00:00:00 2001 From: stekman08 <38240615+stekman08@users.noreply.github.com> Date: Wed, 13 Sep 2023 19:06:52 +0200 Subject: [PATCH 5/8] Refactor the instruction little more --- GPTPullRequestReview/src/review.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/GPTPullRequestReview/src/review.ts b/GPTPullRequestReview/src/review.ts index bd431ab..b591adf 100644 --- a/GPTPullRequestReview/src/review.ts +++ b/GPTPullRequestReview/src/review.ts @@ -10,13 +10,13 @@ export async function reviewFile(targetBranch: string, fileName: string, httpsAg const defaultOpenAIModel = 'gpt-3.5-turbo'; const patch = await git.diff([targetBranch, '--', fileName]); - const minor = ignoreFormatting ? 'Minor (stylistic issues)' : 'Ignore styling, formatting and spaces'; + const minor = ignoreFormatting ? 'c) Minor (stylistic issues)' : 'Note: Ignore styling, formatting and spaces'; const instructions = `As a PR reviewer, your role is key for code quality. \ - Patches come with a 'Subject' as the commit message and code diffs in unidiff format. \ + Each patch entry has the commit message in the Subject line followed by the code changes (diffs) in a unidiff format. \ Only focus on changed lines. Classify feedback as: \ - a) Critical (syntax, logic errors), \ - b) Major (inefficiency, standard violations), \ - c) ${minor}. \ + a) Critical (syntax, logic errors) \ + b) Major (inefficiency, standard violations) \ + ${minor} \ Offer actionable, specific comments in the PR review. \ If no issues, state 'No feedback.' \ Adhere to these guidelines to maintain code quality.`; From 718262d27a7deb212d77ab7620ca99bc34ca4208 Mon Sep 17 00:00:00 2001 From: stekman08 <38240615+stekman08@users.noreply.github.com> Date: Wed, 13 Sep 2023 19:14:24 +0200 Subject: [PATCH 6/8] Remove unnecessary instruction to save tokens --- GPTPullRequestReview/src/review.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/GPTPullRequestReview/src/review.ts b/GPTPullRequestReview/src/review.ts index b591adf..fdc2d99 100644 --- a/GPTPullRequestReview/src/review.ts +++ b/GPTPullRequestReview/src/review.ts @@ -18,8 +18,7 @@ export async function reviewFile(targetBranch: string, fileName: string, httpsAg b) Major (inefficiency, standard violations) \ ${minor} \ Offer actionable, specific comments in the PR review. \ - If no issues, state 'No feedback.' \ - Adhere to these guidelines to maintain code quality.`; + If no issues, state 'No feedback.'`; console.log(instructions); From 32984d1e36a2176784c5596024d90c044109b9ad Mon Sep 17 00:00:00 2001 From: stekman08 <38240615+stekman08@users.noreply.github.com> Date: Wed, 13 Sep 2023 19:17:28 +0200 Subject: [PATCH 7/8] remove console.log --- GPTPullRequestReview/src/review.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/GPTPullRequestReview/src/review.ts b/GPTPullRequestReview/src/review.ts index fdc2d99..a381eae 100644 --- a/GPTPullRequestReview/src/review.ts +++ b/GPTPullRequestReview/src/review.ts @@ -20,8 +20,6 @@ export async function reviewFile(targetBranch: string, fileName: string, httpsAg Offer actionable, specific comments in the PR review. \ If no issues, state 'No feedback.'`; - console.log(instructions); - try { let choices: any; From 2601f5d31f0ca8afe7f856c58a7e0d7e1fabfbb1 Mon Sep 17 00:00:00 2001 From: stekman08 <38240615+stekman08@users.noreply.github.com> Date: Wed, 13 Sep 2023 19:18:01 +0200 Subject: [PATCH 8/8] delete yarn.lock --- yarn.lock | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 yarn.lock diff --git a/yarn.lock b/yarn.lock deleted file mode 100644 index fb57ccd..0000000 --- a/yarn.lock +++ /dev/null @@ -1,4 +0,0 @@ -# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. -# yarn lockfile v1 - -