Automated PR code reviews with GitHub GPT 4 and Google Sheets
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...
🔌 Nodes & Integrations Used (6)
📖 Implementation & Setup Guide
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** 1. Triggered on PR creation
3. Extracts code diffs from the PR
5. Formats and feeds them into an OpenAI prompt
7. Enriches the prompt using a Google Sheet of Swift best practices
9. Posts an AI-generated review as a comment on the PR
11. 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
**1. Import the Workflow** in n8n, click on Workflows → Import from file or JSON Paste or upload the JSON code of this template
**2. 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
⚡ How to import this workflow into n8n:
- Click the Direct Download JSON button above to save
Automated_PR_code_reviews_with_GitHub_GPT_4_and_Google_Sheets.json. - Log in to your n8n Cloud or self-hosted n8n instance.
- In your workflow canvas, click the menu in top-right and select Import from File (or paste the JSON directly).
- Configure your credentials (e.g. API keys, database URLs) in the corresponding node settings.
- Click Execute Workflow to test and switch to Active!
Related AI Agents Workflows
View All in AI Agents →5 ways to process images PDFs with Gemini AI in n8n
How it works Many users have asked in the support forum about different methods to analyze images and PDF documents with Google Gemini AI in n8n. This workfl...
7 AI Sales Assistant
Production-ready n8n automation template for 7 AI Sales Assistant built by AhiXLight. Seamlessly connects Airtop Tool, Slack, Airtop with 24 configured nodes.
AAVE portfolio professional AI agent Telegram Email GPT 4o
A next-generation AI-powered DeFi health monitor that tracks wallet positions across Aave V3 using GPT-4o and LangChain. It delivers human-readable reports v...
Access control for AI agents RBAC using Airtable and Telegram
Purpose This workflow allows granular control over the access to tools connected to AI Agents (including Multi-Agent setups) using Role Based Access Control....