Skip to content

Conversation

@miles-kt-inkeep
Copy link
Contributor

No description provided.

miles-kt-inkeep and others added 21 commits January 26, 2026 15:27
Add three new tables to the runtime schema for tracking GitHub App installations:
- github_app_installations: Tracks installations linked to tenants with status tracking
- github_app_repositories: Stores repositories accessible through each installation
- github_project_repository_access: Links projects to specific repositories for fine-grained access control

Includes proper indexes, foreign key constraints with cascade deletes, and comprehensive tests.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add comprehensive data access layer for GitHub App installation management:

Installation management:
- createInstallation: Create new installation records
- getInstallationByGitHubId: Lookup by GitHub's installation ID
- getInstallationById: Lookup with tenant validation
- getInstallationsByTenantId: List tenant installations
- updateInstallationStatus: Update status by internal ID
- updateInstallationStatusByGitHubId: Update status by GitHub ID
- deleteInstallation: Soft delete with cleanup

Repository management:
- syncRepositories: Full sync (add/remove/update repos)
- addRepositories: Add repos (for webhook events)
- removeRepositories: Remove repos (for webhook events)
- getRepositoriesByInstallationId: List repos for installation
- getRepositoryByFullName: Find by org/repo name
- getRepositoryById: Find by internal ID
- getRepositoriesByTenantId: List all tenant repos
- getRepositoryCount: Count repos for installation

Project access functions:
- setProjectRepositoryAccess: Set/replace access list
- getProjectRepositoryAccess: Get access entries
- getProjectRepositoryAccessWithDetails: Get with repo details
- checkProjectRepositoryAccess: Check repo access permission
- clearProjectRepositoryAccess: Remove all access
- validateRepositoryOwnership: Validate repo ownership

Tests: 45 unit tests covering all functions

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add isWebhookConfigured() helper function to check if GITHUB_WEBHOOK_SECRET is set
- Add getWebhookSecret() function to retrieve the webhook secret with error handling
- Add validateGitHubWebhookConfigOnStartup() to log warning if webhook secret not configured
- Update .env.example with GITHUB_WEBHOOK_SECRET documentation
- Add comprehensive unit tests for config validation

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add GET /manage/tenants/:tenantId/github/install-url endpoint that:
- Generates a signed JWT state token containing tenantId with 10-minute expiration
- Uses GITHUB_STATE_SIGNING_SECRET for HS256 signing
- Returns URL to install the GitHub App with the state parameter
- Requires tenant authentication

New environment variables:
- GITHUB_STATE_SIGNING_SECRET: HS256 signing secret for state JWT (min 32 chars)
- GITHUB_APP_NAME: GitHub App name for installation URL generation

Includes:
- Config functions for state signing and app name validation
- 25 unit tests for config functions and endpoint behavior

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Implements GET /api/github/callback endpoint to handle GitHub App
installation redirects. Validates JWT state token, fetches installation
details from GitHub API, stores installation in database, and syncs
repositories.

Key features:
- State JWT validation with expiration and signature checks
- GitHub API integration for installation and repository fetching
- Database integration for installation creation/update
- Repository syncing with pagination support
- Redirect to Manage UI with success/error status

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Create POST /api/github/webhooks endpoint for receiving GitHub events
- Implement HMAC SHA-256 signature verification using GITHUB_WEBHOOK_SECRET
- Use timing-safe comparison to prevent timing attacks
- Parse X-GitHub-Event and X-GitHub-Delivery headers
- Return 401 for invalid/missing signature, 200 for unhandled events
- Add 18 comprehensive unit tests covering all verification scenarios

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Implement webhook event handlers for GitHub App installation lifecycle events:
- Handle 'installation' event: created (activate pending), deleted (soft delete),
  suspend (set suspended status), unsuspend (reactivate)
- Handle 'installation_repositories' event: added (add repos to DB),
  removed (remove repos and project access)
- All webhook events are logged for debugging
- Database errors return 200 to prevent GitHub retries
- Added 18+ unit tests for all event types and edge cases

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add GET /manage/tenants/:tenantId/github/installations endpoint to list
GitHub App installations connected to a tenant. Features:
- Returns array of installations with id, installationId, accountLogin,
  accountType, status, repositoryCount, createdAt, updatedAt
- Filters out deleted installations by default
- Supports includeDeleted=true query param to include deleted ones
- Fetches repository count for each installation
- OpenAPI documented with typed request/response schemas

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add DELETE /manage/tenants/:tenantId/github/installations/:installationId
endpoint for disconnecting GitHub App installations from a tenant.

- Soft deletes installation (sets status to 'deleted')
- Removes all project repository access entries for the installation's repos
- Does NOT uninstall the GitHub App from GitHub (user can do that separately)
- Returns 404 if installation not found or belongs to different tenant
- Added 8 unit tests covering success, 404, 500, and status variants

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Create POST /manage/tenants/:tenantId/github/installations/:installationId/sync
endpoint to manually refresh repository list from GitHub API.

- Uses createAppJwt() and fetchInstallationRepositories() to fetch repos
- Syncs database using syncRepositories() data access function
- Returns updated repository list with sync stats (added/removed/updated)
- Returns 404 for invalid installation, 503 for GitHub API failures
- Added 9 unit tests covering all scenarios

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Create PUT and GET endpoints for configuring project-level GitHub
repository access:

- GET /manage/tenants/:tenantId/projects/:projectId/github-access
  Returns current access configuration (mode='all' or 'selected' with
  repository list)

- PUT /manage/tenants/:tenantId/projects/:projectId/github-access
  Configures access mode and validates repository ownership

Features:
- mode='all' grants access to all tenant repositories
- mode='selected' scopes access to specific repository IDs
- Validates repository IDs belong to tenant's GitHub installations
- Full replacement of existing access entries (not incremental)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Validate GitHub App installation exists in our database before generating token
- Return 403 with descriptive error messages for each invalid status:
  - Not registered: "Please connect your GitHub organization in the Inkeep dashboard"
  - Pending: "GitHub App installation is pending organization admin approval"
  - Suspended: "GitHub App installation is suspended"
  - Deleted: "GitHub App installation has been disconnected"
- Include tenant_id in successful response metadata for future use
- Add optional project_id parameter to validate project-level repository access
- Add 7 new tests covering all validation scenarios

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Created API client functions in lib/api/github.ts for fetching installations, syncing repos, and disconnecting
- Created GitHub settings page at /[tenantId]/settings/github with:
  - Empty state when no installations exist
  - List of connected organizations with status badges
  - Actions dropdown for view details, sync repos, and disconnect
- Created GitHubInstallationsList component with table display
- Created GitHubInstallButton for initiating OAuth flow
- Created DisconnectInstallationDialog with confirmation
- Added SettingsNav component for sub-navigation between Organization and GitHub settings
- Updated settings layout to include navigation tabs
- Added component tests covering data types, status mapping, and navigation

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Create detail page at /[tenantId]/settings/github/[installationId]
- Display installation info: org name/avatar, account type/status badges,
  installation ID, connected date, last updated date
- Show pending status explanation when installation awaits approval
- List all repositories with name (link to GitHub), Public/Private badge,
  and full name
- Add Sync Repositories button to force refresh from GitHub API
- Add Disconnect button with existing confirmation dialog
- Add loading skeleton for async data fetching
- Add 14 component tests covering types, status display, visibility badges,
  URL generation, navigation, and date formatting

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…gs UI

- Add 'GitHub Access' section to project settings form with collapsible UI
- Create ProjectGitHubAccessSection component with:
  - Current access mode display ('All repositories' or list of selected repos)
  - 'Configure Access' dialog for mode selection
  - Multi-select interface for repositories grouped by installation
  - Sync button to refresh repos from GitHub API
- Add API functions: getProjectGitHubAccess(), setProjectGitHubAccess()
- Handle empty state when no GitHub installations are connected
- Reuse existing components: Dialog, RadioGroup, Checkbox, Badge, Table
- Add 17 unit tests for access mode logic and repository selection

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@changeset-bot
Copy link

changeset-bot bot commented Jan 27, 2026

🦋 Changeset detected

Latest commit: aa00b49

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 10 packages
Name Type
@inkeep/agents-api Patch
@inkeep/agents-manage-ui Patch
@inkeep/agents-cli Patch
@inkeep/agents-core Patch
@inkeep/agents-manage-mcp Patch
@inkeep/agents-mcp Patch
@inkeep/agents-sdk Patch
@inkeep/agents-workapps Patch
@inkeep/ai-sdk-provider Patch
@inkeep/create-agents Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link

vercel bot commented Jan 27, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
agents-api Ready Ready Preview, Comment Jan 29, 2026 2:21am
agents-docs Error Error Jan 29, 2026 2:21am
agents-manage-ui Ready Ready Preview, Comment Jan 29, 2026 2:21am

Request Review

@claude
Copy link

claude bot commented Jan 27, 2026

Claude finished @miles-kt-inkeep's task —— View job


GitHub App Management PR Review

Reviewing this comprehensive GitHub app integration feature implementation. This is a substantial PR with 14,836 additions across multiple domains.

Review Tasks:

  • Read repository setup instructions and understand codebase patterns
  • Analyze database schema changes and migration strategy
  • Review API endpoints and route implementations
  • Evaluate UI components and user experience flows
  • Check test coverage and test quality
  • Assess security implications and error handling
  • Review system architecture and design decisions
  • Provide comprehensive feedback and recommendations

Architecture & Design Assessment

Excellent Overall Structure

Database Design:

  • Three-table schema with clear separation of concerns and proper normalization
  • Tenant-scoped design consistent with existing patterns
  • Comprehensive indexes for performance optimization
  • Proper foreign key constraints with cascading deletes

API Design:

  • RESTful endpoints following OpenAPI patterns
  • Proper separation between GitHub domain and management domain
  • Consistent error handling and response structures
  • Good use of Zod validation schemas

Security Analysis

Strong Security Implementation

Webhook Security:

  • Proper HMAC-SHA256 signature verification with timing-safe comparison (/agents-api/src/domains/github/routes/webhooks.ts:22-59)
  • Defensive error handling that prevents information leakage
  • Returns 200 even on processing failures to prevent GitHub retries

OAuth Flow Security:

  • JWT state tokens with proper issuer/audience validation (/agents-api/src/domains/manage/routes/github.ts:47-60)
  • Short-lived tokens (10 minutes) for installation flow
  • Proper secret management through environment variables

GitHub App Authentication:

  • Correct JWT creation for GitHub App API authentication
  • Private key handling through environment configuration

Code Quality Assessment

High-Quality Implementation

Error Handling:

  • Comprehensive error boundaries with graceful degradation
  • Structured error responses with proper HTTP status codes
  • Defensive programming in webhook handlers
  • User-friendly error messages in UI components

TypeScript Usage:

  • Strong typing throughout with proper Zod schemas
  • Good use of generics and type inference
  • Consistent interface definitions

Testing Coverage:

  • 400+ test cases across GitHub functionality
  • Comprehensive webhook signature testing
  • Integration tests for setup flows
  • Mock strategies that maintain test isolation

Areas for Consideration

⚠️ Architecture Considerations

Race Condition Potential:
The setup callback (/agents-api/src/domains/github/routes/setup.ts:173-257) and webhook handlers (/agents-api/src/domains/github/routes/webhooks.ts:192-308) could theoretically race when processing the same installation. Consider adding database-level unique constraints or optimistic locking.

State Token Expiry:
10-minute expiry for installation state tokens may be too short for users who take time to review permissions. Consider 30 minutes or provide clear messaging about the time limit.

Repository Sync Strategy:
The current approach syncs all repositories on installation. For organizations with thousands of repositories, this could be expensive. Consider:

  • Pagination in the GitHub API calls
  • Async processing for large repository sets
  • Rate limiting considerations

⚠️ UI/UX Considerations

Loading States:
The UI properly handles loading states, but consider adding progress indicators for long-running sync operations (/agents-manage-ui/src/components/settings/github-installations-list.tsx:88-100).

Error Recovery:
When installations fail, users need clear guidance on how to retry or resolve issues. The current error handling is good but could benefit from more actionable error messages.


Missing Changeset

The changeset-bot correctly identified that this significant feature addition needs a changeset. Based on the scope, this should be a minor version bump since it adds new functionality:

pnpm bump minor --pkg agents-api --pkg agents-manage-ui "Add GitHub App integration for repository access management"

Final Assessment

This is a very well-executed feature implementation that demonstrates:

  • Strong security practices and proper authentication flows
  • Clean separation of concerns and consistent patterns
  • Comprehensive error handling and user experience consideration
  • Extensive test coverage with proper mocking strategies
  • Good TypeScript practices and type safety

The architecture choices are sound and the implementation follows the codebase's established patterns. The few areas for consideration are minor optimizations rather than fundamental issues.

Recommendation: Approved with minor suggestions for optimization


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants