Skip to content

Commit 1dbf491

Browse files
author
Jakub Jirous
committed
[github] code review using open api
1 parent b2cb8a8 commit 1dbf491

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

.github/workflows/code_review.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: "Code Review"
2+
3+
on:
4+
pull_request:
5+
types: [opened, edited, synchronize]
6+
7+
env:
8+
API_KEY: ${{ secrets.OPENAI_API_KEY }}
9+
10+
jobs:
11+
review:
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: "Checkout code"
16+
uses: actions/checkout@v2
17+
18+
- name: Call ChatGPT API
19+
id: call_api
20+
run: |
21+
code_review_feedback=$(curl -X POST -H "Authorization: Bearer $API_KEY" -d '{"model": "text-davinci-002", "prompt": "Code Review Feedback: ${{ toJson(github.event.pull_request.head.repo.html_url) }}"}')
22+
23+
- name: "Add comment to pull request"
24+
uses: actions/github-script@v3
25+
env:
26+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
27+
with:
28+
script: |
29+
const response = JSON.parse(process.env.code_review_feedback);
30+
const feedback = response.choices[0].text;
31+
const issue_number = context.payload.pull_request.number;
32+
const repo = context.payload.repository.name;
33+
const owner = context.payload.repository.owner.login;
34+
35+
const octokit = new github.GitHub(process.env.GITHUB_TOKEN);
36+
37+
octokit.issues.createComment({
38+
owner,
39+
repo,
40+
issue_number,
41+
body: feedback
42+
});

0 commit comments

Comments
 (0)