-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yml
75 lines (63 loc) · 2.46 KB
/
action.yml
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
name: "PullRequest Code Reviewer for Azure"
description: "Conducts code reviews for PullRequests"
branding:
icon: "activity"
color: "blue"
inputs:
api-key:
description: "Azure OpenAI service api key"
required: true
endpoint-url:
description: "Azure OpenAI service access url"
required: true
runs:
using: "composite"
steps:
- name: Checkout to pull request branch
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Fetch to base branch
shell: bash
run: git fetch origin ${{ github.event.pull_request.base.sha }}:BASE
- name: Setup Python
uses: actions/setup-python@v3
with:
python-version: "3.8"
architecture: "x64"
- name: Install Python Library
shell: bash
run: |
pip install --upgrade pip
pip install openai
- name: Clone Python Script
shell: bash
run: |
mkdir /tmp/pythonscript
git clone https://github.com/alterbooth/github-app-on-azure.git /tmp/pythonscript
- name: Get code to review
shell: bash
run: |
git diff --diff-filter=M --name-only HEAD BASE | grep -f .reviewfiles | grep -v ".github" > modifiedCode.txt
git diff --diff-filter=A --name-only BASE | grep -f .reviewfiles | grep -v ".github" > addedCode.txt
- name: Code review with ChatGPT
shell: bash
env:
API_KEY: ${{ inputs.api-key }}
ENDPOINT_URL: ${{ inputs.endpoint-url }}
GH_TOKEN: ${{ github.token }}
URL: ${{ github.event.pull_request.html_url }}
run: |
cat modifiedCode.txt | while read file_path ; do
git cat-file -p BASE:${file_path} > before.txt
git cat-file -p HEAD:${file_path} > after.txt
result=$(python /tmp/pythonscript/dist/reviewModified.py "${file_path}" "before.txt" "after.txt")
echo "${result}" > result.txt
gh pr comment --body-file result.txt "${URL}"
done
cat addedCode.txt | while read file_path ; do
git cat-file -p HEAD:${file_path} > code.txt
result=$(python /tmp/pythonscript/dist/reviewAdded.py "${file_path}" "code.txt")
echo "${result}" > result.txt
gh pr comment --body-file result.txt "${URL}"
done