providers

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 6, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package providers implements git platform-specific URL parsing and operations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BitbucketProvider

type BitbucketProvider struct{}

BitbucketProvider handles Bitbucket.org URLs

func NewBitbucketProvider

func NewBitbucketProvider() *BitbucketProvider

NewBitbucketProvider creates a new Bitbucket provider

func (*BitbucketProvider) Name

func (p *BitbucketProvider) Name() string

Name returns the provider identifier

func (*BitbucketProvider) ParseURL

func (p *BitbucketProvider) ParseURL(rawURL string) (string, string, string, error)

ParseURL extracts repository, ref, and path from Bitbucket URLs

Bitbucket URL patterns:

  • bitbucket.org/owner/repo
  • bitbucket.org/owner/repo/src/main/path/file.py
  • bitbucket.org/owner/repo/src/v1.0.0/src/components/

Key differences from GitHub/GitLab:

  • Uses /src/ instead of /blob/ or /-/blob/
  • Same path segment for both files and directories (no blob/tree distinction)

func (*BitbucketProvider) Supports

func (p *BitbucketProvider) Supports(url string) bool

Supports returns true if the URL contains bitbucket.org

type GenericProvider

type GenericProvider struct{}

GenericProvider handles unknown git platforms and raw git URLs This is a fallback provider that accepts any URL

func NewGenericProvider

func NewGenericProvider() *GenericProvider

NewGenericProvider creates a new generic provider

func (*GenericProvider) Name

func (p *GenericProvider) Name() string

Name returns the provider identifier

func (*GenericProvider) ParseURL

func (p *GenericProvider) ParseURL(rawURL string) (string, string, string, error)

ParseURL normalizes git URLs without attempting platform-specific parsing

Supported URL formats:

Since there's no standard format for ref/path in generic git URLs, this provider only returns the normalized base URL with empty ref and path.

func (*GenericProvider) Supports

func (p *GenericProvider) Supports(_ string) bool

Supports always returns true as this is the fallback provider

type GitHostingProvider

type GitHostingProvider interface {
	// Name returns the provider identifier ("github", "gitlab", "bitbucket", "generic")
	Name() string

	// Supports returns true if this provider can handle the given URL
	Supports(url string) bool

	// ParseURL extracts repository base URL, ref, and path from platform-specific URLs
	// Returns: (baseURL, ref, path, error)
	// - baseURL: The base repository URL (e.g., "https://github.com/owner/repo")
	// - ref: The branch, tag, or commit reference (empty string if not specified)
	// - path: The file or directory path within the repository (empty string if not specified)
	// - error: Any error encountered during parsing
	ParseURL(rawURL string) (string, string, string, error)
}

GitHostingProvider abstracts git hosting platform-specific operations

type GitHubProvider

type GitHubProvider struct{}

GitHubProvider handles GitHub and GitHub Enterprise URLs

func NewGitHubProvider

func NewGitHubProvider() *GitHubProvider

NewGitHubProvider creates a new GitHub provider

func (*GitHubProvider) Name

func (p *GitHubProvider) Name() string

Name returns the provider identifier

func (*GitHubProvider) ParseURL

func (p *GitHubProvider) ParseURL(rawURL string) (string, string, string, error)

ParseURL extracts repository, ref, and path from GitHub URLs This implementation maintains exact compatibility with the original ParseSmartURL from git_operations.go:179-191

func (*GitHubProvider) Supports

func (p *GitHubProvider) Supports(url string) bool

Supports returns true if the URL contains github.com Also supports GitHub Enterprise instances

type GitLabProvider

type GitLabProvider struct{}

GitLabProvider handles GitLab.com and self-hosted GitLab instances

func NewGitLabProvider

func NewGitLabProvider() *GitLabProvider

NewGitLabProvider creates a new GitLab provider

func (*GitLabProvider) Name

func (p *GitLabProvider) Name() string

Name returns the provider identifier

func (*GitLabProvider) ParseURL

func (p *GitLabProvider) ParseURL(rawURL string) (string, string, string, error)

ParseURL extracts repository, ref, and path from GitLab URLs

GitLab URL patterns:

  • gitlab.com/owner/repo
  • gitlab.com/owner/repo/-/blob/main/path/file.go
  • gitlab.com/owner/group/subgroup/repo/-/blob/v1.0.0/lib/util.go (nested groups)
  • gitlab.example.com/team/project/-/blob/dev/README.md (self-hosted)

Key differences from GitHub:

  • Uses /-/blob/ instead of /blob/ (note the dash!)
  • Supports nested groups with unlimited depth
  • Self-hosted instances are common

func (*GitLabProvider) Supports

func (p *GitLabProvider) Supports(url string) bool

Supports returns true if the URL is likely a GitLab URL Detection strategy: 1. Contains "gitlab.com" (gitlab.com URLs) 2. Contains "/-/blob/" or "/-/tree/" (GitLab-specific URL pattern)

type ProviderRegistry

type ProviderRegistry struct {
	// contains filtered or unexported fields
}

ProviderRegistry manages available git hosting providers with auto-detection

func NewProviderRegistry

func NewProviderRegistry() *ProviderRegistry

NewProviderRegistry creates a new registry with all supported providers

func (*ProviderRegistry) DetectProvider

func (r *ProviderRegistry) DetectProvider(url string) GitHostingProvider

DetectProvider returns the appropriate provider for the given URL If no specific provider matches, returns the generic fallback provider

func (*ProviderRegistry) ParseURL

func (r *ProviderRegistry) ParseURL(url string) (string, string, string, error)

ParseURL delegates URL parsing to the appropriate provider based on auto-detection Returns: (baseURL, ref, path, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL