Overview
Nectr integrates deeply with GitHub to provide automated PR reviews. The integration consists of three main components:- GitHub OAuth - Secure authentication flow for user login
- REST API Client - Fetches PR diffs, files, and posts review comments
- Webhook Manager - Installs per-repo webhooks to receive PR events in real-time
Authentication
GitHub OAuth Flow
Users authenticate via GitHub OAuth to grant Nectr access to their repositories.1
User initiates login
User clicks “Login with GitHub” on the frontend
2
OAuth redirect
User is redirected to GitHub authorization page with configured scopes
3
Callback handling
GitHub redirects back to
/auth/github/callback with authorization code4
Token exchange
Backend exchanges code for access token and stores it encrypted with Fernet (AES-128-CBC)
Token Management
The GitHub client supports two authentication modes: User OAuth Token (Preferred)Required Environment Variables
The
GITHUB_PAT is optional in production when using OAuth tokens. It’s primarily used as a fallback or for development with the gh CLI.GitHub REST API Client
TheGithubClient class (app/integrations/github/client.py:38) provides async methods for all GitHub operations.
Fetching PR Data
Posting Reviews
Repository Queries
PR State Caching
The client implements an LRU + TTL cache for PR state checks:Webhook Management
The webhook manager (app/integrations/github/webhook_manager.py:10) handles per-repo webhook lifecycle.
Installing Webhooks
Uninstalling Webhooks
Webhook Receiver
The webhook endpoint (/api/v1/webhooks/github) receives events from GitHub and triggers PR reviews.
Signature Verification
Event Processing Flow
1
Webhook received
GitHub POSTs to
/api/v1/webhooks/github with event payload2
Signature verification
Verify
X-Hub-Signature-256 header using per-repo webhook secret3
Event deduplication
Check if identical event was processed within last hour (prevents duplicate reviews)
4
Event persisted
Create
Event row with status=“pending”5
Return 200 immediately
GitHub has 10-second timeout, AI review takes 30-60 seconds
6
Background processing
process_pr_in_background() runs asynchronously:- Fetch PR data via GitHub API
- Pull MCP context (Linear issues, Sentry errors)
- Build Neo4j + Mem0 context
- Run AI review
- Post review comment back to GitHub
- Index PR in knowledge graph
- Extract and store memories
Handling User OAuth Tokens
This approach means Nectr posts reviews as the user who connected the repo, not as a bot account. The review appears to come from your GitHub account.
Usage Example
Here’s how the GitHub integration is used in the PR review flow:API Rate Limits
Rate Limit Headers
GitHub includes rate limit info in every response:Troubleshooting
Webhook Not Receiving Events
-
Check webhook status in GitHub repo settings
- Go to
Settings → Webhooks - Click on your webhook
- Check “Recent Deliveries” for failed attempts
- Go to
-
Verify webhook secret matches
-
Test webhook endpoint manually
Reviews Not Posting
-
Check OAuth token validity
-
Verify repo permissions
- OAuth token needs
reposcope for private repos - PAT needs
reposcope
- OAuth token needs
-
Check API response for errors
Related Files
app/integrations/github/client.py:38- GithubClient implementationapp/integrations/github/webhook_manager.py:10- Webhook install/uninstallapp/api/v1/webhooks.py:41- Webhook receiver endpointapp/auth/router.py- OAuth flowapp/auth/token_encryption.py- Token encryption utilities