github

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package github implements the VCS release provider and API client for GitHub repositories, supporting both public and token-authenticated access. It provides repository management, pull requests, release listing, asset downloads, and file retrieval through a testable GitHubClient interface.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoPullRequestFound = errors.New("no pull request found")
	ErrRepoExists         = errors.New("repository already exists")
)

Functions

func GHLogin

func GHLogin(hostname string) (string, error)

GHLogin authenticates with GitHub using the gh CLI device flow.

func GetGitHubToken

func GetGitHubToken(cfg config.Containable) (string, error)

GetGitHubToken returns the GitHub token from config, erroring when none is available. Use this where a token is strictly required (e.g. git operations). For release/update operations on public repos, prefer vcs.ResolveToken directly.

func NewReleaseProvider

func NewReleaseProvider(client GitHubClient) release.Provider

NewReleaseProvider creates a release.Provider backed by the GitHub Releases API.

Types

type GHClient

type GHClient struct {
	Client *github.Client
	// contains filtered or unexported fields
}

GHClient implements GitHubClient using the GitHub REST and GraphQL APIs.

func NewGitHubClient

func NewGitHubClient(src release.ReleaseSourceConfig, cfg config.Containable) (*GHClient, error)

NewGitHubClient creates a GHClient configured from the github config subtree. NewGitHubClient builds a GitHub API client. It is config-less by design: a public repository needs only the ReleaseSource (an empty or "github.com" Host targets the public api.github.com; any other Host is treated as a GitHub Enterprise instance). cfg is the optional `github` config subtree (nil when no such section exists); it supplies a token (for private repos) and explicit `url.api`/`url.upload` overrides that take precedence over the host-derived Enterprise URLs.

func (*GHClient) AddLabelsToPullRequest

func (c *GHClient) AddLabelsToPullRequest(ctx context.Context, owner, repo string, number int, labels []string) error

func (*GHClient) CreatePullRequest

func (c *GHClient) CreatePullRequest(ctx context.Context, owner string, repo string, pr *github.NewPullRequest) (*github.PullRequest, error)

func (*GHClient) CreateRepo

func (c *GHClient) CreateRepo(ctx context.Context, owner, slug string) (*github.Repository, error)

func (*GHClient) DownloadAsset

func (c *GHClient) DownloadAsset(ctx context.Context, owner string, repo string, assetID int64) (io.ReadCloser, error)

func (*GHClient) DownloadAssetTo

func (c *GHClient) DownloadAssetTo(ctx context.Context, fs afero.Fs, owner, repo string, assetID int64, filePath string) error

func (*GHClient) GetClient

func (c *GHClient) GetClient() *github.Client

func (*GHClient) GetFileContents

func (c *GHClient) GetFileContents(ctx context.Context, owner, repo, path, ref string) (string, error)

func (*GHClient) GetPullRequestByBranch

func (c *GHClient) GetPullRequestByBranch(ctx context.Context, owner, repo, branch, state string) (*github.PullRequest, error)

func (*GHClient) GetReleaseAssetID

func (c *GHClient) GetReleaseAssetID(ctx context.Context, owner, repo, tag, assetName string) (int64, error)

func (*GHClient) GetReleaseAssets

func (c *GHClient) GetReleaseAssets(ctx context.Context, owner, repo, tag string) ([]*github.ReleaseAsset, error)

func (*GHClient) ListReleases

func (c *GHClient) ListReleases(ctx context.Context, owner, repo string) ([]string, error)

func (*GHClient) UpdatePullRequest

func (c *GHClient) UpdatePullRequest(ctx context.Context, owner, repo string, number int, pr *github.PullRequest) (*github.PullRequest, *github.Response, error)

func (*GHClient) UploadKey

func (c *GHClient) UploadKey(ctx context.Context, name string, key []byte) error

type GitHubClient

type GitHubClient interface {
	GetClient() *github.Client
	CreatePullRequest(ctx context.Context, owner string, repo string, pull *github.NewPullRequest) (*github.PullRequest, error)
	GetPullRequestByBranch(ctx context.Context, owner, repo, branch, state string) (*github.PullRequest, error)
	AddLabelsToPullRequest(ctx context.Context, owner, repo string, number int, labels []string) error
	UpdatePullRequest(ctx context.Context, owner, repo string, number int, pull *github.PullRequest) (*github.PullRequest, *github.Response, error)
	CreateRepo(ctx context.Context, owner, slug string) (*github.Repository, error)
	UploadKey(ctx context.Context, name string, key []byte) error
	ListReleases(ctx context.Context, owner, repo string) ([]string, error)
	GetReleaseAssets(ctx context.Context, owner, repo, tag string) ([]*github.ReleaseAsset, error)
	GetReleaseAssetID(ctx context.Context, owner, repo, tag, assetName string) (int64, error)
	DownloadAsset(ctx context.Context, owner, repo string, assetID int64) (io.ReadCloser, error)
	DownloadAssetTo(ctx context.Context, fs afero.Fs, owner, repo string, assetID int64, filePath string) error
	GetFileContents(ctx context.Context, owner, repo, path, ref string) (string, error)
}

GitHubClient defines the interface for GitHub API operations.

type GitHubReleaseProvider

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

GitHubReleaseProvider implements release.Provider.

func (*GitHubReleaseProvider) DownloadReleaseAsset

func (p *GitHubReleaseProvider) DownloadReleaseAsset(ctx context.Context, owner, repo string, asset release.ReleaseAsset) (io.ReadCloser, string, error)

func (*GitHubReleaseProvider) GetLatestRelease

func (p *GitHubReleaseProvider) GetLatestRelease(ctx context.Context, owner, repo string) (release.Release, error)

func (*GitHubReleaseProvider) GetReleaseByTag

func (p *GitHubReleaseProvider) GetReleaseByTag(ctx context.Context, owner, repo, tag string) (release.Release, error)

func (*GitHubReleaseProvider) ListReleases

func (p *GitHubReleaseProvider) ListReleases(ctx context.Context, owner, repo string, limit int) ([]release.Release, error)

Jump to

Keyboard shortcuts

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