Skip to main content
POST
Connect Repository

Overview

Connects a repository to Nectr AI by installing a webhook and initiating background tasks to scan the repository structure and build a code knowledge graph. This is a one-click operation that uses the user’s existing OAuth token (with repo scope) - no GitHub redirect required.

Authentication

Requires a valid JWT token in the Authorization header.

Path Parameters

string
required
Repository owner (user or organization)
string
required
Repository name

Request

Response

string
Always returns "connected" on success
integer
Database ID of the newly created installation record
string
Full repository name in owner/repo format

Example Response

What Happens During Connection

1. Webhook Installation

A GitHub webhook is created on the repository with:
  • Events: pull_request, issues
  • Payload URL: {BACKEND_URL}/api/v1/webhooks/github
  • Secret: Randomly generated 64-character hex string
  • Content type: JSON
The webhook ID and secret are stored in the Installation record for later verification and cleanup.

2. Database Record Creation

An Installation record is persisted with:

3. Background Tasks (Async)

Two tasks are queued in the background: Project Scanner (scan_repo):
  • Fetches the repository file tree from GitHub
  • Analyzes project structure and dependencies
  • Identifies language, framework, and key files
Graph Builder (build_repo_graph):
  • Creates a Neo4j knowledge graph of the codebase
  • Indexes files with language and size metadata
  • Establishes Repository -[:CONTAINS]-> File relationships
These tasks run asynchronously and do not block the response.

Error Responses

Repository is already connected
JWT token is invalid, expired, or missing
GitHub OAuth token cannot be decrypted (SECRET_KEY changed)
Failed to install webhook on GitHub
Common causes:
  • User lacks admin permissions on the repository
  • OAuth token missing repo scope
  • GitHub API is unavailable

Permissions Required

GitHub OAuth Scopes

  • repo - Required to create webhooks and access repository contents

Repository Access

The authenticated user must have admin permissions on the repository to install webhooks.