github

package
v0.31.1 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2026 License: MIT Imports: 13 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. Client construction uses package-owned ClientSettings; GTB config integration lives in ClientSettingsFromConfig.

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 vcs.TokenConfig) (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 ClientSettings added in v0.30.0

type ClientSettings struct {
	ReleaseSource release.ReleaseSourceConfig
	APIURL        string `json:"api_url"    yaml:"api_url"`
	UploadURL     string `json:"upload_url" yaml:"upload_url"`
	Auth          vcs.AuthConfig
}

ClientSettings contains the typed configuration NewGitHubClient needs.

Fields are populated by the GTB config adapter (ClientSettingsFromConfig) via the narrow vcs.TokenConfig seam, not decoded with mapstructure. The json/yaml tags are for documentation and serialisation only.

func ClientSettingsFromConfig added in v0.30.0

func ClientSettingsFromConfig(src release.ReleaseSourceConfig, cfg vcs.TokenConfig) ClientSettings

ClientSettingsFromConfig adapts the github config subtree into typed client settings. It preserves the existing `url.*` and `auth.*` key layout.

type GHClient

type GHClient struct {
	Client *github.Client
}

GHClient implements GitHubClient using the GitHub REST and GraphQL APIs.

func NewGitHubClient

func NewGitHubClient(settings ClientSettings) (*GHClient, error)

NewGitHubClient builds a GitHub API client from typed settings. A public repository needs only the ReleaseSource; an empty or "github.com" Host targets the public api.github.com, while any other Host is treated as a GitHub Enterprise instance. Explicit API/upload URLs take precedence over 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