v2.0.0-alpha.5: GitHub App Integration - #135
Merged
Merged
Conversation
Phase 1 design covering GitHub App infrastructure, OAuth replacement, webhook sync, and installation token management. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Add GitHubAppInstallation model and GitHubInstallationStatus enum - Add GitHub App environment variables (GITHUB_APP_ID, GITHUB_APP_PRIVATE_KEY, GITHUB_APP_WEBHOOK_SECRET) - Add GitHub App service with JWT generation, token caching, and webhook verification - Add repository layer for installation CRUD operations - Add installation callback route with ownership verification - Add webhook endpoint for installation events (created/deleted/suspend/unsuspend) - Update plan document with identity vs authorization design decisions~
- Add settings page with GitHub integration status - Add Import dialog with 3-step flow (identity → app → repo) - Add callback page for popup-based installation flow - Add Server Actions for GitHub data fetching - Add NEXT_PUBLIC_GITHUB_APP_NAME env variable - Improve private key resolution for PEM/base64 formats
…th flow Phase 3 completed: Migrated to Octokit and merged authentication and authorization flow ## Completed Work ### 1. Migrate to Octokit - Replace manual JWT signing with @octokit/app - Octokit automatically manages installation token caching - Use @octokit/webhooks for webhook signature verification ### 2. Merge OAuth Flow - Implement GitHub App OAuth flow (enabled "Request user authorization during installation") - Add exchangeCodeForUserToken() to handle OAuth code exchange - Add refreshUserToken() to handle token refresh - Callback creates both UserIdentity and GitHubAppInstallation ### 3. Fix Critical Issues - Fix callback returning JSON instead of HTML page - Fix OAuth token exchange using wrong endpoint (404 error) - Fix frontend still using deprecated checkGitHubIdentity() - Fix GitHub App missing Callback URL configuration ### 4. Frontend Optimization - Remove deprecated checkGitHubIdentity() call - Use installations.length directly to check connection status - Simplify logic to align with Phase 3 design goals ## Modified Files - lib/services/github-app.ts - Migrate to Octokit, fix OAuth token exchange - app/api/github/app/callback/route.ts - Handle OAuth flow, return HTML page - app/api/github/app/webhook/route.ts - Use @octokit/webhooks - components/github/github-status-card.tsx - Remove deprecated function call - lib/env.ts - Add GITHUB_APP_CLIENT_ID and GITHUB_APP_CLIENT_SECRET - docs/plans/2026-02-25-github-app-integration-plan.md - Update progress documentation ## Verification Results - ✅ Lint check passed - ✅ Build successful - ✅ GitHub App installation flow works correctly - ✅ OAuth code exchange successful - ✅ UserIdentity and GitHubAppInstallation created correctly - ✅ Popup closes automatically - ✅ Frontend state updates correctly ## Next Steps Phase 4: Data Migration - Populate new fields when users re-associate repos
- Redefine Phase 4 as 'Code Migration' instead of 'Data Migration' - Add detailed implementation steps for updating frontend components - Add backward compatibility strategy with fallback logic - Mark Phase 5 as optional with clear timing recommendations - Add estimated workload: 1-2 hours for Phase 4 Key changes: - Phase 4: Update frontend code to use new fields with fallback - Phase 5: Optional cleanup, can be deferred or skipped~
- Update repo-status-indicator to prioritize new GitHub fields with fallback - Update GitHub page to use new field strategy - Update repoService to save both new and legacy fields - Remove planning documents - Bump version to 2.0.0-alpha.5 Closes #115
✅ PR Check Results: PassedBuild Checks
✨ Great work!All checks passed successfully. Your PR is ready for review. Details:
🔗 View Details: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
GitHub App Integration
Summary
This PR implements GitHub App integration to replace the legacy GitHub OAuth approach for repository operations. The integration provides better security, fine-grained permissions, and a streamlined user experience.
Changes
Phase 1: Backend Infrastructure ✅
GitHubAppInstallationmodel and new GitHub fields onProject(githubAppInstallationId,githubRepoId,githubRepoFullName)lib/services/github-app.tswith JWT generation, installation token caching, and webhook signature verificationlib/repo/github.tsfor installation CRUD and project-repo linkingapp/api/github/app/callback/route.ts- Handles GitHub App installation callback with ownership verificationapp/api/github/app/webhook/route.ts- Processes installation lifecycle events (created/deleted/suspend/unsuspend)Phase 2: Frontend UI ✅
app/settings/page.tsxwith GitHub integration statuscomponents/dialog/import-github-dialog.tsxwith 3-step flow (GitHub identity → GitHub App → Repo selection)components/github/github-status-card.tsx- GitHub connection statuscomponents/github/repo-selector.tsx- Searchable repo selectorcomponents/github/installation-list.tsx- Installation managementPhase 3: Octokit + Merged OAuth ✅
@octokit/restand@octokit/appgithub.com/login/oauth/access_tokeninstead of API route)postMessagefor popup communication)Phase 4: Code Migration ✅
components/layout/repo-status-indicator.tsxto prioritize new fields with fallbackapp/(dashboard)/projects/[id]/github/page.tsxwith new field strategylib/services/repoService.ts:createGithubRepo()returnsrepoIdandrepoFullNameinitializeRepo()saves both new and legacy fieldspushToGithub()usesgithubRepoFullName || githubRepopatternBackward Compatibility
The implementation follows an expand-contract migration strategy:
githubRepo) continues to workUser Flow
Environment Variables Required
Testing
Remaining Work (Phase 5 - Optional)
Phase 5 (Cleanup) is optional and can be deferred:
githubRepofield from schemaThis can be done after 3-6 months when legacy data is no longer needed.