-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Let's not reinvent the wheel, there is already a plugin for it
- Loading branch information
Thanasis Politis
committed
Mar 25, 2023
1 parent
3ba54d2
commit 3d06e71
Showing
1 changed file
with
13 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,23 @@ | ||
name: ChatGPT Code Review | ||
|
||
permissions: | ||
contents: read | ||
pull-requests: write | ||
|
||
on: | ||
pull_request: | ||
types: [opened, edited, reopened, synchronize] | ||
types: [opened, reopened, synchronize] | ||
|
||
jobs: | ||
code_review: | ||
test: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Install Python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: "3.9" | ||
|
||
- name: Install dependencies | ||
run: pip install requests | ||
|
||
- name: Run code review | ||
- uses: anc95/ChatGPT-CodeReview@main | ||
env: | ||
PR_NUMBER: ${{ github.event.pull_request.number }} | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
CHATGPT_API_KEY: ${{ secrets.CHATGPT_API_KEY }} | ||
run: | | ||
set -e | ||
# Get the list of files changed in the pull request | ||
files=$(git diff --name-only HEAD~1) | ||
# Loop through each file and get its contents | ||
for file in $files; do | ||
contents=$(git show HEAD~1:$file) | ||
# Send the contents to ChatGPT for review | ||
response=$(curl -s -X POST -H "Authorization: Bearer $CHATGPT_API_KEY" -H "Content-Type: application/json" -d "{\"text\": \"$contents\"}" "https://api.openai.com/v1/engines/davinci-codex/completions?prompt=Please review the following code:&max_tokens=100&n=1") | ||
# Parse the response to get the review | ||
review=$(echo $response | jq -r '.choices[].text') | ||
# Post the review as a comment on the pull request | ||
curl -s -X POST -H "Authorization: Bearer $GITHUB_TOKEN" -H "Content-Type: application/json" -d "{\"body\": \"$review\"}" "https://api.github.com/repos/${{ github.repository }}/issues/${PR_NUMBER}/comments" | ||
done | ||
OPENAI_API_KEY: ${{ secrets.CHATGPT_API_KEY }} | ||
# Optional | ||
LANGUAGE: English | ||
MODEL: gpt-3.5-turbo | ||
# top_p: 1 | ||
# temperature: 1 |