Automatically review pull requests and provide feedback using OpenAI, triggered by GitHub webhook, ensuring correctness, security and readability.
- Node.js (v14 or later)
- npm (v6 or later)
-
Clone the repository:
git clone https://github.com/cuongvng/code-review-assistant.git cd github-pr-webhook-listener
-
Install the dependencies:
npm install
-
Create a
.env
file in thesrc
directory and add the following environment variables:OPENAI_API_KEY=<your-openai-api-key> GITHUB_TOKEN=<your-github-token>
-
Update the
main
function insrc/github.ts
to handle the pull request event as needed.
-
Start the server:
npx tsx server.ts
-
Set up a webhook in the target GitHub repository:
- Go to the target repository on GitHub.
- Click on
Settings
. - In the left sidebar, click on
Webhooks
. - Click the
Add webhook
button. - In the
Payload URL
field, enter the URL of your server (e.g.,http://your-server-url/webhook
). - Set the
Content type
toapplication/json
. - In the
Which events would you like to trigger this webhook?
section, selectLet me select individual events
and checkPull requests
. - Click the
Add webhook
button to save the webhook.
From this PR
To make the server accessible to GitHub, you need to deploy it to a hosting service like Heroku, AWS, or any other cloud provider. Once deployed, use the deployed URL as the Payload URL
when setting up the webhook in the target repository.
This project is licensed under the MIT License. See the LICENSE file for details.