Engineering teams, code reviewers, and tech leads who want to automate code review feedback. Ideal for repositories with high PR volume where consistent first-pass review is valuable.
This workflow automates pull request code review using GPT-4o and routes findings to GitHub and Slack. When a pull request is opened, it fetches the raw diff, sends it to GPT-4o for analysis, and posts a formatted Markdown comment with severity rating, categorized issues, suggestions, and an overall score. Critical findings trigger immediate Slack alerts.
GITHUB_OWNER, GITHUB_REPO, and GITHUB_TOKENAdjust the diff truncation limit (default 12,000 chars) in the Format PR Diff node. Modify the GPT-4o system prompt to focus on specific code quality concerns like security or performance. Update Slack channel routing based on your team's notification policy.
| # | Node Name | Type | Purpose |
|---|---|---|---|
| 1 | When PR Opened | GitHub Trigger | Receives pull_request webhook events |
| 2 | Check PR Open | If | Passes only action = opened to avoid duplicates |
| 3 | Fetch PR Diff | HTTP Request | Fetches the raw unified diff from GitHub |
| 4 | Format PR Diff | Code | Extracts PR metadata; truncates diff to 12,000 chars |
| 5 | AI Code Review with GPT-4 | OpenAI | Sends diff to GPT-4o; returns structured JSON review |
| 6 | Build Comment for GitHub | Code | Parses JSON; assembles Markdown comment |
| 7 | Post Comment to GitHub | GitHub | Posts the AI review comment on the pull request |
| 8 | Check Critical Severity | If | Routes based on CRITICAL vs non-critical severity |
| 9 | Alert Critical Issues to Slack | Slack | Sends urgent alert to #incident |
| 10 | Share Review Summary on Slack | Slack | Sends summary notification to #code-reviews |
Total: 10 nodes (+ 5 Sticky Notes)
| # | Sticky Note Title | Color | Role |
|---|---|---|---|
| 1 | Main Sticky Note (Overview) | Yellow | Workflow overview, How it works, Setup steps, Customization |
| 2 | Trigger and filter PR | White | Covers GitHub trigger and PR filter |
| 3 | Fetch and format diff | White | Covers diff retrieval and formatting |
| 4 | AI review and comment | White | Covers AI review and comment building |
| 5 | Severity check and alerts | White | Covers severity routing and Slack notifications |
All sticky notes use H2 headings (## ) and follow n8n public guidelines.
ai gpt-4 openai github slack code-review devops automation