Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Feature to Ignore Formatting and Update Instruction Prompt #39

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions GPTPullRequestReview/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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!');
Expand Down Expand Up @@ -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.");
Expand All @@ -57,4 +58,4 @@ async function run() {
}
}

run();
run();
22 changes: 11 additions & 11 deletions GPTPullRequestReview/src/review.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -77,4 +77,4 @@ export async function reviewFile(targetBranch: string, fileName: string, httpsAg
console.log(error.message);
}
}
}
}
10 changes: 9 additions & 1 deletion GPTPullRequestReview/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,19 @@
"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": {
"Node10": {
"target": "dist/index.js"
}
}
}
}