github

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 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

func GraphQL added in v1.1.1

func GraphQL(ctx context.Context, client *gh.Client, query string, vars map[string]any, out any) error

GraphQL posts a query to the API's /graphql endpoint with the client's auth, and decodes the "data" part into out

func NewRESTClient added in v1.1.1

func NewRESTClient(token string) *gh.Client

NewRESTClient returns a plain go-github client that sends the token

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)

	// GetAuthenticatedUser returns the account the token belongs to
	GetAuthenticatedUser(ctx context.Context) (*gh.User, error)

	// ListGists returns all gists of the authenticated user, secret ones included
	ListGists(ctx context.Context) ([]*gh.Gist, error)

	// GetIssuePRCounts returns how many issues and pull requests (all states) a repo has
	GetIssuePRCounts(ctx context.Context, owner, repo string) (issues, pulls int, err 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 GraphQLError added in v1.1.1

type GraphQLError struct {
	Errors []GraphQLErrorItem
	Rate   gh.Rate
}

GraphQLError is returned when a GraphQL reply carries errors. The data that did come back is still decoded.

func (*GraphQLError) Error added in v1.1.1

func (e *GraphQLError) Error() string

func (*GraphQLError) HasType added in v1.1.1

func (e *GraphQLError) HasType(types ...string) bool

HasType reports whether any error has one of the given types

type GraphQLErrorItem added in v1.1.1

type GraphQLErrorItem struct {
	Type    string `json:"type"`
	Message string `json:"message"`
}

GraphQLErrorItem is one entry of a GraphQL "errors" list

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)

	// GetAuthenticatedUserFunc can be set to mock GetAuthenticatedUser behavior
	GetAuthenticatedUserFunc func(ctx context.Context) (*gh.User, error)

	// ListGistsFunc can be set to mock ListGists behavior
	ListGistsFunc func(ctx context.Context) ([]*gh.Gist, error)

	// GetIssuePRCountsFunc can be set to mock GetIssuePRCounts behavior
	GetIssuePRCountsFunc func(ctx context.Context, owner, repo string) (int, int, 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) GetAuthenticatedUser added in v1.1.1

func (m *MockClient) GetAuthenticatedUser(ctx context.Context) (*gh.User, error)

GetAuthenticatedUser implements Client.GetAuthenticatedUser

func (*MockClient) GetBranchRef

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

GetBranchRef implements Client.GetBranchRef

func (*MockClient) GetIssuePRCounts added in v1.1.1

func (m *MockClient) GetIssuePRCounts(ctx context.Context, owner, repo string) (int, int, error)

GetIssuePRCounts implements Client.GetIssuePRCounts

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) ListGists added in v1.1.1

func (m *MockClient) ListGists(ctx context.Context) ([]*gh.Gist, error)

ListGists implements Client.ListGists

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

Jump to

Keyboard shortcuts

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