From 500d731062d913ab446e603c53f312423ae08cb9 Mon Sep 17 00:00:00 2001 From: Alexander Van de Kleut <54694031+avandekleut@users.noreply.github.com> Date: Wed, 20 Aug 2025 15:27:15 -0400 Subject: [PATCH] add system prompt path injection --- action.yml | 4 ++++ package.json | 3 ++- src/main.ts | 26 +++++++++++++++++++++++++- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/action.yml b/action.yml index 976aed7..584c682 100644 --- a/action.yml +++ b/action.yml @@ -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" diff --git a/package.json b/package.json index 5ec57c8..48684c2 100644 --- a/package.json +++ b/package.json @@ -24,5 +24,6 @@ "@vercel/ncc": "^0.36.1", "prettier": "^2.8.6", "typescript": "^5.0.2" - } + }, + "packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e" } diff --git a/src/main.ts b/src/main.ts index 13677ae..62bd183 100644 --- a/src/main.ts +++ b/src/main.ts @@ -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": , "reviewComment": ""}]} - 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