n8n

How to Automate GitHub PR Code Review?

Pull requests pile up. This setup posts an AI code review on every new PR, adds a clear label, and follows your team rules from a Google Sheet. It helps engineering teams speed up reviews and keep a steady quality bar.

When a pull request opens, the GitHub event starts the run. The HTTP Request step collects changed files and diffs from the GitHub API. A Code step formats those diffs into a short, structured prompt. The OpenAI Chat Model powers a Code Review Agent that reads the prompt and your best practices from Google Sheets, then writes a helpful review. A GitHub action posts the comment to the PR and can apply a ReviewedByAI label for easy tracking. The flow reduces back and forth, makes feedback consistent, and shortens the time to merge.

You will need GitHub access, an OpenAI key, and a Google Sheet with your rules. Expect review time per PR to drop from about 30 minutes to under 5 minutes, with more consistent feedback across the team. Great for small teams, open source maintainers, and squads that triage many PRs each day.

What are the key features?

  • PR event trigger starts the run as soon as a pull request is opened or updated.
  • HTTP Request step fetches changed files and diffs from the GitHub API.
  • Code step formats diffs and filenames into a clean prompt for the AI.
  • OpenAI Chat Model generates a focused review based on the diffs.
  • Google Sheets tool lets the agent read your team’s best practices during review.
  • Agent composes practical comments with suggestions and risks.
  • GitHub action posts the review as a PR comment for the team to see.
  • Optional labeler marks the PR as ReviewedByAI for easy tracking.

What are the benefits?

  • Reduce manual review time from 30 minutes to 5 minutes per PR
  • Automate about 70% of first pass code checks
  • Improve guideline adherence by 50% using shared best practices
  • Speed up PR triage with automatic ReviewedByAI labels
  • Connect GitHub, OpenAI, and Google Sheets in one flow

How do you set it up?

  1. Import the template into n8n: Create a new workflow in n8n > Click the three dots menu > Select 'Import from File' > Choose the downloaded JSON file.
  2. You'll need accounts with GitHub, OpenAI and Google Sheets. See the Tools Required section above for links to create accounts with these services.
  3. Open the PR Trigger node. In the credential dropdown, click Create new credential and connect your GitHub account with OAuth. Fill in the repository owner and repository name. Make sure the event is pull_request.
  4. Open the GitHub Robot node. In the credential dropdown, create or select your GitHub API credential. Set the owner and repository. Keep the pull request number expression as provided. Ensure the operation posts a review comment.
  5. Open the Add Label to PR node. Use your GitHub OAuth credential. Set the repository and confirm the issue number expression. Keep the labels field to include ReviewedByAI.
  6. Open the HTTP Request node. If your repo is private, add an Authorization header with a GitHub token. For public repos this may not be needed. Keep the URL expression that reads files from the PR.
  7. Open the Code node that builds the prompt. Review the prompt text and adjust tone, severity, and coding focus to match your team standards. Save your changes.
  8. Open the OpenAI Chat Model node. Click Create new credential and paste your OpenAI API key. Choose the model set in the template or select another model if needed.
  9. Open the Google Sheets tool node. Click Create new credential and connect your Google account. Paste the Document ID and set the Sheet name that stores your rules and examples.
  10. Open the Code Review Agent node. Confirm it uses the OpenAI model and the Google Sheets tool. Save the workflow.
  11. Create a test PR in your GitHub repo. Watch the n8n execution. Confirm a review comment appears and the label is added.
  12. If the trigger does not fire, check the repo Webhooks page to confirm n8n registered a webhook and that n8n is reachable. Reconnect GitHub credentials if needed.
  13. If the comment is empty or truncated, limit large diffs or reduce file count in the Code node. If Google Sheets content is not read, verify the Document ID, Sheet name, and Google permission.

Tools Required

$24 / mo or $20 / mo billed annually to use n8n in the cloud. However, the local or self-hosted n8n Community Edition is free.

GitHub

Sign up

Free tier: $0 / mo

Google Sheets

Sign up

Free: $0 (Google Sheets API usage has no additional cost; quota limits apply)

OpenAI

Sign up

Pay-as-you-go: GPT-5 at $1.25 per 1M input tokens and $10 per 1M output tokens

Similar Templates

Join Futurise to access 1,200+ automation templates

Get instant access to ready-made automation workflows for n8n, Make.com, AI agents, and more. Download, customise, and deploy in minutes.