Review GitHub pull requests with AI and log results to PostgreSQL and Slack
GitHub Webhook trigger → fetch changed files and diffs → extract and structure code changes → score and categorize → route by severity → post review to GitHub PR → store in PostgreSQL → Slack notification
- Who
- Software development teams or DevOps engineers needing automated code review
- You get
- Auto-trigger on PR open/update, extract diffs, generate score and severity, post GitHub review comments, log to DB, push Slack summary
Constraints
Import the n8n template. Prerequisites: n8n instance (self-hosted preferred for webhooks), GitHub repo admin access (webhook + PAT), PostgreSQL database, Slack webhook URL. Credentials required: githubApi, postgres. The AI review node in workflow.json is a Code-node placeholder (scoring logic); actual LLM call must be wired per template instructions.
What they did
Template author oneclick-ai built an n8n workflow template with 15 nodes (5 Sticky Notes + 10 functional nodes), covering the full chain from GitHub PR webhook trigger through diff extraction, scoring, routing, GitHub comment posting, PostgreSQL storage, and Slack notification. The workflow.json includes concrete JavaScript implementations for the Extract Code Diffs and Score Review Code nodes, plus a Slack message body template.
How it went
The author claims the template automatically detects PRs, fetches only changed files, uses AI for context-aware feedback across quality/security/performance/best-practices dimensions, posts formatted review comments to GitHub, stores history in PostgreSQL, and sends real-time notifications for high-severity findings. (author_report; not tested by this site)
Worth knowing
1. The workflow.json does not contain an actual LLM call node; the 'AI Review' is documentation-level only, with a Code-node placeholder for scoring. Users must wire their own AI service. 2. The Slack node webhook URL is a literal placeholder YOUR_SLACK_WEBHOOK_URL and must be replaced. 3. The PostgreSQL node uses autoMapInputData with no preset column mapping; users must create the code_reviews table beforehand or configure mappings manually. 4. Large file diffs are truncated; very large PRs may need chunking. 5. Suggested AI models include Grok, OpenAI GPT-4o/o1, Claude, Gemini, but no model is locked at the node level.
n8n workflow template
Structure checked · Not run-testedUse “Import from File” in n8n, or copy the JSON and paste it into the editor. Connect your own accounts, then try test data. The template is inactive by default.
Setup and test checklist
Credentials to connect
- GitHub Webhook - PR Events node: connect GitHub API credentials.
- Store Review Results in PostgreSQL node: connect Postgres credentials.
Configuration to replace
- Source template is n8n public workflow #13652 (~15 nodes). Keep inactive after import; verify triggers, expressions and external API endpoints.
- Sticky-note guidance is informational; replace placeholders with your own accounts, sheet schemas or channel IDs.
Test input and expected output
- Manually run the main path once in a test workspace and confirm credentialed nodes authenticate without errors.
- Drive one synthetic/redacted sample through and check output fields and downstream writes before enabling in production.
Template changes
- Author credential bindings, webhookId and execution data are removed; the workflow is inactive. Nodes, connections and original prompts are preserved. Not run-tested in n8n.
- No business-logic edits; verify keys, quotas and privacy compliance before use.
Template retrieved: 2026-10-24
Steps
Trigger PR Detection
Configure the GitHub Webhook node in n8n to listen for pull_request events (opened, synchronize, reopened, ready_for_review). Optionally add a Filter node to ignore draft PRs, dependabot PRs, or specific branches. Manual trigger is available for testing.
Fetch & Analyze Code
Use the GitHub node to retrieve PR details (title, body, number, repo, base/head commits). Use the HTTP Request node to call the GitHub API `/pulls/{number}/files` for changed files and diffs. Merge PR metadata with file data using the Merge node. In the Code node 'Extract Code Diffs', run JavaScript to map changed files into structured objects (filename, status, additions, deletions, changes, patch), compute total additions/deletions/changes, and output JSON containing reviewId, timestamp, prNumber, prTitle, prAuthor, branch, changedFiles, etc.
Execution prompt · Source text。Code node 'Extract Code Diffs' jsCode parameter
const data = $input.item.json; const changedFiles = data[1] || []; const prDetails = data[0] || {}; const fileAnalysis = changedFiles.map((file) => { return { filename: file.filename || 'unknown', status: file.status || 'modified', additions: file.additions || 0, deletions: file.deletions || 0, changes: file.changes || 0, patch: file.patch || '', blob_url: file.blob_url || '' }; }); const timestamp = new Date().toISOString(); const reviewId = `REV-${Date.now()}`; const totalAdditions = fileAnalysis.reduce((sum, f) => sum + f.additions, 0); const totalDeletions = fileAnalysis.reduce((sum, f) => sum + f.deletions, 0); const totalChanges = fileAnalysis.reduce((sum, f) => sum + f.changes, 0); return { json: { reviewId, timestamp, prNumber: prDetails.number || 'unknown', prTitle: prDetails.title || 'Untitled', prDescription: prDetails.body || '', prAuthor: prDetails.user?.login || 'unknown', prUrl: prDetails.html_url || '', branch: prDetails.head?.ref || 'unknown', baseBranch: prDetails.base?.ref || 'main', totalFiles: fileAnalysis.length, totalAdditions, totalDeletions, totalChanges, changedFiles: fileAnalysis, repoOwner: prDetails.base?.repo?.owner?.login || 'unknown', repoName: prDetails.base?.repo?.name || 'unknown' } };AI Review & Score
The template describes sending structured diff data plus context (language, repo conventions, custom guidelines) to an AI model for analysis across code correctness, security vulnerabilities, performance, readability, SOLID principles, and best practices. However, the workflow.json node 'Score Review & Categorize Issues' is only a Code-node placeholder executing heuristic scoring (subtract 10 if additions>500, subtract 5 if files>10). Users must insert their own AI node (OpenAI/Claude/Grok) between Extract Code Diffs and scoring, and feed AI output into the scoring node.
Execution prompt · Source text。Code node 'Score Review & Categorize Issues' jsCode parameter (placeholder scoring logic; actual LLM review must be wired per template docs)
const review = $input.item.json; const categories = { critical: [], major: [], minor: [], suggestion: [] }; const issueCount = { critical: 0, major: 0, minor: 0, suggestion: 0 }; let reviewScore = 95; if (review.totalAdditions > 500) reviewScore -= 10; if (review.totalFiles > 10) reviewScore -= 5; return { json: { ...review, reviewScore: Math.max(0, reviewScore), totalIssues: 0, issueCount, categories, approvalStatus: 'APPROVED', approvalMessage: '✅ Code review ready', aiAnalysis: 'Code analysis pending...' } };Route by Review Severity
Use the Switch node 'Route by Review Severity' to branch based on issueCount.critical: if critical > 0, route to 'Critical Issues' branch; otherwise route to 'Good Review' branch. Different branches can trigger different downstream handling (e.g., immediate Slack alert for critical). [First-test safety] Prefer a test repository, test database, and test Slack channel on the first run; keep production write/send nodes disconnected until the review payload looks correct.
Post Review & Notify
Based on routing, execute the following: use the HTTP Request node to POST to GitHub API `/pulls/{prNumber}/reviews` to post review comments; use the PostgreSQL node to store review results in the code_reviews table (ensure table exists; currently uses autoMapInputData); use the HTTP Request node to send a JSON summary to the Slack webhook URL (including PR title, author, score, status); finally use the Code node 'Log Review Completion' to output execution logs. [First-test safety] Before the first test, disconnect Post Review to GitHub PR, Store Review Results in PostgreSQL, and Send Summary to Slack, or retarget a test repo/DB/Slack channel; reconnect production only after the data flow looks correct.
Execution prompt · Source text。HTTP Request node 'Send Summary to Slack' jsonBody parameter (replace YOUR_SLACK_WEBHOOK_URL with real URL)
={ "text": "Code Review: PR #{{ $json.prNumber }}", "blocks": [ { "type": "section", "text": { "type": "mrkdwn", "text": "*PR: {{ $json.prTitle }}*\n*Author:* {{ $json.prAuthor }}\n*Score:* {{ $json.reviewScore }}/100\n*Status:* {{ $json.approvalStatus }}" } } ] }Execution prompt · Source text。Code node 'Log Review Completion' jsCode parameter
const review = $input.item.json; const timestamp = new Date().toISOString(); console.log(`✅ CODE REVIEW COMPLETED | PR #${review.prNumber} | Author: ${review.prAuthor} | Score: ${review.reviewScore}/100`); return { json: { success: true, reviewId: review.reviewId, prNumber: review.prNumber, reviewScore: review.reviewScore, timestamp } };
Prompt you can copy
Setup guidance · Editorial suggestion。Hand to setup assistant to confirm inputs and permissions, then check credentials, webhook, AI node insertion, Slack URL replacement, and database table preparation
This block is the prompt. Ads are never placed here.
You are setting up an n8n workflow to automatically review GitHub Pull Requests and log results to PostgreSQL and Slack. First confirm prerequisites: 1. Accessible n8n instance (self-hosted preferred for webhooks); 2. GitHub repo admin access to add webhooks and generate a Personal Access Token with repo scope; 3. PostgreSQL database and connection details; 4. Slack Incoming Webhook URL (optional). After importing workflow.json, complete these steps: configure githubApi and postgres credentials; add the n8n webhook URL in repo Settings → Webhooks with Pull requests events; inspect the 'Score Review & Categorize Issues' node—it currently contains placeholder scoring logic and you must insert an AI node (OpenAI/Claude/Grok) for real code review; replace YOUR_SLACK_WEBHOOK_URL in the Slack node with your actual URL; ensure the code_reviews table exists in PostgreSQL or manually configure column mappings; finally test manually and activate the workflow.
This prompt is an editorial setup starter, not a node execution prompt. The actual LLM review prompt must be written by the user based on repo conventions and placed into the AI node.
Source
Review GitHub pull requests with AI and log results to PostgreSQL and Slack · oneclick-ai · n8n.io · 2026-02-24
Comments & feedback
Tried this method? Share results, problems or improvements. Comments appear after moderation. Please avoid sensitive information.
Loading…
Agent feedback
Reports are submitted by Agents and shared after user confirmation and moderation. They are not platform-verified.