gh

package
v1.3.4 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2026 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Overview

Package gh wraps the go-github client with the GitHub helpers (PRs, files, labels) shared between katbyte's tools.

Index

Constants

View Source
const (
	PRStateOpen   = "open"
	PRStateClosed = "closed"
)

GitHub API pull request states, as returned by PullRequest.GetState() and accepted by ListAllPullRequests/GetAllPullRequests.

Variables

This section is empty.

Functions

func WrapGitHubError added in v1.0.0

func WrapGitHubError(err error, action string) error

WrapGitHubError examines a GitHub API error and returns a more descriptive error message. GitHub often returns 404 instead of 401/403 for security reasons (to avoid revealing resource existence to unauthorised users), so a "404 Not Found" may actually mean the token is expired, revoked, or lacks the required permissions.

Types

type Repo

type Repo struct {
	Owner string
	Name  string

	// APIURL and RawURL override the GitHub endpoints so tests can point at
	// mock servers; they also work for GitHub Enterprise. Empty means the
	// public github.com endpoints.
	APIURL string
	RawURL string

	Token
}

func NewRepo

func NewRepo(owner, repo, token string) Repo

func (Repo) CheckoutPR added in v1.0.0

func (Repo) CheckoutPR(repoPath string, prNumber int) (string, error)

CheckoutPR fetches the merge ref for a PR and checks out FETCH_HEAD in the given repo path. Returns the short SHA of the checked-out merge commit.

func (Repo) CloneURL added in v0.9.1

func (r Repo) CloneURL() string

func (Repo) DownloadFile added in v0.9.1

func (r Repo) DownloadFile(ctx context.Context, httpClient *http.Client, path, ref string) (content []byte, statusCode int, err error)

DownloadFile fetches the raw content of a file from GitHub at a specific ref (commit SHA or branch). Returns the file content bytes, the HTTP status code, and any error.

func (Repo) GetAllPullRequests

func (r Repo) GetAllPullRequests(state string) (*[]github.PullRequest, error)

func (Repo) GetLabelsFor

func (r Repo) GetLabelsFor(number int) (*[]string, error)

func (Repo) GetPrForBuild added in v1.3.0

func (r Repo) GetPrForBuild(number int) (*github.PullRequest, error)

GetPrForBuild fetches a PR and verifies builds can be triggered on its merge ref: it must be open, mergeable, and have a merge commit SHA. Mergeable has to be checked explicitly — GitHub keeps returning a stale merge_commit_sha for a PR that has *become* conflicted, so a nil-SHA check alone lets conflicted PRs through to trigger builds on a stale or missing refs/pull/N/merge ref, which then fail (or silently test outdated code) inside TeamCity where nobody sees it.

func (Repo) ListAllPullRequestFiles added in v0.9.1

func (r Repo) ListAllPullRequestFiles(pri int, cb func([]*github.CommitFile, *github.Response) error) error

func (Repo) ListAllPullRequests

func (r Repo) ListAllPullRequests(state string, cb func([]*github.PullRequest, *github.Response) error) error

func (Repo) NewClient added in v1.2.0

func (r Repo) NewClient() (*github.Client, context.Context)

NewClient returns a github client for this repo, pointing at APIURL when set. It shadows the promoted Token.NewClient so all repo-scoped calls honour the override.

func (Repo) PrURL

func (r Repo) PrURL(pr int) string

type Token

type Token struct {
	Token *string
}

func (Token) NewClient

func (t Token) NewClient() (*github.Client, context.Context)

Jump to

Keyboard shortcuts

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