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 57
/
Copy pathprompt.js
41 lines (38 loc) · 1.41 KB
/
prompt.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
function genReviewPRPrompt(title, body, diff) {
const prompt = `Can you tell me the problems with the following pull request and describe your suggestions?
title: ${title}
body: ${body}
The following diff is the changes made in this PR.
${diff}`;
return prompt;
}
function genReviewPRSplitedPrompt(title, body, diff, limit) {
let splits = [];
diff
.split(/(diff --git .+\n)/g)
.slice(1)
.reduce((prev, cur, i) => {
if (i % 2 == 1) {
let dif = prev + cur;
if (dif.length > limit) {
const header = diff.split("\n", 1)[0];
const info = "This diff is too large so I omitted it for you.";
splits.push(`${header}\n${info}`);
} else splits.push(dif);
}
return cur;
});
return {
welcomePrompts: [
`Here is a pull request. Please assume you are a reviewer of this PR. First I will tell you the title and body of the PR. Please greet the PR author if you have done reading.
The title is ${title}
The remaining part is the body.
${body}`,
`Now I will give you the changes made in this PR one file at a time.
When a diff is too large, I will omit it and tell you about that.`,
],
diffPrompts: splits,
endPrompt: `Based on your existing knowledge, can you tell me the problems with the above pull request and your suggestions for this PR?`,
};
}
module.exports = { genReviewPRPrompt, genReviewPRSplitedPrompt };