diff --git a/GPTPullRequestReview/src/index.ts b/GPTPullRequestReview/src/index.ts index 39c3e1d..3d560ff 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."); @@ -57,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 f072e48..a381eae 100644 --- a/GPTPullRequestReview/src/review.ts +++ b/GPTPullRequestReview/src/review.ts @@ -5,20 +5,20 @@ 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 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.'`; + 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. \ + 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) \ + ${minor} \ + Offer actionable, specific comments in the PR review. \ + If no issues, state 'No feedback.'`; try { let choices: any; @@ -77,4 +77,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 46f1636..133f94c 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 an .editorconfig)" } ], "execution": { @@ -61,4 +69,4 @@ "target": "dist/index.js" } } -} \ No newline at end of file +}