Automated PR Code Reviews with GitHub, GPT-4, and Google Sheets Best Practices
AI-Agent Code Review for GitHub Pull Requests
Description:
This n8n workflow automates the process of reviewing code changes in GitHub pull requests using an OpenAI-powered agent.
It connects your GitHub repo, extracts modified files, analyzes diffs, and uses an AI agent to generate a code review based on your internal code best practices (fed from a Google Sheet).
It ends by posting the review as a comment on the PR and tagging it with a visual label like β Reviewed by AI.
π§ What It Does Triggered on PR creation
Extracts code diffs from the PR
Formats and feeds them into an OpenAI prompt
Enriches the prompt using a Google Sheet of Swift best practices
Posts an AI-generated review as a comment on the PR
Applies a PR label to visually mark reviewed PRs
β Prerequisites Before deploying this workflow, ensure you have the following:
n8n Instance (Self-hosted or Cloud) GitHub Repository with PR activity OpenAI API Key** for GPT-4o, GPT-4-turbo, or GPT-3.5 GitHub OAuth App** (or PAT) connected to n8n to post comments and access PR diffs (Optional) Google Sheets API credentials if using the code best practices lookup node. βοΈ Setup Instructions
-
Import the Workflow in n8n, click on Workflows β Import from file or JSON Paste or upload the JSON code of this template
-
Configure Triggers and Connections
π GitHub Trigger
Node**: PR Trigger Repository**: Select the GitHub repo(s) to monitor Events**: Set to pull_request Auth**: Use GitHub OAuth2 credentials
π₯ HTTP Request
Node: Get file's Diffs from PR
No authentication needed; it uses dynamic path from trigger
π§ OpenAI Model Node**: OpenAI Chat Model
Model**: Select gpt-4o, gpt-4-turbo, or gpt-3.5-turbo
Credential**: Provide your OpenAI API Key
π§βπ» Code Review Agent Node : Code Review Agent Connected to OpenAI and optionally to tools like Google Sheets
π¬ GitHub Comment Poster
Uses GitHub API to post review comments back on PR Node: GitHub Robot Credential: Use the agent Github account (OAuth or PAT) Repo : Pick your owen Github Repository
π·οΈ PR Labeler (optional) Adds label ReviewedByAI after successful comment
Node: Add Label to PR Label : you ca customize the label text of your owen tag.
π Google Sheet Best Practices config (optional) Connects to a Google Sheet for coding guideline lookups, we can replace Google sheet by another tool or data base
First prepare your best practices list with the clear description and the code bad/good examples Add al the best practices in your Google Sheet Configure* the Code Best Practices node* in the template : Credential : Use your Google Sheet account by OAuth2 URL : Add your Google Sheet document URL Sheet : Add the name of the best practices sheet
Related Templates
Get Airtable data via AI and Obsidian Notes
I am submitting this workflow for the Obsidian community to showcase the potential of integrating Obsidian with n8n. Whi...
Task Deadline Reminders with Google Sheets, ChatGPT, and Gmail
Intro This template is for project managers, team leads, or anyone who wants to automatically remind teammates of tasks ...
Use OpenRouter in n8n versions <1.78
What it is: In version 1.78, n8n introduced a dedicated node to use the OpenRouter service, which lets you to use a lot...
π Please log in to import templates to n8n and favorite templates
Workflow Visualization
Loading...
Preparing workflow renderer
Comments (0)
Login to post comments