refactor: add SourceControlProvider interface for GitHub#68
Conversation
Introduces a pluggable abstraction for source control platforms (GitHub, with future support for GitLab/Bitbucket) through the SourceControlProvider interface. Changes: - Add source-control module with types, errors, and token manager - Implement GitHubSourceControlProvider with getRepository(), createPullRequest(), and generatePushAuth() methods - Refactor handleCreatePR in SessionDO to use the new provider - Organize files: types.ts, errors.ts, providers/constants.ts, providers/types.ts following codebase conventions The provider properly handles merged PR state detection and fails early when push auth generation fails (rather than attempting a doomed push).
Terraform Validation Results
Pushed by: @ColeMurray, Action: |
Greptile OverviewGreptile SummaryIntroduced a pluggable Key changes:
The refactoring maintains all existing functionality while improving testability and enabling future GitLab/Bitbucket support. |
Move token decryption to the session layer where it belongs: - Remove SourceControlTokenManager interface and token-manager.ts - Simplify SourceControlAuthContext to use plain token instead of encrypted - Session layer now decrypts tokens before calling provider methods - Provider is now a pure API client with no encryption concerns This improves separation of concerns: - Session layer: storage, encryption, token refresh - Provider: API calls with plain tokens Also simplifies testing - providers can be tested with plain token strings without needing to mock encryption.
There was a problem hiding this comment.
Pull request overview
This PR introduces a pluggable SourceControlProvider abstraction layer to enable future support for multiple source control platforms (GitLab, Bitbucket). The initial implementation includes a GitHub provider that wraps existing GitHub API functionality.
Changes:
- Adds
source-controlmodule with provider interface, types, error handling, and token management - Implements
GitHubSourceControlProviderwith repository info retrieval, PR creation, and push authentication - Refactors
SessionDO.handleCreatePRto use the new provider interface with improved error handling
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
source-control/types.ts |
Core interfaces defining the provider abstraction, including capabilities, repository info, auth contexts, and PR configuration |
source-control/errors.ts |
Error classification system distinguishing transient (retryable) from permanent errors |
source-control/token-manager.ts |
Token encryption/decryption wrapper implementing the SourceControlTokenManager interface |
source-control/providers/types.ts |
Provider-specific configuration types, starting with GitHubProviderConfig |
source-control/providers/constants.ts |
Shared constants for API base URLs and user-agent strings |
source-control/providers/github-provider.ts |
GitHub implementation with repository queries, PR creation, labels, reviewers, and push auth generation |
source-control/providers/index.ts |
Provider factory exports |
source-control/index.ts |
Main module exports consolidating types, errors, token manager, and providers |
session/durable-object.ts |
Integration of the source control provider with lazy initialization, improved error handling, and early failure when push auth generation fails |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Terraform Validation Results
Pushed by: @ColeMurray, Action: |
Remove speculative generality - capabilities were declared but never checked anywhere in the codebase. Following YAGNI: add capability checks when a second provider (GitLab/Bitbucket) is actually implemented.
Terraform Validation Results
Pushed by: @ColeMurray, Action: |
File was not imported anywhere after migration to SourceControlProvider. Functions like getPullRequestByHead, updatePullRequest, addPRComment can be added to the provider interface if needed in the future.
Terraform Validation Results
Pushed by: @ColeMurray, Action: |
Add section comments distinguishing user-authenticated operations (getRepository, createPullRequest) from app-authenticated operations (generatePushAuth). Explains why generatePushAuth() doesn't take an auth parameter - it uses app credentials configured at construction.
Terraform Validation Results
Pushed by: @ColeMurray, Action: |
Use fetchWithTimeout (60s timeout) instead of raw fetch() to prevent hung GitHub API requests from blocking the Durable Object indefinitely. Consistent with existing pattern in auth/github-app.ts.
Terraform Validation Results
Pushed by: @ColeMurray, Action: |
Summary
Introduces a pluggable
SourceControlProviderinterface for source control platforms, with an initial GitHub implementation. This establishes the abstraction layer for future GitLab/Bitbucket support.source-controlmodule with types, errors, and token managerGitHubSourceControlProviderwithgetRepository(),createPullRequest(), andgeneratePushAuth()methodshandleCreatePRinSessionDOto use the new provider interfacetypes.ts,errors.ts,providers/constants.ts,providers/types.tsKey Design Decisions
SourceControlProvidermatches existingSandboxProviderpatterntransientvspermanenterrors for future retry logicBug Fixes (from code review)
state: "closed"withmerged: true)Test plan
npm run typecheck -w @open-inspect/control-plane)npm run lint -w @open-inspect/control-plane)