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
.envfile in thesrcdirectory and add the following environment variables:OPENAI_API_KEY=<your-openai-api-key> GITHUB_TOKEN=<your-github-token>
-
Update the
mainfunction insrc/github.tsto 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 webhookbutton. - In the
Payload URLfield, enter the URL of your server (e.g.,http://your-server-url/webhook). - Set the
Content typetoapplication/json. - In the
Which events would you like to trigger this webhook?section, selectLet me select individual eventsand checkPull requests. - Click the
Add webhookbutton 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.
