This commit is contained in:
Luke Hollenback 2024-04-02 11:55:35 -06:00 committed by GitHub
commit d85e6358e4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 14 additions and 4 deletions

View file

@ -15,6 +15,10 @@ inputs:
description: "Glob patterns to exclude files from the diff analysis" description: "Glob patterns to exclude files from the diff analysis"
required: false required: false
default: "" default: ""
custom_prompts:
description: "Custom commands to augment the agent's prompts with. Each line is an individual command."
required: false
default: ""
runs: runs:
using: "node16" using: "node16"
main: "dist/index.js" main: "dist/index.js"

View file

@ -58,14 +58,15 @@ async function getDiff(
async function analyzeCode( async function analyzeCode(
parsedDiff: File[], parsedDiff: File[],
prDetails: PRDetails prDetails: PRDetails,
customPrompts: 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) {
if (file.to === "/dev/null") continue; // Ignore deleted files if (file.to === "/dev/null") continue; // Ignore deleted files
for (const chunk of file.chunks) { for (const chunk of file.chunks) {
const prompt = createPrompt(file, chunk, prDetails); const prompt = createPrompt(file, chunk, prDetails, customPrompts);
const aiResponse = await getAIResponse(prompt); const aiResponse = await getAIResponse(prompt);
if (aiResponse) { if (aiResponse) {
const newComments = createComment(file, chunk, aiResponse); const newComments = createComment(file, chunk, aiResponse);
@ -78,7 +79,7 @@ async function analyzeCode(
return comments; 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: return `Your task is to review pull requests. Instructions:
- Provide the response in following JSON format: {"reviews": [{"lineNumber": <line_number>, "reviewComment": "<review comment>"}]} - Provide the response in following JSON format: {"reviews": [{"lineNumber": <line_number>, "reviewComment": "<review comment>"}]}
- Do not give positive comments or compliments. - 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. - Write the comment in GitHub Markdown format.
- Use the given description only for the overall context and only comment the code. - Use the given description only for the overall context and only comment the code.
- IMPORTANT: NEVER suggest adding comments to the code. - IMPORTANT: NEVER suggest adding comments to the code.
${customPrompts}
Review the following code diff in the file "${ Review the following code diff in the file "${
file.to 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) { if (comments.length > 0) {
await createReviewComment( await createReviewComment(
prDetails.owner, prDetails.owner,