Resolved COnflict

This commit is contained in:
Bhavik MacBook PRO 16 2023-05-12 00:13:13 +05:30
commit 1f559fdb0c
4 changed files with 72 additions and 17 deletions

View file

@ -66,9 +66,12 @@ ${code}
- Are sensitive data and credentials stored securely? - Are sensitive data and credentials stored securely?
- Are all external libraries and packages up-to-date? - 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)?' - Is the code protected against common security vulnerabilities such as SQL injection and cross-site scripting (XSS)?'
ANSWER_TEMPLATE: ANSWER_TEMPLATE:
description: 'The template for the answer sent to the GitHub comment.' description: 'The template for the answer sent to the GitHub comment.'
default: 'AI Code Review: default: 'AI Code Review:
=======
### Summary:
${answer}' ${answer}'
runs: runs:

42
dist/index.js vendored
View file

@ -39213,6 +39213,8 @@ async function run() {
const githubToken = core.getInput('GITHUB_TOKEN'); const githubToken = core.getInput('GITHUB_TOKEN');
const githubBaseURL = core.getInput('GITHUB_BASE_URL') || process.env.GITHUB_API_URL; const githubBaseURL = core.getInput('GITHUB_BASE_URL') || process.env.GITHUB_API_URL;
const promptTemplate = core.getInput('PROMPT_TEMPLATE'); 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 maxCodeLength = core.getInput('MAX_CODE_LENGTH');
const answerTemplate = core.getInput('ANSWER_TEMPLATE'); const answerTemplate = core.getInput('ANSWER_TEMPLATE');
const giteaToken = core.getInput('GITHUB_TOKEN'); const giteaToken = core.getInput('GITHUB_TOKEN');
@ -39225,6 +39227,8 @@ async function run() {
core.debug(`githubToken length: ${githubToken.length}`); core.debug(`githubToken length: ${githubToken.length}`);
core.debug(`githubBaseURL: ${githubBaseURL}`); core.debug(`githubBaseURL: ${githubBaseURL}`);
core.debug(`promptTemplate: ${promptTemplate}`); core.debug(`promptTemplate: ${promptTemplate}`);
core.debug(`codeTemplate: ${codeTemplate}`);
core.debug(`jokeTemplate: ${jokeTemplate}`);
core.debug(`maxCodeLength: ${maxCodeLength}`); core.debug(`maxCodeLength: ${maxCodeLength}`);
core.debug(`answerTemplate: ${answerTemplate}`); core.debug(`answerTemplate: ${answerTemplate}`);
core.debug(`SourceAt: ${sourceAt}`); core.debug(`SourceAt: ${sourceAt}`);
@ -39237,7 +39241,7 @@ async function run() {
// Get the code to analyze from the review comment // Get the code to analyze from the review comment
var content = comment && comment.body || ''; var content = comment && comment.body || '';
var completeContent = comment && comment.body || '';
if(sourceAt === 'github') { if(sourceAt === 'github') {
const url = `${githubBaseURL}/repos/${repoOwner}/${repoName}/pulls/${prNumber}`; const url = `${githubBaseURL}/repos/${repoOwner}/${repoName}/pulls/${prNumber}`;
@ -39255,7 +39259,7 @@ async function run() {
if (!content || content == fullReviewComment) { if (!content || content == fullReviewComment) {
// Extract the code from the pull request content // Extract the code from the pull request content
content = promptTemplate.replace('${code}', code); content = code;
} else { } else {
content = content.substring(reviewCommentPrefix.length); content = content.substring(reviewCommentPrefix.length);
content = content.replace('${code}', code); content = content.replace('${code}', code);
@ -39290,7 +39294,7 @@ async function run() {
if (!content || content == fullReviewComment) { if (!content || content == fullReviewComment) {
// Extract the code from the pull request content // Extract the code from the pull request content
content = promptTemplate.replace('${code}', code); content = code;
} else { } else {
content = content.substring(reviewCommentPrefix.length); content = content.substring(reviewCommentPrefix.length);
content = content.replace('${code}', code); content = content.replace('${code}', code);
@ -39315,20 +39319,30 @@ async function run() {
programmingLanguage = detectedLanguage; programmingLanguage = detectedLanguage;
} }
var messages = [{ var messageReview = promptTemplate.replace('${code}', content);
var messageJoke = jokeTemplate.replace('${code}', content);
var reviewInputMessages = [{
role: "system", role: "system",
content: `You are a master of programming language ${programmingLanguage}` content: `You are a master of programming language ${programmingLanguage}`
}, { }, {
role: "user", role: "user",
content: content content: messageReview
}];
var jokeInputMessages = [{
role: "system",
content: `You are a master of programming language ${programmingLanguage}`
}, {
role: "user",
content: messageJoke
}]; }];
core.debug(`content: ${content}`); core.debug(`content: ${content}`);
// Call the OpenAI ChatGPT API to analyze the code // Call the OpenAI ChatGPT API to analyze the code
response = await axios.post('https://api.openai.com/v1/chat/completions', { responseReview = await axios.post('https://api.openai.com/v1/chat/completions', {
"model": "gpt-3.5-turbo", "model": "gpt-3.5-turbo",
"messages": messages "messages": reviewInputMessages
}, configWithProxy({ }, configWithProxy({
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
@ -39336,7 +39350,19 @@ async function run() {
} }
})); }));
const answer = response.data.choices[0].message.content; // 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;
core.debug(`openai response: ${answer}`); core.debug(`openai response: ${answer}`);
if(sourceAt === 'github') { if(sourceAt === 'github') {

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

View file

@ -27,6 +27,8 @@ async function run() {
const githubToken = core.getInput('GITHUB_TOKEN'); const githubToken = core.getInput('GITHUB_TOKEN');
const githubBaseURL = core.getInput('GITHUB_BASE_URL') || process.env.GITHUB_API_URL; const githubBaseURL = core.getInput('GITHUB_BASE_URL') || process.env.GITHUB_API_URL;
const promptTemplate = core.getInput('PROMPT_TEMPLATE'); 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 maxCodeLength = core.getInput('MAX_CODE_LENGTH');
const answerTemplate = core.getInput('ANSWER_TEMPLATE'); const answerTemplate = core.getInput('ANSWER_TEMPLATE');
const giteaToken = core.getInput('GITHUB_TOKEN'); const giteaToken = core.getInput('GITHUB_TOKEN');
@ -39,6 +41,8 @@ async function run() {
core.debug(`githubToken length: ${githubToken.length}`); core.debug(`githubToken length: ${githubToken.length}`);
core.debug(`githubBaseURL: ${githubBaseURL}`); core.debug(`githubBaseURL: ${githubBaseURL}`);
core.debug(`promptTemplate: ${promptTemplate}`); core.debug(`promptTemplate: ${promptTemplate}`);
core.debug(`codeTemplate: ${codeTemplate}`);
core.debug(`jokeTemplate: ${jokeTemplate}`);
core.debug(`maxCodeLength: ${maxCodeLength}`); core.debug(`maxCodeLength: ${maxCodeLength}`);
core.debug(`answerTemplate: ${answerTemplate}`); core.debug(`answerTemplate: ${answerTemplate}`);
core.debug(`SourceAt: ${sourceAt}`); core.debug(`SourceAt: ${sourceAt}`);
@ -51,7 +55,7 @@ async function run() {
// Get the code to analyze from the review comment // Get the code to analyze from the review comment
var content = comment && comment.body || ''; var content = comment && comment.body || '';
var completeContent = comment && comment.body || '';
if(sourceAt === 'github') { if(sourceAt === 'github') {
const url = `${githubBaseURL}/repos/${repoOwner}/${repoName}/pulls/${prNumber}`; const url = `${githubBaseURL}/repos/${repoOwner}/${repoName}/pulls/${prNumber}`;
@ -69,7 +73,7 @@ async function run() {
if (!content || content == fullReviewComment) { if (!content || content == fullReviewComment) {
// Extract the code from the pull request content // Extract the code from the pull request content
content = promptTemplate.replace('${code}', code); content = code;
} else { } else {
content = content.substring(reviewCommentPrefix.length); content = content.substring(reviewCommentPrefix.length);
content = content.replace('${code}', code); content = content.replace('${code}', code);
@ -104,7 +108,7 @@ async function run() {
if (!content || content == fullReviewComment) { if (!content || content == fullReviewComment) {
// Extract the code from the pull request content // Extract the code from the pull request content
content = promptTemplate.replace('${code}', code); content = code;
} else { } else {
content = content.substring(reviewCommentPrefix.length); content = content.substring(reviewCommentPrefix.length);
content = content.replace('${code}', code); content = content.replace('${code}', code);
@ -129,20 +133,30 @@ async function run() {
programmingLanguage = detectedLanguage; programmingLanguage = detectedLanguage;
} }
var messages = [{ var messageReview = promptTemplate.replace('${code}', content);
var messageJoke = jokeTemplate.replace('${code}', content);
var reviewInputMessages = [{
role: "system", role: "system",
content: `You are a master of programming language ${programmingLanguage}` content: `You are a master of programming language ${programmingLanguage}`
}, { }, {
role: "user", role: "user",
content: content content: messageReview
}];
var jokeInputMessages = [{
role: "system",
content: `You are a master of programming language ${programmingLanguage}`
}, {
role: "user",
content: messageJoke
}]; }];
core.debug(`content: ${content}`); core.debug(`content: ${content}`);
// Call the OpenAI ChatGPT API to analyze the code // Call the OpenAI ChatGPT API to analyze the code
response = await axios.post('https://api.openai.com/v1/chat/completions', { responseReview = await axios.post('https://api.openai.com/v1/chat/completions', {
"model": "gpt-3.5-turbo", "model": "gpt-3.5-turbo",
"messages": messages "messages": reviewInputMessages
}, configWithProxy({ }, configWithProxy({
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
@ -150,7 +164,19 @@ async function run() {
} }
})); }));
const answer = response.data.choices[0].message.content; // 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;
core.debug(`openai response: ${answer}`); core.debug(`openai response: ${answer}`);
if(sourceAt === 'github') { if(sourceAt === 'github') {