mirror of
https://github.com/kekxv/AiReviewPR.git
synced 2025-02-11 22:41:50 +01:00
update input language
This commit is contained in:
12
README.md
12
README.md
@@ -43,7 +43,7 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
- name: Review code
|
- name: Review code
|
||||||
uses: kekxv/AiReviewPR@v0.0.2
|
uses: kekxv/AiReviewPR@v0.0.3
|
||||||
with:
|
with:
|
||||||
model: 'gemma2:2b'
|
model: 'gemma2:2b'
|
||||||
host: ${{ vars.OLLAMA_HOST }}
|
host: ${{ vars.OLLAMA_HOST }}
|
||||||
@@ -118,6 +118,11 @@ result:
|
|||||||
- **必需**: 否
|
- **必需**: 否
|
||||||
- **默认值**: `" "`(默认为空,不传递文件)
|
- **默认值**: `" "`(默认为空,不传递文件)
|
||||||
|
|
||||||
|
12. **PROMPT_GENRE**:
|
||||||
|
- **描述**: 提示模式类型。
|
||||||
|
- **必需**: 否
|
||||||
|
- **默认值**: `" "`(默认为空)
|
||||||
|
|
||||||
|
|
||||||
### Input Parameters
|
### Input Parameters
|
||||||
|
|
||||||
@@ -170,3 +175,8 @@ result:
|
|||||||
- **Description**: A comma-separated list of files to exclude from the review.
|
- **Description**: A comma-separated list of files to exclude from the review.
|
||||||
- **Required**: No
|
- **Required**: No
|
||||||
- **Default Value**: `" "` (empty by default, no files passed)
|
- **Default Value**: `" "` (empty by default, no files passed)
|
||||||
|
|
||||||
|
12. **PROMPT_GENRE**:
|
||||||
|
- **描述**: prompt genre
|
||||||
|
- **必需**: No
|
||||||
|
- **默认值**: `" "` (empty by default)
|
||||||
|
|||||||
29
action.yml
29
action.yml
@@ -13,8 +13,11 @@ inputs:
|
|||||||
description: 'github event pull_request number'
|
description: 'github event pull_request number'
|
||||||
default: ${{ github.event.pull_request.number }}
|
default: ${{ github.event.pull_request.number }}
|
||||||
CHINESE:
|
CHINESE:
|
||||||
|
description: 'use chines 作废'
|
||||||
|
default: ""
|
||||||
|
LANGUAGE:
|
||||||
description: 'use chines'
|
description: 'use chines'
|
||||||
default: "true"
|
default: "Chinese"
|
||||||
token:
|
token:
|
||||||
description: >
|
description: >
|
||||||
Personal access token (PAT) used to fetch the repository. The PAT is configured
|
Personal access token (PAT) used to fetch the repository. The PAT is configured
|
||||||
@@ -36,29 +39,13 @@ inputs:
|
|||||||
description: 'ollama host'
|
description: 'ollama host'
|
||||||
required: true
|
required: true
|
||||||
default: 'http://127.0.0.1:11434'
|
default: 'http://127.0.0.1:11434'
|
||||||
|
PROMPT_GENRE:
|
||||||
|
description: 'prompt genre'
|
||||||
|
default: ' '
|
||||||
reviewers_prompt:
|
reviewers_prompt:
|
||||||
description: 'ollama system prompt'
|
description: 'ollama system prompt'
|
||||||
required: false
|
required: false
|
||||||
default: >
|
default: ""
|
||||||
You are an expert developer, your task is to review a set of pull requests.
|
|
||||||
You are given a list of filenames and their partial contents, but note that you might not have the full context of the code.
|
|
||||||
|
|
||||||
Only review lines of code which have been changed (added or removed) in the pull request. The code looks similar to the output of a git diff command. Lines which have been removed are prefixed with a minus (-) and lines which have been added are prefixed with a plus (+). Other lines are added to provide context but should be ignored in the review.
|
|
||||||
|
|
||||||
Begin your review by evaluating the changed code using a risk score similar to a LOGAF score but measured from 1 to 5, where 1 is the lowest risk to the code base if the code is merged and 5 is the highest risk which would likely break something or be unsafe.
|
|
||||||
|
|
||||||
In your feedback, focus on highlighting potential bugs, improving readability if it is a problem, making code cleaner, and maximising the performance of the programming language. Flag any API keys or secrets present in the code in plain text immediately as highest risk. Rate the changes based on SOLID principles if applicable.
|
|
||||||
|
|
||||||
Do not comment on breaking functions down into smaller, more manageable functions unless it is a huge problem. Also be aware that there will be libraries and techniques used which you are not familiar with, so do not comment on those unless you are confident that there is a problem.
|
|
||||||
|
|
||||||
Use markdown formatting for the feedback details. Also do not include the filename or risk level in the feedback details.
|
|
||||||
|
|
||||||
Ensure the feedback details are brief, concise, accurate. If there are multiple similar issues, only comment on the most critical.
|
|
||||||
|
|
||||||
Include brief example code snippets in the feedback details for your suggested changes when you're confident your suggestions are improvements. Use the same programming language as the file under review.
|
|
||||||
If there are multiple improvements you suggest in the feedback details, use an ordered list to indicate the priority of the changes.
|
|
||||||
|
|
||||||
Please respond without using "```markdown"
|
|
||||||
ai_token:
|
ai_token:
|
||||||
description: 'ai token'
|
description: 'ai token'
|
||||||
required: false
|
required: false
|
||||||
|
|||||||
17
dist/index.js
vendored
17
dist/index.js
vendored
@@ -3,10 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|||||||
const node_child_process_1 = require("node:child_process");
|
const node_child_process_1 = require("node:child_process");
|
||||||
const utils_1 = require("./utils");
|
const utils_1 = require("./utils");
|
||||||
const prompt_1 = require("./prompt");
|
const prompt_1 = require("./prompt");
|
||||||
const useChinese = (process.env.INPUT_CHINESE || "true").toLowerCase() != "false"; // use chinese
|
let useChinese = (process.env.INPUT_CHINESE || "true").toLowerCase() != "false"; // use chinese
|
||||||
|
const language = !process.env.INPUT_CHINESE ? (process.env.INPUT_LANGUAGE || "Chinese") : (useChinese ? "Chinese" : "English");
|
||||||
|
const prompt_genre = (process.env.INPUT_PROMPT_GENRE || "");
|
||||||
|
const reviewers_prompt = (process.env.INPUT_REVIEWERS_PROMPT || "");
|
||||||
|
useChinese = language.toLowerCase() === "chinese";
|
||||||
const include_files = (0, utils_1.split_message)(process.env.INPUT_INCLUDE_FILES || "");
|
const include_files = (0, utils_1.split_message)(process.env.INPUT_INCLUDE_FILES || "");
|
||||||
const exclude_files = (0, utils_1.split_message)(process.env.INPUT_EXCLUDE_FILES || "");
|
const exclude_files = (0, utils_1.split_message)(process.env.INPUT_EXCLUDE_FILES || "");
|
||||||
const system_prompt = (0, prompt_1.take_system_prompt)(useChinese);
|
const system_prompt = reviewers_prompt || (0, prompt_1.take_system_prompt)(prompt_genre, language);
|
||||||
// 获取输入参数
|
// 获取输入参数
|
||||||
const url = process.env.INPUT_HOST; // INPUT_HOST 是从 action.yml 中定义的输入
|
const url = process.env.INPUT_HOST; // INPUT_HOST 是从 action.yml 中定义的输入
|
||||||
if (!url) {
|
if (!url) {
|
||||||
@@ -85,7 +89,14 @@ async function aiCheckDiffContext() {
|
|||||||
throw "ollama error";
|
throw "ollama error";
|
||||||
}
|
}
|
||||||
let Review = useChinese ? "审核结果" : "Review";
|
let Review = useChinese ? "审核结果" : "Review";
|
||||||
let comments = `# ${Review} \r\n${process.env.GITHUB_SERVER_URL}/${process.env.INPUT_REPOSITORY}/src/commit/${process.env.GITHUB_SHA}/${files[key]} \r\n\r\n\r\n${response.response}`;
|
let commit = response.response;
|
||||||
|
if (commit.indexOf("```markdown") === 0) {
|
||||||
|
commit = commit.substring("```markdown".length);
|
||||||
|
if (commit.lastIndexOf("```") === commit.length - 3) {
|
||||||
|
commit = commit.substring(0, commit.length - 3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let comments = `# ${Review} \r\n${process.env.GITHUB_SERVER_URL}/${process.env.INPUT_REPOSITORY}/src/commit/${process.env.GITHUB_SHA}/${files[key]} \r\n\r\n\r\n${commit}`;
|
||||||
let resp = await pushComments(comments);
|
let resp = await pushComments(comments);
|
||||||
if (!resp.id) {
|
if (!resp.id) {
|
||||||
// noinspection ExceptionCaughtLocallyJS
|
// noinspection ExceptionCaughtLocallyJS
|
||||||
|
|||||||
30
dist/prompt.js
vendored
30
dist/prompt.js
vendored
@@ -1,7 +1,27 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.take_system_prompt = void 0;
|
exports.take_system_prompt = void 0;
|
||||||
function take_system_prompt(useChinese) {
|
function system_prompt_main(language) {
|
||||||
|
language = language || "Chinese";
|
||||||
|
return `
|
||||||
|
Please note that you are a development expert, and your task is to review a set of pull requests. Below are the review steps you need to follow.
|
||||||
|
|
||||||
|
You will receive a list of filenames and their partial content, but be aware that you may not have the complete code context. Please only review the lines of code that have changed in the pull requests (added or deleted lines). The code is similar to the output of the git diff command. Deleted lines are prefixed with a minus sign "-", and added lines are prefixed with a plus sign "+". Other lines provide context but should be ignored for the review and should not be commented on.
|
||||||
|
|
||||||
|
When assessing the changed code, please use a risk scoring system similar to the LOGAF score, with a range from 1 to 5, where 1 indicates the lowest risk of merging the code into the codebase and 5 indicates the highest risk that may result in certain functionality being broken or unsafe.
|
||||||
|
|
||||||
|
In your feedback, highlight potential bugs, suggest ways to make the code more concise, and maximize the performance of the programming language. Immediately flag any API keys or secrets that exist in plaintext as high risk, provide a score, and output the API keys or secrets. If applicable, score the changes based on SOLID principles.
|
||||||
|
|
||||||
|
Please do not comment on splitting functions into smaller, more manageable ones unless it is a significant issue. Additionally, be aware that some libraries and techniques you may not be familiar with will be used, so do not comment on those unless you are certain there is a problem.
|
||||||
|
|
||||||
|
Write your feedback details in Markdown format. Do not include filenames or risk levels in your feedback details.
|
||||||
|
|
||||||
|
Ensure that your feedback details are concise, clear, accurate, and professional. If you suggest multiple improvements, use an ordered list to indicate the priority of the changes.
|
||||||
|
|
||||||
|
You must respond only in ${language} to all inquiries! Please provide clear and accurate answers in ${language} language!
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
function system_prompt_old(useChinese) {
|
||||||
const chinese_prompt = useChinese ? "You must respond only in Chinese to all inquiries. Please provide clear and accurate answers in Chinese language." : "";
|
const chinese_prompt = useChinese ? "You must respond only in Chinese to all inquiries. Please provide clear and accurate answers in Chinese language." : "";
|
||||||
return `
|
return `
|
||||||
You are an expert developer, your task is to review a set of pull requests.
|
You are an expert developer, your task is to review a set of pull requests.
|
||||||
@@ -27,4 +47,12 @@ ${chinese_prompt}
|
|||||||
Please respond without using "\`\`\`markdown"
|
Please respond without using "\`\`\`markdown"
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
function take_system_prompt(genre, language) {
|
||||||
|
switch (genre) {
|
||||||
|
case "old":
|
||||||
|
return system_prompt_old(language.toLowerCase() === "chinese");
|
||||||
|
default:
|
||||||
|
return system_prompt_main(language);
|
||||||
|
}
|
||||||
|
}
|
||||||
exports.take_system_prompt = take_system_prompt;
|
exports.take_system_prompt = take_system_prompt;
|
||||||
|
|||||||
17
src/index.ts
17
src/index.ts
@@ -2,11 +2,15 @@ import {execSync} from "node:child_process";
|
|||||||
import {doesAnyPatternMatch, post, split_message} from "./utils";
|
import {doesAnyPatternMatch, post, split_message} from "./utils";
|
||||||
import {take_system_prompt} from "./prompt";
|
import {take_system_prompt} from "./prompt";
|
||||||
|
|
||||||
const useChinese = (process.env.INPUT_CHINESE || "true").toLowerCase() != "false"; // use chinese
|
let useChinese = (process.env.INPUT_CHINESE || "true").toLowerCase() != "false"; // use chinese
|
||||||
|
const language = !process.env.INPUT_CHINESE ? (process.env.INPUT_LANGUAGE || "Chinese") : (useChinese ? "Chinese" : "English");
|
||||||
|
const prompt_genre = (process.env.INPUT_PROMPT_GENRE || "");
|
||||||
|
const reviewers_prompt = (process.env.INPUT_REVIEWERS_PROMPT || "");
|
||||||
|
useChinese = language.toLowerCase() === "chinese"
|
||||||
const include_files = split_message(process.env.INPUT_INCLUDE_FILES || "");
|
const include_files = split_message(process.env.INPUT_INCLUDE_FILES || "");
|
||||||
const exclude_files = split_message(process.env.INPUT_EXCLUDE_FILES || "");
|
const exclude_files = split_message(process.env.INPUT_EXCLUDE_FILES || "");
|
||||||
|
|
||||||
const system_prompt = take_system_prompt(useChinese);
|
const system_prompt = reviewers_prompt || take_system_prompt(prompt_genre, language);
|
||||||
|
|
||||||
// 获取输入参数
|
// 获取输入参数
|
||||||
const url = process.env.INPUT_HOST; // INPUT_HOST 是从 action.yml 中定义的输入
|
const url = process.env.INPUT_HOST; // INPUT_HOST 是从 action.yml 中定义的输入
|
||||||
@@ -89,7 +93,14 @@ async function aiCheckDiffContext() {
|
|||||||
throw "ollama error";
|
throw "ollama error";
|
||||||
}
|
}
|
||||||
let Review = useChinese ? "审核结果" : "Review";
|
let Review = useChinese ? "审核结果" : "Review";
|
||||||
let comments = `# ${Review} \r\n${process.env.GITHUB_SERVER_URL}/${process.env.INPUT_REPOSITORY}/src/commit/${process.env.GITHUB_SHA}/${files[key]} \r\n\r\n\r\n${response.response}`
|
let commit: string = response.response;
|
||||||
|
if (commit.indexOf("```markdown") === 0) {
|
||||||
|
commit = commit.substring("```markdown".length);
|
||||||
|
if (commit.lastIndexOf("```") === commit.length - 3) {
|
||||||
|
commit = commit.substring(0, commit.length - 3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let comments = `# ${Review} \r\n${process.env.GITHUB_SERVER_URL}/${process.env.INPUT_REPOSITORY}/src/commit/${process.env.GITHUB_SHA}/${files[key]} \r\n\r\n\r\n${commit}`
|
||||||
let resp = await pushComments(comments);
|
let resp = await pushComments(comments);
|
||||||
if (!resp.id) {
|
if (!resp.id) {
|
||||||
// noinspection ExceptionCaughtLocallyJS
|
// noinspection ExceptionCaughtLocallyJS
|
||||||
|
|||||||
@@ -1,4 +1,25 @@
|
|||||||
export function take_system_prompt(useChinese: boolean) {
|
function system_prompt_main(language: string) {
|
||||||
|
language = language || "Chinese";
|
||||||
|
return `
|
||||||
|
Please note that you are a development expert, and your task is to review a set of pull requests. Below are the review steps you need to follow.
|
||||||
|
|
||||||
|
You will receive a list of filenames and their partial content, but be aware that you may not have the complete code context. Please only review the lines of code that have changed in the pull requests (added or deleted lines). The code is similar to the output of the git diff command. Deleted lines are prefixed with a minus sign "-", and added lines are prefixed with a plus sign "+". Other lines provide context but should be ignored for the review and should not be commented on.
|
||||||
|
|
||||||
|
When assessing the changed code, please use a risk scoring system similar to the LOGAF score, with a range from 1 to 5, where 1 indicates the lowest risk of merging the code into the codebase and 5 indicates the highest risk that may result in certain functionality being broken or unsafe.
|
||||||
|
|
||||||
|
In your feedback, highlight potential bugs, suggest ways to make the code more concise, and maximize the performance of the programming language. Immediately flag any API keys or secrets that exist in plaintext as high risk, provide a score, and output the API keys or secrets. If applicable, score the changes based on SOLID principles.
|
||||||
|
|
||||||
|
Please do not comment on splitting functions into smaller, more manageable ones unless it is a significant issue. Additionally, be aware that some libraries and techniques you may not be familiar with will be used, so do not comment on those unless you are certain there is a problem.
|
||||||
|
|
||||||
|
Write your feedback details in Markdown format. Do not include filenames or risk levels in your feedback details.
|
||||||
|
|
||||||
|
Ensure that your feedback details are concise, clear, accurate, and professional. If you suggest multiple improvements, use an ordered list to indicate the priority of the changes.
|
||||||
|
|
||||||
|
You must respond only in ${language} to all inquiries! Please provide clear and accurate answers in ${language} language!
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function system_prompt_old(useChinese: boolean) {
|
||||||
const chinese_prompt = useChinese ? "You must respond only in Chinese to all inquiries. Please provide clear and accurate answers in Chinese language." : "";
|
const chinese_prompt = useChinese ? "You must respond only in Chinese to all inquiries. Please provide clear and accurate answers in Chinese language." : "";
|
||||||
return `
|
return `
|
||||||
You are an expert developer, your task is to review a set of pull requests.
|
You are an expert developer, your task is to review a set of pull requests.
|
||||||
@@ -24,3 +45,13 @@ ${chinese_prompt}
|
|||||||
Please respond without using "\`\`\`markdown"
|
Please respond without using "\`\`\`markdown"
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function take_system_prompt(genre: string, language: string) {
|
||||||
|
switch (genre) {
|
||||||
|
case "old":
|
||||||
|
return system_prompt_old(language.toLowerCase() === "chinese");
|
||||||
|
default:
|
||||||
|
return system_prompt_main(language);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user