mirror of
https://github.com/freeedcom/ai-codereviewer.git
synced 2024-11-30 07:59:03 +00:00
Merge pull request #3 from freeedcom/use-pr-title-to-increase-context-awareness
use PR title to increase the AI context awareness
This commit is contained in:
commit
4152906beb
16
src/main.ts
16
src/main.ts
@ -20,6 +20,7 @@ interface PRDetails {
|
|||||||
owner: string;
|
owner: string;
|
||||||
repo: string;
|
repo: string;
|
||||||
pull_number: number;
|
pull_number: number;
|
||||||
|
title: string;
|
||||||
description: string;
|
description: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,6 +37,7 @@ async function getPRDetails(): Promise<PRDetails> {
|
|||||||
owner: repository.owner.login,
|
owner: repository.owner.login,
|
||||||
repo: repository.name,
|
repo: repository.name,
|
||||||
pull_number: number,
|
pull_number: number,
|
||||||
|
title: prResponse.data.title ?? "",
|
||||||
description: prResponse.data.body ?? "",
|
description: prResponse.data.body ?? "",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -57,13 +59,13 @@ async function getDiff(
|
|||||||
|
|
||||||
async function analyzeCode(
|
async function analyzeCode(
|
||||||
parsedDiff: File[],
|
parsedDiff: File[],
|
||||||
prDescription: string
|
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 }> = [];
|
||||||
|
|
||||||
for (const file of parsedDiff) {
|
for (const file of parsedDiff) {
|
||||||
for (const chunk of file.chunks) {
|
for (const chunk of file.chunks) {
|
||||||
const prompt = createPrompt(file, chunk, prDescription);
|
const prompt = createPrompt(file, chunk, prDetails);
|
||||||
const aiResponse = await getAIResponse(prompt);
|
const aiResponse = await getAIResponse(prompt);
|
||||||
if (aiResponse) {
|
if (aiResponse) {
|
||||||
const comment = createComment(file, chunk, aiResponse);
|
const comment = createComment(file, chunk, aiResponse);
|
||||||
@ -76,16 +78,18 @@ async function analyzeCode(
|
|||||||
return comments;
|
return comments;
|
||||||
}
|
}
|
||||||
|
|
||||||
function createPrompt(file: File, chunk: Chunk, prDescription: string): string {
|
function createPrompt(file: File, chunk: Chunk, prDetails: PRDetails): string {
|
||||||
return `
|
return `
|
||||||
Review the following code changes in the file "${
|
Review the following code changes in the file "${
|
||||||
file.to
|
file.to
|
||||||
}" and take the pull request description into account when writing the response.
|
}" and take the pull request title and description into account when writing the response.
|
||||||
|
|
||||||
|
Title: ${prDetails.title}
|
||||||
|
|
||||||
Description:
|
Description:
|
||||||
|
|
||||||
---
|
---
|
||||||
${prDescription}
|
${prDetails.description}
|
||||||
---
|
---
|
||||||
|
|
||||||
Please provide comments and suggestions ONLY if there is something to improve, write the answer in Github markdown. If the code looks good, DO NOT return any text (leave the response completely empty)
|
Please provide comments and suggestions ONLY if there is something to improve, write the answer in Github markdown. If the code looks good, DO NOT return any text (leave the response completely empty)
|
||||||
@ -183,7 +187,7 @@ async function createReviewComment(
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
const comments = await analyzeCode(filteredDiff, prDetails.description);
|
const comments = await analyzeCode(filteredDiff, prDetails);
|
||||||
if (comments.length > 0) {
|
if (comments.length > 0) {
|
||||||
await createReviewComment(
|
await createReviewComment(
|
||||||
prDetails.owner,
|
prDetails.owner,
|
||||||
|
Loading…
Reference in New Issue
Block a user