github

package
v3.0.0-...-86bc622 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2026 License: MIT Imports: 9 Imported by: 0

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

View Source
const (
	KeyService = "suzuki-shunsuke/pinact"
)

Variables

This section is empty.

Functions

func Ptr

func Ptr[T any](v T) *T

Ptr returns a pointer to the provided value. This is a convenience function that delegates to new for creating pointers to values, commonly needed for GitHub API structs.

Types

type Client

type Client = github.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).

func NewWithBaseURL

func NewWithBaseURL(ctx context.Context, baseURL, token string) (*Client, error)

NewWithBaseURL creates a new GitHub API client with a custom base URL. This is used for GitHub Enterprise Server instances.

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 Commit

type Commit = github.Commit

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 GitObject

type GitObject = github.GitObject

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 Reference

type Reference = github.Reference

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

type Response

type Response = github.Response

type Timestamp

type Timestamp = github.Timestamp

Jump to

Keyboard shortcuts

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