Skip to main content

Overview

Nectr integrates deeply with GitHub to provide automated PR reviews. The integration consists of three main components:
  1. GitHub OAuth - Secure authentication flow for user login
  2. REST API Client - Fetches PR diffs, files, and posts review comments
  3. 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 code
4

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)
Personal Access Token (Fallback)

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

The GithubClient 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 payload
2

Signature verification

Verify X-Hub-Signature-256 header using per-repo webhook secret
3

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

GitHub’s API has rate limits:
  • Authenticated requests: 5,000/hour
  • Unauthenticated requests: 60/hour
The client uses authenticated requests (via OAuth token or PAT) to get the higher limit.

Rate Limit Headers

GitHub includes rate limit info in every response:
The client currently does not implement automatic rate limit handling. Consider adding:

Troubleshooting

Webhook Not Receiving Events

  1. Check webhook status in GitHub repo settings
    • Go to Settings → Webhooks
    • Click on your webhook
    • Check “Recent Deliveries” for failed attempts
  2. Verify webhook secret matches
  3. Test webhook endpoint manually

Reviews Not Posting

  1. Check OAuth token validity
  2. Verify repo permissions
    • OAuth token needs repo scope for private repos
    • PAT needs repo scope
  3. Check API response for errors
  • app/integrations/github/client.py:38 - GithubClient implementation
  • app/integrations/github/webhook_manager.py:10 - Webhook install/uninstall
  • app/api/v1/webhooks.py:41 - Webhook receiver endpoint
  • app/auth/router.py - OAuth flow
  • app/auth/token_encryption.py - Token encryption utilities