1
- name : " Code Review Workflow "
1
+ name : " Code Review with OpenAI "
2
2
3
3
on :
4
4
pull_request :
5
- types : [opened, synchronize, reopened]
6
5
branches :
6
+ - main
7
7
- develop
8
8
9
9
jobs :
10
10
code-review :
11
+ name : " Code Review"
11
12
runs-on : ubuntu-latest
12
13
13
14
steps :
@@ -19,11 +20,43 @@ jobs:
19
20
with :
20
21
node-version : 16
21
22
22
- - name : " Fetch pull request information"
23
- id : pr-info
23
+ - name : " Install OpenAI package"
24
+ run : |
25
+ npm install openai
26
+
27
+ - name : " Send code to OpenAI for review"
28
+ id : code-review
24
29
uses : actions/github-script@v3
30
+ env :
31
+ OPENAI_API_KEY : ${{ secrets.OPENAI_API_KEY }}
25
32
with :
26
- github-token : ${{ secrets.GH_TOKEN }}
27
33
script : |
28
- const pr = context.payload.pull_request;
29
- console.log(` Pull request information: ${JSON.stringify(pr)}`);
34
+ const openai = require("openai");
35
+ openai.prompt(
36
+ {
37
+ model: "text-davinci-002",
38
+ prompt: "Please review the code in this pull request and provide feedback",
39
+ maxTokens: 100,
40
+ temperature: 0.5,
41
+ topP: 1
42
+ },
43
+ function(error, response) {
44
+ if (error) {
45
+ throw new Error(error);
46
+ }
47
+ const review = response.choices[0].text;
48
+ const pull_request_number = context.payload.pull_request.number;
49
+ const pull_request_body = context.payload.pull_request.body;
50
+ const new_body = pull_request_body + "\n\n" + "Code Review: " + review;
51
+ octokit.pulls.update({
52
+ owner: context.repo.owner,
53
+ repo: context.repo.repo,
54
+ pull_number: pull_request_number,
55
+ body: new_body
56
+ }).then(() => {
57
+ console.log("Code review successfully added to the pull request!");
58
+ }).catch((error) => {
59
+ throw new Error(error);
60
+ });
61
+ }
62
+ );
0 commit comments