Skip to content

Commit

Permalink
fix: updated code
Browse files Browse the repository at this point in the history
  • Loading branch information
arwa-lokhandwala committed Jun 29, 2023
1 parent 0bf6da9 commit bae22fc
Showing 1 changed file with 34 additions and 18 deletions.
52 changes: 34 additions & 18 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ const { Octokit } = require("@octokit/rest");
const express = require('express');
const { Configuration, OpenAIApi } = require("openai");

const octokit = new Octokit({auth: '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'})
const openAIAPIKey = 'keyhere'
const octokit = new Octokit({auth: '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'})
const openAIAPIKey = ''


const app = express()
Expand Down Expand Up @@ -37,7 +37,7 @@ async function getLatestPR() {
'X-GitHub-Api-Version': '2022-11-28'
}
})
console.log('--- Get latest PR', res)
// console.log('--- Get latest PR', res)
return [res.data[0].number, res.data[0].path]
}

Expand All @@ -50,21 +50,21 @@ async function getPRFiles(pull_number) {
'X-GitHub-Api-Version': '2022-11-28'
}
})
// console.log('Files Diff Response', res)
console.log('Files Diff Response', res)
return res
}

async function getChatGPTResponse(queryText) {
const configuration = new Configuration({
organization: "org-FNLEwrTIjd8amAb84DOcvNNL",
apiKey: openAIAPIKey,
});
const openai = new OpenAIApi(configuration);
const response = await openai.createChatCompletion({
model: "gpt-4",
messages: [{role: "user", content: queryText}],
});
return response.data.choices[0].message
async function getLatestCommitID(pull_number) {
const res = await octokit.request('GET /repos/{owner}/{repo}/pulls/{pull_number}/commits', {
owner: 'RedVentures',
repo: 'rd-hackathon-2023-team-2',
pull_number: pull_number,
headers: {
'X-GitHub-Api-Version': '2022-11-28'
}
})
// console.log('Latest Commit Response Response', res)
return res.data[res.data.length-1].sha
}

async function commentChatGPTReview(queryText, pull_number, commit_id, path) {
Expand All @@ -73,19 +73,35 @@ async function commentChatGPTReview(queryText, pull_number, commit_id, path) {
apiKey: openAIAPIKey,
});
const openai = new OpenAIApi(configuration);

const res = await openai.createChatCompletion({
model: "gpt-4",
messages: [{role: "user", content: queryText}],
messages: [
{role: "user", content: `Act as Programming expert and give useful feedback. It should only include improvement feedback along with examples. This is the code for which the feedback is needed ${queryText}`},
{role: "assistant", content: `Explain in plain english what's done in this code ${queryText}`}
],
});

await createReviewComment(pull_number, res.data.choices[0].message.content, commit_id, path)

for(let comment of res.data.choices) {
console.log(`\n\n${comment}\n\n`)
await createReviewComment(pull_number, comment.message.content, commit_id, path)
}

}


app.get('/', async (req, res) => {
const [pull_number, path] = await getLatestPR()
const filesDiff = await getPRFiles(pull_number)
await commentChatGPTReview(filesDiff.data[0].patch, pull_number,filesDiff.data[0].filename)
const commitId = await getLatestCommitID(pull_number)

for(const file of filesDiff.data) {
console.log(file,' ---file')
if(file.filename.includes('.js') || file.filename.includes('.css')) {
await commentChatGPTReview(file.patch, pull_number,commitId,file.filename)
}
}
res.send('Review Completed!')
})

Expand Down

0 comments on commit bae22fc

Please sign in to comment.