From 3ba54d2bbb652c282753a165025fee4c59b157b4 Mon Sep 17 00:00:00 2001 From: Thanasis Politis Date: Sat, 25 Mar 2023 22:16:34 +0200 Subject: [PATCH 1/4] Added new endpoint reverse_2 --- main.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/main.go b/main.go index daf3b09..322dd84 100644 --- a/main.go +++ b/main.go @@ -39,5 +39,13 @@ func main() { fmt.Fprintf(w, "Hello, %s!\n", reversed) }) + http.HandleFunc("/reverse_2", func(w http.ResponseWriter, r *http.Request) { + reversed, err := reverser.Reverse(r.Context(), r.URL.Query().Get("name")) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + } + fmt.Fprintf(w, "Hello, %s!\n", reversed) + }) + http.Serve(lis, nil) } From 3d06e71917f92574e4f4171ab3163e4d5a19222c Mon Sep 17 00:00:00 2001 From: Thanasis Politis Date: Sat, 25 Mar 2023 23:15:31 +0200 Subject: [PATCH 2/4] Let's not reinvent the wheel, there is already a plugin for it --- .github/workflows/main.yml | 49 ++++++++++---------------------------- 1 file changed, 13 insertions(+), 36 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 1a2b569..b412c5a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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 From 8ca888f01bd4d4a620059782edf106f117c01f0d Mon Sep 17 00:00:00 2001 From: Thanasis Politis Date: Sat, 25 Mar 2023 23:17:45 +0200 Subject: [PATCH 3/4] Revert code to the main branch version --- main.go | 8 -------- 1 file changed, 8 deletions(-) diff --git a/main.go b/main.go index 322dd84..daf3b09 100644 --- a/main.go +++ b/main.go @@ -39,13 +39,5 @@ func main() { fmt.Fprintf(w, "Hello, %s!\n", reversed) }) - http.HandleFunc("/reverse_2", func(w http.ResponseWriter, r *http.Request) { - reversed, err := reverser.Reverse(r.Context(), r.URL.Query().Get("name")) - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - } - fmt.Fprintf(w, "Hello, %s!\n", reversed) - }) - http.Serve(lis, nil) } From 518dc8d42aa1e64467cfd345dd648f0f4bfa59df Mon Sep 17 00:00:00 2001 From: Thanasis Politis Date: Sat, 25 Mar 2023 23:19:02 +0200 Subject: [PATCH 4/4] Adding new function again to test the bot actions --- main.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/main.go b/main.go index daf3b09..322dd84 100644 --- a/main.go +++ b/main.go @@ -39,5 +39,13 @@ func main() { fmt.Fprintf(w, "Hello, %s!\n", reversed) }) + http.HandleFunc("/reverse_2", func(w http.ResponseWriter, r *http.Request) { + reversed, err := reverser.Reverse(r.Context(), r.URL.Query().Get("name")) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + } + fmt.Fprintf(w, "Hello, %s!\n", reversed) + }) + http.Serve(lis, nil) }