mirror of
https://github.com/freeedcom/ai-codereviewer.git
synced 2024-11-23 04:29:03 +00:00
Merge pull request #2 from freeedcom/pass-pr-description-for-the-context
pass pr description for the context
This commit is contained in:
commit
f3bfd9a657
26
src/main.ts
26
src/main.ts
@ -20,16 +20,23 @@ interface PRDetails {
|
|||||||
owner: string;
|
owner: string;
|
||||||
repo: string;
|
repo: string;
|
||||||
pull_number: number;
|
pull_number: number;
|
||||||
|
description: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getPRDetails(): Promise<PRDetails> {
|
async function getPRDetails(): Promise<PRDetails> {
|
||||||
const { repository, number } = JSON.parse(
|
const { repository, number } = JSON.parse(
|
||||||
readFileSync(process.env.GITHUB_EVENT_PATH || "", "utf8")
|
readFileSync(process.env.GITHUB_EVENT_PATH || "", "utf8")
|
||||||
);
|
);
|
||||||
|
const prResponse = await octokit.pulls.get({
|
||||||
|
owner: repository.owner.login,
|
||||||
|
repo: repository.name,
|
||||||
|
pull_number: number,
|
||||||
|
});
|
||||||
return {
|
return {
|
||||||
owner: repository.owner.login,
|
owner: repository.owner.login,
|
||||||
repo: repository.name,
|
repo: repository.name,
|
||||||
pull_number: number,
|
pull_number: number,
|
||||||
|
description: prResponse.data.body ?? "",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,13 +56,14 @@ async function getDiff(
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function analyzeCode(
|
async function analyzeCode(
|
||||||
parsedDiff: File[]
|
parsedDiff: File[],
|
||||||
|
prDescription: string
|
||||||
): 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);
|
const prompt = createPrompt(file, chunk, prDescription);
|
||||||
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);
|
||||||
@ -68,11 +76,19 @@ async function analyzeCode(
|
|||||||
return comments;
|
return comments;
|
||||||
}
|
}
|
||||||
|
|
||||||
function createPrompt(file: File, chunk: Chunk): string {
|
function createPrompt(file: File, chunk: Chunk, prDescription: string): string {
|
||||||
return `
|
return `
|
||||||
Review the following code changes in the file "${
|
Review the following code changes in the file "${
|
||||||
file.to
|
file.to
|
||||||
}" and 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)
|
}" and take the pull request description into account when writing the response.
|
||||||
|
|
||||||
|
Description:
|
||||||
|
|
||||||
|
---
|
||||||
|
${prDescription}
|
||||||
|
---
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
${chunk.content}
|
${chunk.content}
|
||||||
${chunk.changes
|
${chunk.changes
|
||||||
@ -167,7 +183,7 @@ async function createReviewComment(
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
const comments = await analyzeCode(filteredDiff);
|
const comments = await analyzeCode(filteredDiff, prDetails.description);
|
||||||
if (comments.length > 0) {
|
if (comments.length > 0) {
|
||||||
await createReviewComment(
|
await createReviewComment(
|
||||||
prDetails.owner,
|
prDetails.owner,
|
||||||
|
Loading…
Reference in New Issue
Block a user