scm

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2026 License: GPL-3.0 Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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")
	// ErrBranchListingUnsupported is returned by providers that have not yet
	// implemented ListBranches.
	ErrBranchListingUnsupported = NewSCMError("branch listing not supported for this provider", "BRANCH_LISTING_UNSUPPORTED")
)

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. SECURITY: see GitHubClient — same SSRF mitigation pattern.

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) ListBranches added in v0.3.0

func (c *AzureClient) ListBranches(_ context.Context, _ string, _ ListOptions) ([]Branch, error)

ListBranches is not yet implemented for this provider.

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. SECURITY: see GitHubClient — same SSRF mitigation pattern.

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) ListBranches added in v0.3.0

func (c *BitbucketClient) ListBranches(ctx context.Context, fullName string, opts ListOptions) ([]Branch, error)

ListBranches returns the branches of a Bitbucket Cloud repository. Bitbucket Server/Data Center is not supported yet (different REST API). A single page of up to 100 branches is fetched (covers the common case; following the cloud `next` URL is left as a follow-up).

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 Branch added in v0.3.0

type Branch struct {
	Name      string
	Protected bool
	CommitSHA string
}

Branch is a repository branch as reported by an SCM provider.

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)

	// ListBranches returns the branches of a repository (owner/repo). Providers
	// that do not implement it return ErrBranchListingUnsupported.
	ListBranches(ctx context.Context, fullName string, opts ListOptions) ([]Branch, 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. SECURITY: validates user-supplied BaseURL via httpsec.ValidateURL to prevent SSRF (e.g. attacker setting BaseURL=http://169.254.169.254/... to read AWS IMDS metadata via TestConnection). The httpClient also uses httpsec.SafeHTTPClient whose dialer rejects loopback / private / link-local addresses as defense-in-depth.

func (*GitHubClient) CreateIssue added in v0.3.0

func (c *GitHubClient) CreateIssue(ctx context.Context, owner, repo, title, body string, labels []string) (int, string, error)

CreateIssue creates a GitHub issue in the given owner/repo and returns the new issue's number and html_url.

SECURITY: owner/repo are path-escaped to prevent path injection. On a non-201 response the error includes only the status code — the response body is NOT leaked verbatim (it may echo attacker-influenced input or reveal internal detail).

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) ListBranches added in v0.3.0

func (c *GitHubClient) ListBranches(ctx context.Context, fullName string, opts ListOptions) ([]Branch, error)

ListBranches returns the branches of a repository, walking pages up to a cap.

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

func (*GitHubClient) UpdateIssueState added in v0.3.0

func (c *GitHubClient) UpdateIssueState(ctx context.Context, owner, repo string, number int, state string) error

UpdateIssueState sets a GitHub issue's state ("open" or "closed"). Used by outbound finding→issue status sync. owner/repo are path-escaped; on a non-200 response the error carries only the status code (no body leak).

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. SECURITY: see GitHubClient — same SSRF mitigation pattern.

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) ListBranches added in v0.3.0

func (c *GitLabClient) ListBranches(ctx context.Context, fullName string, opts ListOptions) ([]Branch, error)

ListBranches returns the branches of a GitLab project, walking pages up to a cap.

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) Is added in v0.3.0

func (e *SCMError) Is(target error) bool

Is reports whether target is an SCMError with the same code. This lets errors.Is match a wrapped SCM error (e.g. ErrAuthFailed.Wrap(...), which is a fresh instance) against the package sentinels like ErrAuthFailed.

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