mirror of
https://github.com/freeedcom/ai-codereviewer.git
synced 2025-06-28 20:14:14 +00:00
Merge pull request #1 from lukehollenback/custom-prompts
Added custom prompt support.
This commit is contained in:
commit
f578b5b665
2 changed files with 14 additions and 4 deletions
|
@ -15,6 +15,10 @@ inputs:
|
|||
description: "Glob patterns to exclude files from the diff analysis"
|
||||
required: false
|
||||
default: ""
|
||||
custom_prompts:
|
||||
description: "Custom commands to augment the agent's prompts with. Each line is an individual command."
|
||||
required: false
|
||||
default: ""
|
||||
runs:
|
||||
using: "node16"
|
||||
main: "dist/index.js"
|
||||
|
|
14
src/main.ts
14
src/main.ts
|
@ -58,14 +58,15 @@ async function getDiff(
|
|||
|
||||
async function analyzeCode(
|
||||
parsedDiff: File[],
|
||||
prDetails: PRDetails
|
||||
prDetails: PRDetails,
|
||||
customPrompts: string
|
||||
): Promise<Array<{ body: string; path: string; line: number }>> {
|
||||
const comments: Array<{ body: string; path: string; line: number }> = [];
|
||||
|
||||
for (const file of parsedDiff) {
|
||||
if (file.to === "/dev/null") continue; // Ignore deleted files
|
||||
for (const chunk of file.chunks) {
|
||||
const prompt = createPrompt(file, chunk, prDetails);
|
||||
const prompt = createPrompt(file, chunk, prDetails, customPrompts);
|
||||
const aiResponse = await getAIResponse(prompt);
|
||||
if (aiResponse) {
|
||||
const newComments = createComment(file, chunk, aiResponse);
|
||||
|
@ -78,7 +79,7 @@ async function analyzeCode(
|
|||
return comments;
|
||||
}
|
||||
|
||||
function createPrompt(file: File, chunk: Chunk, prDetails: PRDetails): string {
|
||||
function createPrompt(file: File, chunk: Chunk, prDetails: PRDetails, customPrompts: string): string {
|
||||
return `Your task is to review pull requests. Instructions:
|
||||
- Provide the response in following JSON format: {"reviews": [{"lineNumber": <line_number>, "reviewComment": "<review comment>"}]}
|
||||
- Do not give positive comments or compliments.
|
||||
|
@ -86,6 +87,7 @@ function createPrompt(file: File, chunk: Chunk, prDetails: PRDetails): string {
|
|||
- Write the comment in GitHub Markdown format.
|
||||
- Use the given description only for the overall context and only comment the code.
|
||||
- IMPORTANT: NEVER suggest adding comments to the code.
|
||||
${customPrompts}
|
||||
|
||||
Review the following code diff in the file "${
|
||||
file.to
|
||||
|
@ -232,7 +234,11 @@ async function main() {
|
|||
);
|
||||
});
|
||||
|
||||
const comments = await analyzeCode(filteredDiff, prDetails);
|
||||
const customPrompts = core.getMultilineInput("custom_prompts")
|
||||
.map(customPrompt => `- ${customPrompt}`)
|
||||
.join("\n")
|
||||
|
||||
const comments = await analyzeCode(filteredDiff, prDetails, customPrompts);
|
||||
if (comments.length > 0) {
|
||||
await createReviewComment(
|
||||
prDetails.owner,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue