mirror of
https://github.com/ingress-it-solutions/gitea-code-review-action.git
synced 2025-04-19 10:46:45 +00:00
commit
c29eccff0d
4 changed files with 400 additions and 420 deletions
65
action.yaml
65
action.yaml
|
@ -27,21 +27,55 @@ inputs:
|
|||
default: 'github'
|
||||
PROMPT_TEMPLATE:
|
||||
description: 'The template for the FULL_REVIEW_COMMENT prompt.'
|
||||
default: 'Please analyze the pull request''s code and provide me an explanation for your decision in bullet points. Also provide me whether it requires optimization or code correction:
|
||||
\`\`\`
|
||||
${code}
|
||||
\`\`\`'
|
||||
default: 'Your task is to act as a code reviewer and review a pull request by summarizing the changes made, identifying potential issues related to logic and runtime, and creating a bullet list of action items needed before the change can be approved. The output should focus on items mentioned in the given code review checklist.
|
||||
Instructions:
|
||||
- Review the output of git diff for the pull request
|
||||
- Summarize the overview of the changes made
|
||||
- Identify potential issues related to logic and runtime
|
||||
- Output as a markdown document, with the following sections:
|
||||
#### Overview of changes:
|
||||
- Summarize the overview of the changes made
|
||||
#### Changelog:
|
||||
- Summarize the overview in a bullet point to consider it in Change-log.
|
||||
#### issues:
|
||||
- Identify potential issues related to logic and runtime
|
||||
- Identify issues mentioned in the code review checklist
|
||||
#### Action items:
|
||||
- Mandatory action items that are must and needed before the change can be approved
|
||||
#### Joke about this PR:
|
||||
- Tell me a joke about this Code Review
|
||||
- If there are no issues, output "None"
|
||||
- If there are no action items, output "None"
|
||||
- Create a bullet list of action items needed before the change can be approved
|
||||
- The response sentences are no longer than 16 words each
|
||||
- Keep the response sentences as short as possible
|
||||
- Focus on items mentioned in the given code review checklist:
|
||||
Code Structure
|
||||
- Validation
|
||||
- Business logic should be in service class
|
||||
- Dont repeat yourself (DRY)
|
||||
- Prefer to use Eloquent over using Query Builder and raw SQL queries. Prefer collections over arrays
|
||||
- Mass assignment
|
||||
- Do not execute queries in Blade templates and use eager loading (N + 1 problem)
|
||||
- Chunk data for data-heavy tasks
|
||||
- Comment your code, but prefer descriptive method and variable names over comments
|
||||
- Do not put JS and CSS in Blade templates and do not put any HTML in PHP classes
|
||||
- Use config and language files, constants instead of text in the code
|
||||
- Use standard Laravel tools accepted by community
|
||||
- Follow Laravel naming conventions
|
||||
- Use shorter and more readable syntax where possible
|
||||
- Use IoC container or facades instead of new Class
|
||||
- Are there any unnecessary files, folders, or code modules?
|
||||
- Does the code follow the Single Responsibility Principle (SRP) and Dont Repeat Yourself (DRY) principle?
|
||||
Error Handling
|
||||
- Are all error scenarios covered in the code?
|
||||
- Are the error messages clear and helpful?
|
||||
- Is the code handling errors gracefully?
|
||||
Security
|
||||
- Are sensitive data and credentials stored securely?
|
||||
- Are all external libraries and packages up-to-date?
|
||||
- Is the code protected against common security vulnerabilities such as SQL injection and cross-site scripting (XSS)?
|
||||
|
||||
JOKE_TEMPLATE:
|
||||
description: 'The template for the FULL_REVIEW_JOKE prompt.'
|
||||
default: 'Please analyze the pull request''s code and can you write a funny joke about it.:
|
||||
\`\`\`
|
||||
${code}
|
||||
\`\`\`'
|
||||
|
||||
CODE_TEMPLATE:
|
||||
description: 'The place for the actual code.'
|
||||
default: '
|
||||
\`\`\`
|
||||
${code}
|
||||
\`\`\`'
|
||||
|
@ -49,11 +83,10 @@ ${code}
|
|||
ANSWER_TEMPLATE:
|
||||
description: 'The template for the answer sent to the GitHub comment.'
|
||||
default: 'AI Code Review:
|
||||
|
||||
=======
|
||||
### Summary:
|
||||
|
||||
${answer}'
|
||||
|
||||
runs:
|
||||
using: 'node16'
|
||||
main: 'dist/index.js'
|
||||
|
|
43
dist/index.js
vendored
43
dist/index.js
vendored
|
@ -39213,8 +39213,6 @@ async function run() {
|
|||
const githubToken = core.getInput('GITHUB_TOKEN');
|
||||
const githubBaseURL = core.getInput('GITHUB_BASE_URL') || process.env.GITHUB_API_URL;
|
||||
const promptTemplate = core.getInput('PROMPT_TEMPLATE');
|
||||
const codeTemplate = core.getInput('CODE_TEMPLATE');
|
||||
const jokeTemplate = core.getInput('JOKE_TEMPLATE');
|
||||
const maxCodeLength = core.getInput('MAX_CODE_LENGTH');
|
||||
const answerTemplate = core.getInput('ANSWER_TEMPLATE');
|
||||
const giteaToken = core.getInput('GITHUB_TOKEN');
|
||||
|
@ -39227,8 +39225,6 @@ async function run() {
|
|||
core.debug(`githubToken length: ${githubToken.length}`);
|
||||
core.debug(`githubBaseURL: ${githubBaseURL}`);
|
||||
core.debug(`promptTemplate: ${promptTemplate}`);
|
||||
core.debug(`codeTemplate: ${codeTemplate}`);
|
||||
core.debug(`jokeTemplate: ${jokeTemplate}`);
|
||||
core.debug(`maxCodeLength: ${maxCodeLength}`);
|
||||
core.debug(`answerTemplate: ${answerTemplate}`);
|
||||
core.debug(`SourceAt: ${sourceAt}`);
|
||||
|
@ -39241,7 +39237,7 @@ async function run() {
|
|||
|
||||
// Get the code to analyze from the review comment
|
||||
var content = comment && comment.body || '';
|
||||
var completeContent = comment && comment.body || '';
|
||||
|
||||
if(sourceAt === 'github') {
|
||||
|
||||
const url = `${githubBaseURL}/repos/${repoOwner}/${repoName}/pulls/${prNumber}`;
|
||||
|
@ -39259,7 +39255,7 @@ async function run() {
|
|||
|
||||
if (!content || content == fullReviewComment) {
|
||||
// Extract the code from the pull request content
|
||||
content = codeTemplate.replace('${code}', code);
|
||||
content = promptTemplate.replace('${code}', code);
|
||||
} else {
|
||||
content = content.substring(reviewCommentPrefix.length);
|
||||
content = content.replace('${code}', code);
|
||||
|
@ -39294,7 +39290,7 @@ async function run() {
|
|||
|
||||
if (!content || content == fullReviewComment) {
|
||||
// Extract the code from the pull request content
|
||||
content = codeTemplate.replace('${code}', code);
|
||||
content = promptTemplate.replace('${code}', code);
|
||||
} else {
|
||||
content = content.substring(reviewCommentPrefix.length);
|
||||
content = content.replace('${code}', code);
|
||||
|
@ -39319,30 +39315,20 @@ async function run() {
|
|||
programmingLanguage = detectedLanguage;
|
||||
}
|
||||
|
||||
var messageReview = promptTemplate.replace('${code}', content);
|
||||
var messageJoke = jokeTemplate.replace('${code}', content);
|
||||
var reviewInputMessages = [{
|
||||
var messages = [{
|
||||
role: "system",
|
||||
content: `You are a master of programming language ${programmingLanguage}`
|
||||
}, {
|
||||
role: "user",
|
||||
content: messageReview
|
||||
}];
|
||||
|
||||
var jokeInputMessages = [{
|
||||
role: "system",
|
||||
content: `You are a master of programming language ${programmingLanguage}`
|
||||
}, {
|
||||
role: "user",
|
||||
content: messageJoke
|
||||
content: content
|
||||
}];
|
||||
|
||||
core.debug(`content: ${content}`);
|
||||
|
||||
// Call the OpenAI ChatGPT API to analyze the code
|
||||
responseReview = await axios.post('https://api.openai.com/v1/chat/completions', {
|
||||
response = await axios.post('https://api.openai.com/v1/chat/completions', {
|
||||
"model": "gpt-3.5-turbo",
|
||||
"messages": reviewInputMessages
|
||||
"messages": messages
|
||||
}, configWithProxy({
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
|
@ -39350,19 +39336,7 @@ async function run() {
|
|||
}
|
||||
}));
|
||||
|
||||
// Call the OpenAI ChatGPT API to analyze the code
|
||||
responseJoke = await axios.post('https://api.openai.com/v1/chat/completions', {
|
||||
"model": "gpt-3.5-turbo",
|
||||
"messages": jokeInputMessages
|
||||
}, configWithProxy({
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `Bearer ${openaiToken}`
|
||||
}
|
||||
}));
|
||||
|
||||
|
||||
const answer = response.data.choices[0].message.content + '/n/n' + '### Funny Joke about this PR:' +'/n/n' + responseJoke.data.choices[0].message.content;
|
||||
const answer = response.data.choices[0].message.content;
|
||||
core.debug(`openai response: ${answer}`);
|
||||
|
||||
if(sourceAt === 'github') {
|
||||
|
@ -39442,7 +39416,6 @@ function findFileNames(str) {
|
|||
}
|
||||
|
||||
run();
|
||||
|
||||
})();
|
||||
|
||||
module.exports = __webpack_exports__;
|
||||
|
|
2
dist/index.js.map
vendored
2
dist/index.js.map
vendored
File diff suppressed because one or more lines are too long
42
index.js
42
index.js
|
@ -27,8 +27,6 @@ async function run() {
|
|||
const githubToken = core.getInput('GITHUB_TOKEN');
|
||||
const githubBaseURL = core.getInput('GITHUB_BASE_URL') || process.env.GITHUB_API_URL;
|
||||
const promptTemplate = core.getInput('PROMPT_TEMPLATE');
|
||||
const codeTemplate = core.getInput('CODE_TEMPLATE');
|
||||
const jokeTemplate = core.getInput('JOKE_TEMPLATE');
|
||||
const maxCodeLength = core.getInput('MAX_CODE_LENGTH');
|
||||
const answerTemplate = core.getInput('ANSWER_TEMPLATE');
|
||||
const giteaToken = core.getInput('GITHUB_TOKEN');
|
||||
|
@ -41,8 +39,6 @@ async function run() {
|
|||
core.debug(`githubToken length: ${githubToken.length}`);
|
||||
core.debug(`githubBaseURL: ${githubBaseURL}`);
|
||||
core.debug(`promptTemplate: ${promptTemplate}`);
|
||||
core.debug(`codeTemplate: ${codeTemplate}`);
|
||||
core.debug(`jokeTemplate: ${jokeTemplate}`);
|
||||
core.debug(`maxCodeLength: ${maxCodeLength}`);
|
||||
core.debug(`answerTemplate: ${answerTemplate}`);
|
||||
core.debug(`SourceAt: ${sourceAt}`);
|
||||
|
@ -55,7 +51,7 @@ async function run() {
|
|||
|
||||
// Get the code to analyze from the review comment
|
||||
var content = comment && comment.body || '';
|
||||
var completeContent = comment && comment.body || '';
|
||||
|
||||
if(sourceAt === 'github') {
|
||||
|
||||
const url = `${githubBaseURL}/repos/${repoOwner}/${repoName}/pulls/${prNumber}`;
|
||||
|
@ -73,7 +69,7 @@ async function run() {
|
|||
|
||||
if (!content || content == fullReviewComment) {
|
||||
// Extract the code from the pull request content
|
||||
content = codeTemplate.replace('${code}', code);
|
||||
content = promptTemplate.replace('${code}', code);
|
||||
} else {
|
||||
content = content.substring(reviewCommentPrefix.length);
|
||||
content = content.replace('${code}', code);
|
||||
|
@ -108,7 +104,7 @@ async function run() {
|
|||
|
||||
if (!content || content == fullReviewComment) {
|
||||
// Extract the code from the pull request content
|
||||
content = codeTemplate.replace('${code}', code);
|
||||
content = promptTemplate.replace('${code}', code);
|
||||
} else {
|
||||
content = content.substring(reviewCommentPrefix.length);
|
||||
content = content.replace('${code}', code);
|
||||
|
@ -133,30 +129,20 @@ async function run() {
|
|||
programmingLanguage = detectedLanguage;
|
||||
}
|
||||
|
||||
var messageReview = promptTemplate.replace('${code}', content);
|
||||
var messageJoke = jokeTemplate.replace('${code}', content);
|
||||
var reviewInputMessages = [{
|
||||
var messages = [{
|
||||
role: "system",
|
||||
content: `You are a master of programming language ${programmingLanguage}`
|
||||
}, {
|
||||
role: "user",
|
||||
content: messageReview
|
||||
}];
|
||||
|
||||
var jokeInputMessages = [{
|
||||
role: "system",
|
||||
content: `You are a master of programming language ${programmingLanguage}`
|
||||
}, {
|
||||
role: "user",
|
||||
content: messageJoke
|
||||
content: content
|
||||
}];
|
||||
|
||||
core.debug(`content: ${content}`);
|
||||
|
||||
// Call the OpenAI ChatGPT API to analyze the code
|
||||
responseReview = await axios.post('https://api.openai.com/v1/chat/completions', {
|
||||
response = await axios.post('https://api.openai.com/v1/chat/completions', {
|
||||
"model": "gpt-3.5-turbo",
|
||||
"messages": reviewInputMessages
|
||||
"messages": messages
|
||||
}, configWithProxy({
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
|
@ -164,19 +150,7 @@ async function run() {
|
|||
}
|
||||
}));
|
||||
|
||||
// Call the OpenAI ChatGPT API to analyze the code
|
||||
responseJoke = await axios.post('https://api.openai.com/v1/chat/completions', {
|
||||
"model": "gpt-3.5-turbo",
|
||||
"messages": jokeInputMessages
|
||||
}, configWithProxy({
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `Bearer ${openaiToken}`
|
||||
}
|
||||
}));
|
||||
|
||||
|
||||
const answer = response.data.choices[0].message.content + '/n/n' + '### Funny Joke about this PR:' +'/n/n' + responseJoke.data.choices[0].message.content;
|
||||
const answer = response.data.choices[0].message.content;
|
||||
core.debug(`openai response: ${answer}`);
|
||||
|
||||
if(sourceAt === 'github') {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue