This repository has been archived by the owner on Aug 15, 2024. It is now read-only.
generated from actions/javascript-action
-
Notifications
You must be signed in to change notification settings - Fork 58
/
run.js
59 lines (57 loc) · 1.64 KB
/
run.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
const core = require("@actions/core");
const { genReviewPRPrompt, genReviewPRSplitedPrompt } = require("./prompt");
const { callChatGPT, startConversation } = require("./chatgpt");
const { Octokit } = require("@octokit/action");
const github = require("@actions/github");
const octokit = new Octokit();
const context = github.context;
async function runPRReview({ api, repo, owner, number, split }) {
const {
data: { title, body },
} = await octokit.pulls.get({
owner,
repo,
pull_number: number,
});
const { data: diff } = await octokit.rest.pulls.get({
owner,
repo,
pull_number: number,
mediaType: {
format: "diff",
},
});
let reply;
if (split == "yolo") {
const prompt = genReviewPRPrompt(title, body, diff);
core.info(`The prompt is: ${prompt}`);
const response = await callChatGPT(api, prompt, 5);
reply = response;
} else {
reply = "";
const { welcomePrompts, diffPrompts, endPrompt } = genReviewPRSplitedPrompt(
title,
body,
diff,
65536
);
const conversation = startConversation(api, 5);
let cnt = 0;
const prompts = welcomePrompts.concat(diffPrompts);
prompts.push(endPrompt);
for (const prompt of prompts) {
core.info(`Sending ${prompt}`);
const response = await conversation.sendMessage(prompt);
core.info(`Received ${response}`);
reply += `**ChatGPT#${++cnt}**: ${response}\n\n`;
// Wait for 10s
await new Promise((r) => setTimeout(r, 10000));
}
}
await octokit.issues.createComment({
...context.repo,
issue_number: number,
body: reply,
});
}
module.exports = { runPRReview };