A collection of ChatGPT assistants, e.g., code viewer, labeler, assigner, etc.
There're already many chatgpt-actions, why we need to reinvent the wheel?
-
Leave too much comments on Github pull requests
Some of existing actions send each hunks in a pull request diff to ChatGPT, and yields a comment (or comment snippet) for each hunk. That makes them in practically unusable, as receiving 20+ email notification after submitting a pull request is not a good experience. For the reviewer's perspective, we usually just focus on the hunks that are "too good" or "too bad".
This actions take such experience into consideration, and only leave comments for the hunks that are not "LGTM". (We do have an option to leave comments for good hunks as well).
-
Lack of customization of the prompt
All of existing actions hard-coded the prompt template inside the source code and there's no chance to customize the prompt. When the built-in prompt is not good enough, ChatGPT responses with useless comments.
At the same time, someone may have good prompt ideas, he/she want to try using ChatGPT as an AI assistant for code quality evaluation and review, but he/she needs to reinvent the wheel for a new action to play on Github.
This action makes the prompt template configurable. With a set of variables like
$title
,$description
,$filename
,$patch
, you can customize the message sent to ChatGPT for better experience.Prompt engineering is an art to make ChatGPT success, we encourage the community to try discovering new, novel, and insightful prompts to make ChatGPT do code review job better, without reinventing the wheel for another chatgpt-action.
ANY SUGGESTIONS AND IMPROVEMENTS ARE HIGHLY APPRECIATED!!!
-
Code review your pull requests
- uses: jschmid1/chatgpt-action@main env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} with: debug: false action: review review_comment_lgtm: true
-
Customizable prompt templates
- uses: jschmid1/chatgpt-action@main env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} with: debug: false action: review review_patch: | Hi ChatGPT, I have a pull request with title "$title" and the description is as follows, > $description This is the patch > $patch and here are the filenames: > $filename Do something custom with these
name: Code Review
permissions:
contents: read
pull-requests: write
on:
pull_request:
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
repository: ${{github.event.pull_request.head.repo.full_name}}
ref: ${{github.event.pull_request.head.ref}}
submodules: false
- uses: jschmid1/chatgpt-action@main
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
with:
debug: false
action: review
review_comment_lgtm: true
See also: ./action.yml
GITHUB_TOKEN
OPENAI_API_KEY
: use this to authenticate with OpenAI API, official ChatGPT's API.
action
: The action to run, currently can bereview
debug
: Enable debug mode, will show messages and responses between ChatGPT server in CI logs.review_comment_lgtm
: Leave comments even the patch is LGTMpath_filters
: Rules to filter files to be reviewed.
See also: ./action.yml
review_beginning
: The beginning prompt of a code review dialogreview_patch
: The prompt for each chunks/patches
-
code review (
action: review
):$title
: Title of the pull requests.$description
: The description of the pull request.$filename
: Filename of the file being viewed.$patch
: The diff contents of the patch being viewed.
Any suggestions or pull requests for improving the prompts are highly appreciated.
First, you'll need to have a reasonably modern version of
node
handy, tested with node 16.
Install the dependencies
$ npm install
Build the typescript and package it for distribution
$ npm run build && npm run package
Github Actions limits the access of secrets from forked repositories. To enable
this feature, you need to use the pull_request_target
event instead of
pull_request
in your workflow file. Note that with pull_request_target
, you
need extra configuration to ensure checking out the right commit:
name: Code Review
permissions:
contents: read
pull-requests: write
on:
pull_request_target:
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
repository: ${{github.event.pull_request.head.repo.full_name}}
ref: ${{github.event.pull_request.head.ref}}
submodules: false
- uses: jschmid1/chatgpt-action@main
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
with:
debug: false
action: review
review_comment_lgtm: true
Set debug: true
in the workflow file to enable debug mode, which will show the messages
The MIT License (MIT), Courtesy to Tao He for most of the base code and the inspiration.