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 ¶
- Variables
- func GHLogin(hostname string) (string, error)
- func GetGitHubToken(cfg vcs.TokenConfig) (string, error)
- func NewReleaseProvider(client GitHubClient) release.Provider
- type ClientSettings
- type GHClient
- func (c *GHClient) AddLabelsToPullRequest(ctx context.Context, owner, repo string, number int, labels []string) error
- func (c *GHClient) CreatePullRequest(ctx context.Context, owner string, repo string, pr *github.NewPullRequest) (*github.PullRequest, error)
- func (c *GHClient) CreateRepo(ctx context.Context, owner, slug string) (*github.Repository, error)
- func (c *GHClient) DownloadAsset(ctx context.Context, owner string, repo string, assetID int64) (io.ReadCloser, error)
- func (c *GHClient) DownloadAssetTo(ctx context.Context, fs afero.Fs, owner, repo string, assetID int64, ...) error
- func (c *GHClient) GetClient() *github.Client
- func (c *GHClient) GetFileContents(ctx context.Context, owner, repo, path, ref string) (string, error)
- func (c *GHClient) GetPullRequestByBranch(ctx context.Context, owner, repo, branch, state string) (*github.PullRequest, error)
- func (c *GHClient) GetReleaseAssetID(ctx context.Context, owner, repo, tag, assetName string) (int64, error)
- func (c *GHClient) GetReleaseAssets(ctx context.Context, owner, repo, tag string) ([]*github.ReleaseAsset, error)
- func (c *GHClient) ListReleases(ctx context.Context, owner, repo string) ([]string, error)
- func (c *GHClient) UpdatePullRequest(ctx context.Context, owner, repo string, number int, pr *github.PullRequest) (*github.PullRequest, *github.Response, error)
- func (c *GHClient) UploadKey(ctx context.Context, name string, key []byte) error
- type GitHubClient
- type GitHubReleaseProvider
- func (p *GitHubReleaseProvider) DownloadReleaseAsset(ctx context.Context, owner, repo string, asset release.ReleaseAsset) (io.ReadCloser, string, error)
- func (p *GitHubReleaseProvider) GetLatestRelease(ctx context.Context, owner, repo string) (release.Release, error)
- func (p *GitHubReleaseProvider) GetReleaseByTag(ctx context.Context, owner, repo, tag string) (release.Release, error)
- func (p *GitHubReleaseProvider) ListReleases(ctx context.Context, owner, repo string, limit int) ([]release.Release, error)
Constants ¶
This section is empty.
Variables ¶
var ( ErrNoPullRequestFound = errors.New("no pull request found") ErrRepoExists = errors.New("repository already exists") )
Functions ¶
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 ¶
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 (*GHClient) CreatePullRequest ¶
func (c *GHClient) CreatePullRequest(ctx context.Context, owner string, repo string, pr *github.NewPullRequest) (*github.PullRequest, error)
func (*GHClient) CreateRepo ¶
func (*GHClient) DownloadAsset ¶
func (*GHClient) DownloadAssetTo ¶
func (*GHClient) GetFileContents ¶
func (*GHClient) GetPullRequestByBranch ¶
func (*GHClient) GetReleaseAssetID ¶
func (*GHClient) GetReleaseAssets ¶
func (*GHClient) ListReleases ¶
func (*GHClient) UpdatePullRequest ¶
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)