Documentation
¶
Overview ¶
Package github provides interfaces and implementation for GitHub API operations
Index ¶
- func GraphQL(ctx context.Context, client *gh.Client, query string, vars map[string]any, ...) error
- func NewRESTClient(token string) *gh.Client
- type Client
- type GraphQLError
- type GraphQLErrorItem
- type ListOptions
- type MockCall
- type MockClient
- func (m *MockClient) CallCount(method string) int
- func (m *MockClient) GetAuthenticatedUser(ctx context.Context) (*gh.User, error)
- func (m *MockClient) GetBranchRef(ctx context.Context, owner, repo, branch string) (string, error)
- func (m *MockClient) GetIssuePRCounts(ctx context.Context, owner, repo string) (int, int, error)
- func (m *MockClient) GetRateLimit(ctx context.Context) (*gh.RateLimits, error)
- func (m *MockClient) GetReleases(ctx context.Context, owner, repo string) ([]*gh.RepositoryRelease, error)
- func (m *MockClient) GetRepository(ctx context.Context, owner, repo string) (*gh.Repository, error)
- func (m *MockClient) ListGists(ctx context.Context) ([]*gh.Gist, error)
- func (m *MockClient) ListOrgRepos(ctx context.Context, org string, opts *ListOptions) ([]*gh.Repository, error)
- func (m *MockClient) ListUserOrgs(ctx context.Context) ([]*gh.Organization, error)
- func (m *MockClient) ListUserRepos(ctx context.Context, username string, opts *ListOptions) ([]*gh.Repository, error)
- func (m *MockClient) RemoveRelease(ctx context.Context, owner, repo string, release *gh.RepositoryRelease) error
- func (m *MockClient) Reset()
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
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
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
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 (*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
GetAuthenticatedUser implements Client.GetAuthenticatedUser
func (*MockClient) GetBranchRef ¶
GetBranchRef implements Client.GetBranchRef
func (*MockClient) GetIssuePRCounts ¶ added in v1.1.1
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) 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