github

package
v1.0.14 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package github provides interfaces and implementation for GitHub API operations

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	// GetReleases returns all releases for a repository
	GetReleases(ctx context.Context, owner, repo string) ([]*gh.RepositoryRelease, error)

	// RemoveRelease deletes a release and its associated tag
	RemoveRelease(ctx context.Context, owner, repo string, release *gh.RepositoryRelease) error

	// ListUserRepos returns all repositories for a user
	ListUserRepos(ctx context.Context, username string, opts *ListOptions) ([]*gh.Repository, error)

	// ListOrgRepos returns all repositories for an organization
	ListOrgRepos(ctx context.Context, org string, opts *ListOptions) ([]*gh.Repository, error)

	// ListUserOrgs returns all organizations the authenticated user belongs to
	ListUserOrgs(ctx context.Context) ([]*gh.Organization, error)

	// GetRepository returns information about a single repository
	GetRepository(ctx context.Context, owner, repo string) (*gh.Repository, error)

	// GetRateLimit returns the current rate limit status
	GetRateLimit(ctx context.Context) (*gh.RateLimits, error)

	// GetBranchRef returns the SHA of a branch (used for fast sync check)
	GetBranchRef(ctx context.Context, owner, repo, branch string) (string, error)
}

Client defines the interface for GitHub API operations

func NewClient

func NewClient(token string) Client

NewClient creates a new GitHub client with the provided token

type ListOptions

type ListOptions struct {
	// Type of repositories to list: all, owner, member (default: all)
	Type string

	// Include private repositories
	IncludePrivate bool

	// PerPage specifies the number of results per page (max 100)
	PerPage int
}

ListOptions specifies optional parameters for list operations

func DefaultListOptions

func DefaultListOptions() *ListOptions

DefaultListOptions returns default list options

type MockCall

type MockCall struct {
	Method string
	Args   []interface{}
}

MockCall records a method call for verification

type MockClient

type MockClient struct {
	// GetReleasesFunc can be set to mock GetReleases behavior
	GetReleasesFunc func(ctx context.Context, owner, repo string) ([]*gh.RepositoryRelease, error)

	// RemoveReleaseFunc can be set to mock RemoveRelease behavior
	RemoveReleaseFunc func(ctx context.Context, owner, repo string, release *gh.RepositoryRelease) error

	// ListUserReposFunc can be set to mock ListUserRepos behavior
	ListUserReposFunc func(ctx context.Context, username string, opts *ListOptions) ([]*gh.Repository, error)

	// ListOrgReposFunc can be set to mock ListOrgRepos behavior
	ListOrgReposFunc func(ctx context.Context, org string, opts *ListOptions) ([]*gh.Repository, error)

	// ListUserOrgsFunc can be set to mock ListUserOrgs behavior
	ListUserOrgsFunc func(ctx context.Context) ([]*gh.Organization, error)

	// GetRepositoryFunc can be set to mock GetRepository behavior
	GetRepositoryFunc func(ctx context.Context, owner, repo string) (*gh.Repository, error)

	// GetRateLimitFunc can be set to mock GetRateLimit behavior
	GetRateLimitFunc func(ctx context.Context) (*gh.RateLimits, error)

	// GetBranchRefFunc can be set to mock GetBranchRef behavior
	GetBranchRefFunc func(ctx context.Context, owner, repo, branch string) (string, error)

	// Call tracking
	Calls []MockCall
}

MockClient is a mock implementation of the Client interface for testing

func NewMockClient

func NewMockClient() *MockClient

NewMockClient creates a new mock client

func (*MockClient) CallCount

func (m *MockClient) CallCount(method string) int

CallCount returns the number of times a method was called

func (*MockClient) GetBranchRef

func (m *MockClient) GetBranchRef(ctx context.Context, owner, repo, branch string) (string, error)

GetBranchRef implements Client.GetBranchRef

func (*MockClient) GetRateLimit

func (m *MockClient) GetRateLimit(ctx context.Context) (*gh.RateLimits, error)

GetRateLimit implements Client.GetRateLimit

func (*MockClient) GetReleases

func (m *MockClient) GetReleases(ctx context.Context, owner, repo string) ([]*gh.RepositoryRelease, error)

GetReleases implements Client.GetReleases

func (*MockClient) GetRepository

func (m *MockClient) GetRepository(ctx context.Context, owner, repo string) (*gh.Repository, error)

GetRepository implements Client.GetRepository

func (*MockClient) ListOrgRepos

func (m *MockClient) ListOrgRepos(ctx context.Context, org string, opts *ListOptions) ([]*gh.Repository, error)

ListOrgRepos implements Client.ListOrgRepos

func (*MockClient) ListUserOrgs

func (m *MockClient) ListUserOrgs(ctx context.Context) ([]*gh.Organization, error)

ListUserOrgs implements Client.ListUserOrgs

func (*MockClient) ListUserRepos

func (m *MockClient) ListUserRepos(ctx context.Context, username string, opts *ListOptions) ([]*gh.Repository, error)

ListUserRepos implements Client.ListUserRepos

func (*MockClient) RemoveRelease

func (m *MockClient) RemoveRelease(ctx context.Context, owner, repo string, release *gh.RepositoryRelease) error

RemoveRelease implements Client.RemoveRelease

func (*MockClient) Reset

func (m *MockClient) Reset()

Reset clears all recorded calls

type RetryConfig

type RetryConfig struct {
	// MaxRetries is the maximum number of retries for transient errors
	MaxRetries int

	// InitialDelay is the initial delay between retries
	InitialDelay time.Duration

	// MaxDelay is the maximum delay between retries
	MaxDelay time.Duration

	// Multiplier is the factor by which delay increases after each retry
	Multiplier float64
}

RetryConfig configures retry behavior for API calls

func DefaultRetryConfig

func DefaultRetryConfig() *RetryConfig

DefaultRetryConfig returns the default retry configuration

type RetryableClient

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

RetryableClient wraps a Client with retry logic

func NewRetryableClient

func NewRetryableClient(c Client, config *RetryConfig) *RetryableClient

NewRetryableClient creates a new client with retry support

Jump to

Keyboard shortcuts

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