provider

package
v0.0.0-...-bf360fe Latest Latest
Warning

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

Go to latest
Published: May 31, 2025 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package provider implements Git hosting provider interfaces for GitHub, GitLab, and Gerrit.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TestGitLabProviderAuthentication

func TestGitLabProviderAuthentication(t *testing.T)

TestGitLabProviderAuthentication tests authentication handling for GitLab provider

func TestGitLabProviderCreateFork

func TestGitLabProviderCreateFork(t *testing.T)

TestGitLabProviderCreateFork tests the CreateFork functionality for GitLab provider

func TestGitLabProviderListRepositories

func TestGitLabProviderListRepositories(t *testing.T)

TestGitLabProviderListRepositories tests the ListRepositories functionality for GitLab provider

func TestGitLabProviderRateLimitHandling

func TestGitLabProviderRateLimitHandling(t *testing.T)

TestGitLabProviderRateLimitHandling tests rate limit handling for GitLab provider

func TestNewGitLabProvider

func TestNewGitLabProvider(t *testing.T)

TestNewGitLabProvider tests the creation of new GitLab provider instances

Types

type Config

type Config struct {
	GitHubToken    string
	GitLabToken    string
	GerritUsername string
	GerritPassword string
	GerritToken    string
}

Config holds configuration for provider authentication

type GerritAccount

type GerritAccount struct {
	ID       int    `json:"_account_id"`
	Name     string `json:"name,omitempty"`
	Email    string `json:"email,omitempty"`
	Username string `json:"username,omitempty"`
}

GerritAccount represents a Gerrit account

type GerritClone

type GerritClone struct {
	URL string `json:"url"`
}

GerritClone represents clone information for a Gerrit project

type GerritProject

type GerritProject struct {
	ID          string                 `json:"id"`
	Name        string                 `json:"name"`
	Parent      string                 `json:"parent,omitempty"`
	Description string                 `json:"description,omitempty"`
	State       string                 `json:"state,omitempty"`
	Branches    map[string]string      `json:"branches,omitempty"`
	WebLinks    []GerritWebLink        `json:"web_links,omitempty"`
	CloneLinks  map[string]GerritClone `json:"clone_links,omitempty"`
}

GerritProject represents a Gerrit project

type GerritProvider

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

GerritProvider implements the Provider interface for Gerrit

func NewGerritProvider

func NewGerritProvider(baseURL, username, password string) (*GerritProvider, error)

NewGerritProvider creates a new Gerrit provider

func (*GerritProvider) Close

func (g *GerritProvider) Close() error

Close performs cleanup operations

func (*GerritProvider) CreateFork

func (g *GerritProvider) CreateFork(_ context.Context, _ *Repository, _ string) (*Repository, error)

CreateFork creates a new project based on an existing one (Gerrit doesn't have traditional forks)

func (*GerritProvider) CreateOrganization

func (g *GerritProvider) CreateOrganization(_ context.Context, _, _, _ string) (*Organization, error)

CreateOrganization creates a new organization (not applicable for Gerrit)

func (*GerritProvider) GetOrganization

func (g *GerritProvider) GetOrganization(ctx context.Context, orgName string) (*Organization, error)

GetOrganization retrieves Gerrit "organization" information (really just server info)

func (*GerritProvider) ListRepositories

func (g *GerritProvider) ListRepositories(ctx context.Context, orgName string) ([]*Repository, error)

ListRepositories lists all projects in a Gerrit server

func (*GerritProvider) Name

func (g *GerritProvider) Name() string

Name returns the provider name

func (*GerritProvider) ParseSource

func (g *GerritProvider) ParseSource(source string) (*SourceInfo, error)

ParseSource parses a Gerrit source URL or identifier

func (*GerritProvider) RepositoryExists

func (g *GerritProvider) RepositoryExists(ctx context.Context, orgName, repoName string) (bool, error)

RepositoryExists checks if a project exists in Gerrit

func (*GerritProvider) SyncRepository

func (g *GerritProvider) SyncRepository(_ context.Context, _ *Repository) error

SyncRepository synchronizes a repository (not applicable for Gerrit)

type GerritWebLink struct {
	Name string `json:"name"`
	URL  string `json:"url"`
}

GerritWebLink represents a web link for a Gerrit project

type GitHubProvider

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

GitHubProvider implements the Provider interface for GitHub

func NewGitHubProvider

func NewGitHubProvider(token, baseURL string) (*GitHubProvider, error)

NewGitHubProvider creates a new GitHub provider

func (*GitHubProvider) Close

func (g *GitHubProvider) Close() error

Close performs cleanup operations

func (*GitHubProvider) CreateFork

func (g *GitHubProvider) CreateFork(ctx context.Context, sourceRepo *Repository, targetOrg string) (*Repository, error)

CreateFork creates a fork of a repository in the target organization

func (*GitHubProvider) CreateOrganization

func (g *GitHubProvider) CreateOrganization(_ context.Context, _, _, _ string) (*Organization, error)

CreateOrganization creates a new GitHub organization (not supported by GitHub API)

func (*GitHubProvider) GetOrganization

func (g *GitHubProvider) GetOrganization(ctx context.Context, orgName string) (*Organization, error)

GetOrganization retrieves GitHub organization information

func (*GitHubProvider) ListRepositories

func (g *GitHubProvider) ListRepositories(ctx context.Context, orgName string) ([]*Repository, error)

ListRepositories lists all repositories in a GitHub organization

func (*GitHubProvider) Name

func (g *GitHubProvider) Name() string

Name returns the provider name

func (*GitHubProvider) ParseSource

func (g *GitHubProvider) ParseSource(source string) (*SourceInfo, error)

ParseSource parses a GitHub source URL or identifier

func (*GitHubProvider) RepositoryExists

func (g *GitHubProvider) RepositoryExists(ctx context.Context, orgName, repoName string) (bool, error)

RepositoryExists checks if a repository exists in a GitHub organization

func (*GitHubProvider) SyncRepository

func (g *GitHubProvider) SyncRepository(ctx context.Context, repo *Repository) error

SyncRepository synchronizes a forked repository with its upstream

type GitLabProvider

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

GitLabProvider implements the Provider interface for GitLab

func NewGitLabProvider

func NewGitLabProvider(token, baseURL string) (*GitLabProvider, error)

NewGitLabProvider creates a new GitLab provider

func (*GitLabProvider) Close

func (g *GitLabProvider) Close() error

Close performs cleanup operations

func (*GitLabProvider) CreateFork

func (g *GitLabProvider) CreateFork(ctx context.Context, sourceRepo *Repository, targetGroup string) (*Repository, error)

CreateFork creates a fork of a project in the target group

func (*GitLabProvider) CreateOrganization

func (g *GitLabProvider) CreateOrganization(ctx context.Context, groupName, displayName, description string) (*Organization, error)

CreateOrganization creates a new GitLab group

func (*GitLabProvider) GetOrganization

func (g *GitLabProvider) GetOrganization(ctx context.Context, groupName string) (*Organization, error)

GetOrganization retrieves GitLab group information

func (*GitLabProvider) ListRepositories

func (g *GitLabProvider) ListRepositories(ctx context.Context, groupName string) ([]*Repository, error)

ListRepositories lists all projects in a GitLab group

func (*GitLabProvider) Name

func (g *GitLabProvider) Name() string

Name returns the provider name

func (*GitLabProvider) ParseSource

func (g *GitLabProvider) ParseSource(source string) (*SourceInfo, error)

ParseSource parses a GitLab source URL or identifier

func (*GitLabProvider) RepositoryExists

func (g *GitLabProvider) RepositoryExists(ctx context.Context, groupName, projectName string) (bool, error)

RepositoryExists checks if a project exists in a GitLab group

func (*GitLabProvider) SyncRepository

func (g *GitLabProvider) SyncRepository(ctx context.Context, repo *Repository) error

SyncRepository synchronizes a forked project with its upstream

type Manager

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

Manager manages multiple Git hosting providers

func NewProviderManager

func NewProviderManager(config *Config) *Manager

NewProviderManager creates a new provider manager

func (*Manager) Close

func (pm *Manager) Close() error

Close closes all registered providers

func (*Manager) GetProvider

func (pm *Manager) GetProvider(name string) (Provider, error)

GetProvider returns a provider by name

func (*Manager) GetProviderForSource

func (pm *Manager) GetProviderForSource(source string) (Provider, *SourceInfo, error)

GetProviderForSource determines and returns the appropriate provider for a source

func (*Manager) RegisterProvider

func (pm *Manager) RegisterProvider(name string, provider Provider)

RegisterProvider registers a provider with the manager

type Organization

type Organization struct {
	ID          string            // Unique identifier
	Name        string            // Organization name
	DisplayName string            // Display name
	Description string            // Organization description
	URL         string            // Organization URL
	Type        string            // Organization type (user, organization, group, etc.)
	Metadata    map[string]string // Provider-specific metadata
}

Organization represents an organization/group from any Git hosting provider

type Provider

type Provider interface {
	// Name returns the provider name (e.g., "github", "gitlab", "gerrit")
	Name() string

	// ParseSource parses a source URL/identifier and returns normalized components
	ParseSource(source string) (*SourceInfo, error)

	// GetOrganization retrieves organization information
	GetOrganization(ctx context.Context, orgName string) (*Organization, error)

	// ListRepositories lists all repositories in an organization
	ListRepositories(ctx context.Context, orgName string) ([]*Repository, error)

	// CreateFork creates a fork of a repository in the target organization
	CreateFork(ctx context.Context, sourceRepo *Repository, targetOrg string) (*Repository, error)

	// CreateOrganization creates a new organization (if supported)
	CreateOrganization(ctx context.Context, orgName, displayName, description string) (*Organization, error)

	// SyncRepository synchronizes a forked repository with its upstream
	SyncRepository(ctx context.Context, repo *Repository) error

	// RepositoryExists checks if a repository exists in an organization
	RepositoryExists(ctx context.Context, orgName, repoName string) (bool, error)

	// Close performs any cleanup operations
	Close() error
}

Provider defines the interface for Git hosting providers

type RateLimitError

type RateLimitError struct {
	RetryAfter time.Duration
	Message    string
}

RateLimitError represents a rate limiting error

func IsRateLimitError

func IsRateLimitError(err error) (*RateLimitError, bool)

IsRateLimitError checks if an error is a rate limit error

func (*RateLimitError) Error

func (e *RateLimitError) Error() string

type Repository

type Repository struct {
	ID          string            // Unique identifier
	Name        string            // Repository name
	FullName    string            // Full name (e.g., "org/repo")
	CloneURL    string            // HTTPS clone URL
	SSHCloneURL string            // SSH clone URL
	Description string            // Repository description
	Private     bool              // Whether repository is private
	Fork        bool              // Whether repository is a fork
	Language    string            // Primary programming language
	Size        int64             // Repository size in KB
	Stars       int               // Star count
	Forks       int               // Fork count
	CreatedAt   string            // Creation timestamp
	UpdatedAt   string            // Last update timestamp
	Metadata    map[string]string // Provider-specific metadata
	Path        string            // Hierarchical path (for Gerrit nested projects)
}

Repository represents a repository from any Git hosting provider

type SourceInfo

type SourceInfo struct {
	Provider     string // Provider name (github, gitlab, gerrit)
	Host         string // Hostname
	Organization string // Organization/group name
	Path         string // Additional path information
	IsSSH        bool   // Whether this is an SSH URL
}

SourceInfo contains parsed information about a source

func ParseGenericSource

func ParseGenericSource(source string) (*SourceInfo, error)

ParseGenericSource provides a generic source parser as fallback

Jump to

Keyboard shortcuts

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