add system prompt path injection

This commit is contained in:
Alexander Van de Kleut 2025-08-20 15:27:15 -04:00
commit 500d731062
3 changed files with 31 additions and 2 deletions

View file

@ -15,6 +15,10 @@ inputs:
description: "Glob patterns to exclude files from the diff analysis"
required: false
default: ""
system_prompt_path:
description: "Path to a file in the repository containing additional system prompt instructions"
required: false
default: ""
runs:
using: "node16"
main: "dist/index.js"

View file

@ -24,5 +24,6 @@
"@vercel/ncc": "^0.36.1",
"prettier": "^2.8.6",
"typescript": "^5.0.2"
}
},
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
}

View file

@ -1,4 +1,5 @@
import { readFileSync } from "fs";
import { existsSync } from "fs";
import * as core from "@actions/core";
import OpenAI from "openai";
import { Octokit } from "@octokit/rest";
@ -8,6 +9,7 @@ import minimatch from "minimatch";
const GITHUB_TOKEN: string = core.getInput("GITHUB_TOKEN");
const OPENAI_API_KEY: string = core.getInput("OPENAI_API_KEY");
const OPENAI_API_MODEL: string = core.getInput("OPENAI_API_MODEL");
const SYSTEM_PROMPT_PATH: string = core.getInput("system_prompt_path");
const octokit = new Octokit({ auth: GITHUB_TOKEN });
@ -56,6 +58,25 @@ async function getDiff(
return response.data;
}
function readSystemPrompt(): string {
if (!SYSTEM_PROMPT_PATH) {
return "";
}
try {
if (existsSync(SYSTEM_PROMPT_PATH)) {
const systemPrompt = readFileSync(SYSTEM_PROMPT_PATH, "utf8");
return systemPrompt.trim();
} else {
console.warn(`System prompt file not found: ${SYSTEM_PROMPT_PATH}`);
return "";
}
} catch (error) {
console.error(`Error reading system prompt file ${SYSTEM_PROMPT_PATH}:`, error);
return "";
}
}
async function analyzeCode(
parsedDiff: File[],
prDetails: PRDetails
@ -79,13 +100,16 @@ async function analyzeCode(
}
function createPrompt(file: File, chunk: Chunk, prDetails: PRDetails): string {
const systemPrompt = readSystemPrompt();
const additionalInstructions = systemPrompt ? `\n\nAdditional instructions from repository:\n${systemPrompt}\n` : "";
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.
- Provide comments and suggestions ONLY if there is something to improve, otherwise "reviews" should be an empty array.
- 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.
- IMPORTANT: NEVER suggest adding comments to the code.${additionalInstructions}
Review the following code diff in the file "${
file.to