Skip to content

Commit 800f2a9

Browse files
author
Jakub Jirous
committed
[github] open ai
[github] open ai [github] open ai [github] open ai [github] open ai [github] open ai [github] open ai [github] open ai [github] open ai
1 parent e659a2a commit 800f2a9

File tree

1 file changed

+40
-7
lines changed

1 file changed

+40
-7
lines changed

.github/workflows/code_review.yml

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
name: "Code Review Workflow"
1+
name: "Code Review with OpenAI"
22

33
on:
44
pull_request:
5-
types: [opened, synchronize, reopened]
65
branches:
6+
- main
77
- develop
88

99
jobs:
1010
code-review:
11+
name: "Code Review"
1112
runs-on: ubuntu-latest
1213

1314
steps:
@@ -19,11 +20,43 @@ jobs:
1920
with:
2021
node-version: 16
2122

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
2429
uses: actions/github-script@v3
30+
env:
31+
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
2532
with:
26-
github-token: ${{ secrets.GH_TOKEN }}
2733
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

Comments
 (0)