Skip to content

Conversation

@konard
Copy link
Contributor

@konard konard commented Dec 9, 2025

Summary

Implements a Git Hosting Provider abstraction layer to support multiple git hosting platforms (GitHub, GitLab, BitBucket) through a unified interface.

Fixes #902

Features

  • Abstract GitHostingProvider base class defining the interface all providers must implement
  • Full GitHubProvider implementation using gh CLI with all methods working
  • Stub implementations for GitLabProvider (glab CLI) and BitBucketProvider (REST API)
  • Provider detection based on URL patterns with priority-based matching
  • Provider registry for managing and extending providers
  • URL parsing and normalization for all providers (handles different formats)
  • CLI tool preference with API fallback support built into the architecture

Architecture

File Description
src/git-hosting/provider.interface.mjs Abstract base class with JSDoc types
src/git-hosting/github.provider.mjs Full GitHub implementation using gh CLI
src/git-hosting/gitlab.provider.mjs GitLab stub (uses glab CLI)
src/git-hosting/bitbucket.provider.mjs BitBucket stub (REST API)
src/git-hosting/index.mjs Factory, registry, and exports
tests/test-git-hosting-providers.mjs 74 comprehensive tests

Key Methods in Provider Interface

// Provider information
getProviderInfo()           // Returns name, displayName, hostname, cliTool, etc.

// URL handling
isProviderUrl(url)          // Check if URL belongs to this provider
parseUrl(url)               // Parse URL into owner, repo, type, number, etc.
normalizeUrl(url)           // Convert any URL format to canonical HTTPS
buildUrl(options)           // Build URL from components

// Authentication
checkAuth()                 // Verify CLI/API authentication status
checkCliAvailable()         // Check if CLI tool is installed

// API operations (GitHub fully implemented, others stubbed)
getIssue(owner, repo, number)
getPullRequest(owner, repo, number)
createPullRequest(owner, repo, options)
getRepositoryInfo(owner, repo)

Usage Example

import { 
  detectProvider, 
  getProviderForUrl, 
  getProvider 
} from './src/git-hosting/index.mjs';

// Detect provider from URL
const info = detectProvider('https://gitlab.com/owner/repo/-/issues/123');
// { name: 'gitlab', hostname: 'gitlab.com' }

// Get provider instance for URL
const provider = getProviderForUrl('https://github.com/owner/repo');
const parsed = provider.parseUrl('https://github.com/owner/repo/issues/42');
// { valid: true, type: 'issue', owner: 'owner', repo: 'repo', number: 42 }

// Get provider by name
const github = getProvider('github');
const issue = await github.getIssue('owner', 'repo', 123);

Test Results

📊 Test Results: 74/74 passed
✅ All tests passed!

Tests cover:

  • Provider detection for all three providers
  • URL parsing (issues, PRs/MRs, repos, users)
  • URL building and normalization
  • Provider info retrieval
  • Rate limit error detection
  • Edge cases (invalid URLs, null inputs, etc.)

ESLint Configuration Update

Updated eslint.config.mjs to add argsIgnorePattern: '^_' for the no-unused-vars rule. This allows underscore-prefixed parameters in abstract methods and stub implementations, which is a standard pattern for intentionally unused parameters.

Next Steps (Future PRs)

  1. Complete GitLab and BitBucket provider implementations
  2. Migrate existing github.lib.mjs to use GitHubProvider
  3. Add self-hosted provider support (GitHub Enterprise, GitLab self-hosted)

🤖 Generated with Claude Code

Adding CLAUDE.md with task information for AI processing.
This file will be removed when the task is complete.

Issue: #902
@konard konard self-assigned this Dec 9, 2025
Implement a provider abstraction layer to support multiple git hosting
platforms (GitHub, GitLab, BitBucket) through a unified interface.

Features:
- Abstract GitHostingProvider base class defining the interface
- Full GitHubProvider implementation using `gh` CLI
- Stub implementations for GitLabProvider and BitBucketProvider
- Provider detection based on URL patterns
- Provider registry with priority-based URL matching
- URL parsing and normalization for all providers
- CLI tool preference with API fallback support

Architecture:
- src/git-hosting/provider.interface.mjs: Abstract base class
- src/git-hosting/github.provider.mjs: GitHub implementation
- src/git-hosting/gitlab.provider.mjs: GitLab stub (uses glab CLI)
- src/git-hosting/bitbucket.provider.mjs: BitBucket stub
- src/git-hosting/index.mjs: Factory, registry, and exports

Test Results: 74/74 tests pass

Also updates ESLint config to allow underscore-prefixed unused
parameters (standard pattern for abstract methods).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@konard konard changed the title [WIP] Add support for GitLab and BitBucket Add Git Hosting Provider abstraction layer (Issue #902) Dec 9, 2025
@konard konard marked this pull request as ready for review December 9, 2025 22:21
@konard
Copy link
Contributor Author

konard commented Dec 9, 2025

🤖 Solution Draft Log

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost estimation:

  • Public pricing estimate: $9.430784 USD
  • Calculated by Anthropic: $8.040491 USD
  • Difference: $-1.390293 (-14.74%)
    📎 Log file uploaded as GitHub Gist (1653KB)
    🔗 View complete solution draft log

Now working session is ended, feel free to review and add any feedback on the solution draft.

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.

Add support for GitLab and BitBucket

2 participants