scm

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2026 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

Package scm provides client implementations for various SCM (Source Code Management) providers

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnsupportedProvider = NewSCMError("unsupported SCM provider", "UNSUPPORTED_PROVIDER")
	ErrAuthFailed          = NewSCMError("authentication failed", "AUTH_FAILED")
	ErrRateLimited         = NewSCMError("rate limit exceeded", "RATE_LIMITED")
	ErrNotFound            = NewSCMError("resource not found", "NOT_FOUND")
	ErrPermissionDenied    = NewSCMError("permission denied", "PERMISSION_DENIED")
)

Common errors

Functions

This section is empty.

Types

type AuthType

type AuthType string

AuthType represents the authentication method

const (
	AuthTypeToken AuthType = "token"
	AuthTypeOAuth AuthType = "oauth"
	AuthTypeApp   AuthType = "app"
)

type AzureClient

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

AzureClient implements the Client interface for Azure DevOps Supports both Azure DevOps Services (dev.azure.com) and Azure DevOps Server

func NewAzureClient

func NewAzureClient(config Config) (*AzureClient, error)

NewAzureClient creates a new Azure DevOps client

func (*AzureClient) GetRepository

func (c *AzureClient) GetRepository(ctx context.Context, fullName string) (*Repository, error)

GetRepository returns a single repository by full name (project/repo)

func (*AzureClient) GetUser

func (c *AzureClient) GetUser(ctx context.Context) (*User, error)

GetUser returns the authenticated user

func (*AzureClient) ListOrganizations

func (c *AzureClient) ListOrganizations(ctx context.Context, opts ListOptions) ([]Organization, error)

ListOrganizations returns organizations/projects the user has access to

func (*AzureClient) ListRepositories

func (c *AzureClient) ListRepositories(ctx context.Context, opts ListOptions) (*ListResult, error)

ListRepositories returns repositories accessible to the user

func (*AzureClient) TestConnection

func (c *AzureClient) TestConnection(ctx context.Context) (*ConnectionTestResult, error)

TestConnection verifies the connection and returns user/org info

type BitbucketClient

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

BitbucketClient implements the Client interface for Bitbucket Supports both Bitbucket Cloud (bitbucket.org) and Bitbucket Server/Data Center

func NewBitbucketClient

func NewBitbucketClient(config Config) (*BitbucketClient, error)

NewBitbucketClient creates a new Bitbucket client

func (*BitbucketClient) GetRepository

func (c *BitbucketClient) GetRepository(ctx context.Context, fullName string) (*Repository, error)

GetRepository returns a single repository by full name

func (*BitbucketClient) GetUser

func (c *BitbucketClient) GetUser(ctx context.Context) (*User, error)

GetUser returns the authenticated user

func (*BitbucketClient) ListOrganizations

func (c *BitbucketClient) ListOrganizations(ctx context.Context, opts ListOptions) ([]Organization, error)

ListOrganizations returns workspaces/projects the user has access to

func (*BitbucketClient) ListRepositories

func (c *BitbucketClient) ListRepositories(ctx context.Context, opts ListOptions) (*ListResult, error)

ListRepositories returns repositories accessible to the user

func (*BitbucketClient) TestConnection

func (c *BitbucketClient) TestConnection(ctx context.Context) (*ConnectionTestResult, error)

TestConnection verifies the connection and returns user/org info

type Client

type Client interface {
	// TestConnection verifies the connection and returns user/org info
	TestConnection(ctx context.Context) (*ConnectionTestResult, error)

	// GetUser returns the authenticated user
	GetUser(ctx context.Context) (*User, error)

	// ListOrganizations returns organizations the user has access to
	ListOrganizations(ctx context.Context, opts ListOptions) ([]Organization, error)

	// ListRepositories returns repositories accessible to the user
	// If organization is set in config, filters by that organization
	ListRepositories(ctx context.Context, opts ListOptions) (*ListResult, error)

	// GetRepository returns a single repository by full name (owner/repo)
	GetRepository(ctx context.Context, fullName string) (*Repository, error)
}

Client defines the interface for SCM provider clients

type ClientFactory

type ClientFactory struct{}

ClientFactory creates SCM clients based on provider

func NewClientFactory

func NewClientFactory() *ClientFactory

NewClientFactory creates a new ClientFactory

func (*ClientFactory) CreateClient

func (f *ClientFactory) CreateClient(config Config) (Client, error)

CreateClient creates an SCM client for the given config

type Config

type Config struct {
	Provider     Provider
	BaseURL      string // Base URL for self-hosted instances
	AccessToken  string
	Organization string // Optional: filter by organization/group
	AuthType     AuthType
}

Config holds the configuration for an SCM client

type ConnectionTestResult

type ConnectionTestResult struct {
	Success      bool
	Message      string
	User         *User
	Organization *Organization
	RepoCount    int
	RateLimit    *RateLimit
}

ConnectionTestResult represents the result of testing a connection

type GitHubClient

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

GitHubClient implements the Client interface for GitHub

func NewGitHubClient

func NewGitHubClient(config Config) (*GitHubClient, error)

NewGitHubClient creates a new GitHub client

func (*GitHubClient) GetRepository

func (c *GitHubClient) GetRepository(ctx context.Context, fullName string) (*Repository, error)

GetRepository returns a single repository by full name

func (*GitHubClient) GetUser

func (c *GitHubClient) GetUser(ctx context.Context) (*User, error)

GetUser returns the authenticated user

func (*GitHubClient) ListOrganizations

func (c *GitHubClient) ListOrganizations(ctx context.Context, opts ListOptions) ([]Organization, error)

ListOrganizations returns organizations the user has access to

func (*GitHubClient) ListRepositories

func (c *GitHubClient) ListRepositories(ctx context.Context, opts ListOptions) (*ListResult, error)

ListRepositories returns repositories accessible to the user

func (*GitHubClient) TestConnection

func (c *GitHubClient) TestConnection(ctx context.Context) (*ConnectionTestResult, error)

TestConnection verifies the connection and returns user/org info

type GitLabClient

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

GitLabClient implements the Client interface for GitLab

func NewGitLabClient

func NewGitLabClient(config Config) (*GitLabClient, error)

NewGitLabClient creates a new GitLab client

func (*GitLabClient) GetRepository

func (c *GitLabClient) GetRepository(ctx context.Context, fullName string) (*Repository, error)

GetRepository returns a single project by full path (namespace/project)

func (*GitLabClient) GetUser

func (c *GitLabClient) GetUser(ctx context.Context) (*User, error)

GetUser returns the authenticated user

func (*GitLabClient) ListOrganizations

func (c *GitLabClient) ListOrganizations(ctx context.Context, opts ListOptions) ([]Organization, error)

ListOrganizations returns groups the user has access to

func (*GitLabClient) ListRepositories

func (c *GitLabClient) ListRepositories(ctx context.Context, opts ListOptions) (*ListResult, error)

ListRepositories returns projects accessible to the user

func (*GitLabClient) TestConnection

func (c *GitLabClient) TestConnection(ctx context.Context) (*ConnectionTestResult, error)

TestConnection verifies the connection and returns user/org info

type ListOptions

type ListOptions struct {
	Page    int
	PerPage int
	Search  string
}

ListOptions represents pagination options

type ListResult

type ListResult struct {
	Repositories []Repository
	Total        int
	HasMore      bool
	NextPage     int
}

ListResult represents a paginated list result

type Organization

type Organization struct {
	ID          string
	Name        string
	Description string
	AvatarURL   string
	RepoCount   int
}

Organization represents an organization/group from the SCM provider

type Provider

type Provider string

Provider represents the SCM provider type

const (
	ProviderGitHub    Provider = "github"
	ProviderGitLab    Provider = "gitlab"
	ProviderBitbucket Provider = "bitbucket"
	ProviderAzure     Provider = "azure"
)

type RateLimit

type RateLimit struct {
	Limit     int
	Remaining int
	ResetAt   time.Time
}

RateLimit represents API rate limit information

type Repository

type Repository struct {
	ID            string
	Name          string
	FullName      string
	Description   string
	HTMLURL       string
	CloneURL      string
	SSHURL        string
	DefaultBranch string
	IsPrivate     bool
	IsFork        bool
	IsArchived    bool
	Language      string         // Primary language
	Languages     map[string]int // All languages with byte counts
	Topics        []string
	Stars         int
	Forks         int
	Size          int // Size in KB
	CreatedAt     time.Time
	UpdatedAt     time.Time
	PushedAt      time.Time
}

Repository represents a repository from the SCM provider

type SCMError

type SCMError struct {
	Message string
	Code    string
	Wrapped error
}

SCMError represents an error from an SCM provider

func NewSCMError

func NewSCMError(message, code string) *SCMError

NewSCMError creates a new SCMError

func (*SCMError) Error

func (e *SCMError) Error() string

Error implements the error interface

func (*SCMError) Unwrap

func (e *SCMError) Unwrap() error

Unwrap returns the wrapped error

func (*SCMError) Wrap

func (e *SCMError) Wrap(err error) *SCMError

Wrap wraps an underlying error

type User

type User struct {
	ID        string
	Username  string
	Name      string
	Email     string
	AvatarURL string
}

User represents an authenticated user from the SCM provider

Jump to

Keyboard shortcuts

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