Documentation
¶
Overview ¶
Package github provides GitHub API client integration and authentication. This package abstracts GitHub API operations, handling client creation with proper authentication through environment variables or OS keyring storage. It manages OAuth2 token-based authentication, provides type aliases for commonly used GitHub API types, and configures HTTP clients for API calls. The package supports both authenticated and unauthenticated API access, with automatic fallback mechanisms for different authentication sources.
Index ¶
- Constants
- func Ptr[T any](v T) *T
- type Client
- type ClientRegistry
- type ClientResolver
- type Commit
- type CommitAuthor
- type GetCommitResult
- type GetCommitSHA1Result
- type GitObject
- type GitService
- type GitServiceImpl
- type ListOptions
- type ListReleasesResult
- type ListTagsResult
- type PullRequestComment
- type PullRequestsService
- type PullRequestsServiceImpl
- type Reference
- type RepositoriesService
- type RepositoriesServiceImpl
- func (r *RepositoriesServiceImpl) Get(ctx context.Context, logger *slog.Logger, owner, repo string) (*Repository, *Response, error)
- func (r *RepositoriesServiceImpl) GetCommitSHA1(ctx context.Context, logger *slog.Logger, owner, repo, ref, lastSHA string) (string, *Response, error)
- func (r *RepositoriesServiceImpl) ListReleases(ctx context.Context, logger *slog.Logger, owner string, repo string, ...) ([]*RepositoryRelease, *Response, error)
- func (r *RepositoriesServiceImpl) ListTags(ctx context.Context, logger *slog.Logger, owner string, repo string, ...) ([]*RepositoryTag, *Response, error)
- func (r *RepositoriesServiceImpl) SetResolver(resolver *ClientResolver)
- type Repository
- type RepositoryRelease
- type RepositoryTag
- type Response
- type Timestamp
Constants ¶
const (
KeyService = "suzuki-shunsuke/pinact"
)
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Client ¶
func New ¶
func New(ctx context.Context, logger *slog.Logger, token string, keyringEnabled, ghtknEnabled bool) *Client
New creates a new GitHub API client with authentication. It configures the client with appropriate HTTP client based on available authentication methods (environment token or keyring).
type ClientRegistry ¶
type ClientRegistry struct {
// contains filtered or unexported fields
}
ClientRegistry manages GitHub clients for github.com and a GHES instance. It maintains a default client for github.com and optionally a client for a configured GHES instance.
func NewClientRegistry ¶
func NewClientRegistry(ctx context.Context, defaultClient *Client, ghes *config.GHES, token string) (*ClientRegistry, error)
NewClientRegistry creates a new ClientRegistry with clients for github.com and optionally a GHES instance.
func (*ClientRegistry) GetGHESClient ¶
func (r *ClientRegistry) GetGHESClient() *Client
GetGHESClient returns the GHES client if configured, or nil if not configured.
type ClientResolver ¶
type ClientResolver struct {
// contains filtered or unexported fields
}
ClientResolver resolves which GitHub service (GHES or github.com) to use for a given repository. It uses the Get a Repository API to check if a repository exists on GHES or github.com, and caches the result to avoid redundant API calls.
func NewClientResolver ¶
func NewClientResolver( defaultRepoService RepositoriesService, defaultGitService GitService, ghesRepoService RepositoriesService, ghesGitService GitService, fallback bool, ) *ClientResolver
NewClientResolver creates a new ClientResolver with the given services.
func (*ClientResolver) GetGitService ¶
func (r *ClientResolver) GetGitService(ctx context.Context, logger *slog.Logger, owner, repo string) (GitService, error)
GetGitService returns the appropriate GitService for the given repository.
func (*ClientResolver) GetRepositoriesService ¶
func (r *ClientResolver) GetRepositoriesService(ctx context.Context, logger *slog.Logger, owner, repo string) (RepositoriesService, error)
GetRepositoriesService returns the appropriate RepositoriesService for the given repository.
type CommitAuthor ¶
type CommitAuthor = github.CommitAuthor
type GetCommitResult ¶
type GetCommitResult struct {
Commit *Commit
Response *Response
// contains filtered or unexported fields
}
GetCommitResult holds the cached result of a GetCommit call.
type GetCommitSHA1Result ¶
type GetCommitSHA1Result struct {
SHA string
Response *Response
// contains filtered or unexported fields
}
GetCommitSHA1Result holds the cached result of a GetCommitSHA1 call.
type GitService ¶
type GitService interface {
GetCommit(ctx context.Context, owner, repo, sha string) (*Commit, *Response, error)
}
GitService defines the interface for GitHub Git API operations.
type GitServiceImpl ¶
type GitServiceImpl struct {
Commits map[string]*GetCommitResult
// contains filtered or unexported fields
}
GitServiceImpl wraps a GitService with caching and GHES fallback support.
func (*GitServiceImpl) GetCommit ¶
func (g *GitServiceImpl) GetCommit(ctx context.Context, logger *slog.Logger, owner, repo, sha string) (*Commit, *Response, error)
GetCommit retrieves a commit object with caching and GHES fallback.
func (*GitServiceImpl) SetResolver ¶
func (g *GitServiceImpl) SetResolver(resolver *ClientResolver)
SetResolver sets the ClientResolver for the GitServiceImpl.
type ListOptions ¶
type ListOptions = github.ListOptions
type ListReleasesResult ¶
type ListReleasesResult struct {
Releases []*RepositoryRelease
Response *Response
// contains filtered or unexported fields
}
ListReleasesResult holds the cached result of a ListReleases call.
type ListTagsResult ¶
type ListTagsResult struct {
Tags []*RepositoryTag
Response *Response
// contains filtered or unexported fields
}
ListTagsResult holds the cached result of a ListTags call.
type PullRequestComment ¶
type PullRequestComment = github.PullRequestComment
type PullRequestsService ¶
type PullRequestsService interface {
CreateComment(ctx context.Context, owner, repo string, number int, comment *PullRequestComment) (*PullRequestComment, *Response, error)
}
PullRequestsService defines the interface for GitHub Pull Requests API operations.
type PullRequestsServiceImpl ¶
type PullRequestsServiceImpl struct {
// contains filtered or unexported fields
}
PullRequestsServiceImpl wraps PullRequestsService with GHES support.
func (*PullRequestsServiceImpl) CreateComment ¶
func (p *PullRequestsServiceImpl) CreateComment(ctx context.Context, owner, repo string, number int, comment *github.PullRequestComment) (*github.PullRequestComment, *github.Response, error)
CreateComment creates a pull request comment. If GHES is enabled, it always uses GHES (no fallback).
func (*PullRequestsServiceImpl) SetServices ¶
func (p *PullRequestsServiceImpl) SetServices(defaultService, ghesService PullRequestsService)
SetServices sets the default and GHES PullRequestsService.
type RepositoriesService ¶
type RepositoriesService interface {
ListTags(ctx context.Context, owner string, repo string, opts *ListOptions) ([]*RepositoryTag, *Response, error)
GetCommitSHA1(ctx context.Context, owner, repo, ref, lastSHA string) (string, *Response, error)
ListReleases(ctx context.Context, owner, repo string, opts *ListOptions) ([]*RepositoryRelease, *Response, error)
Get(ctx context.Context, owner, repo string) (*Repository, *Response, error)
}
RepositoriesService defines the interface for GitHub Repositories API operations.
type RepositoriesServiceImpl ¶
type RepositoriesServiceImpl struct {
Tags map[string]*ListTagsResult
Commits map[string]*GetCommitSHA1Result
Releases map[string]*ListReleasesResult
// contains filtered or unexported fields
}
RepositoriesServiceImpl wraps a RepositoriesService with caching and GHES fallback support.
func (*RepositoriesServiceImpl) Get ¶
func (r *RepositoriesServiceImpl) Get(ctx context.Context, logger *slog.Logger, owner, repo string) (*Repository, *Response, error)
Get fetches a repository to check its existence.
func (*RepositoriesServiceImpl) GetCommitSHA1 ¶
func (r *RepositoriesServiceImpl) GetCommitSHA1(ctx context.Context, logger *slog.Logger, owner, repo, ref, lastSHA string) (string, *Response, error)
GetCommitSHA1 retrieves the commit SHA for a given reference with caching and GHES fallback.
func (*RepositoriesServiceImpl) ListReleases ¶
func (r *RepositoriesServiceImpl) ListReleases(ctx context.Context, logger *slog.Logger, owner string, repo string, opts *ListOptions) ([]*RepositoryRelease, *Response, error)
ListReleases retrieves repository releases with caching and GHES fallback.
func (*RepositoriesServiceImpl) ListTags ¶
func (r *RepositoriesServiceImpl) ListTags(ctx context.Context, logger *slog.Logger, owner string, repo string, opts *ListOptions) ([]*RepositoryTag, *Response, error)
ListTags retrieves repository tags with caching and GHES fallback.
func (*RepositoriesServiceImpl) SetResolver ¶
func (r *RepositoriesServiceImpl) SetResolver(resolver *ClientResolver)
SetResolver sets the ClientResolver for the RepositoriesServiceImpl.
type Repository ¶
type Repository = github.Repository
type RepositoryRelease ¶
type RepositoryRelease = github.RepositoryRelease
type RepositoryTag ¶
type RepositoryTag = github.RepositoryTag