Documentation
¶
Overview ¶
Package gh wraps the go-github client with the GitHub helpers (PRs, files, labels) shared between katbyte's tools.
Index ¶
- Constants
- func WrapGitHubError(err error, action string) error
- type Repo
- func (r Repo) CheckoutPR(repoPath string, prNumber int) (string, error)
- func (r Repo) CloneURL() string
- func (r Repo) DownloadFile(ctx context.Context, httpClient *http.Client, path, ref string) (content []byte, statusCode int, err error)
- func (r Repo) GetAllPullRequests(state string) (*[]github.PullRequest, error)
- func (r Repo) GetLabelsFor(number int) (*[]string, error)
- func (r Repo) GetPrForBuild(number int) (*github.PullRequest, error)
- func (r Repo) ListAllPullRequestFiles(pri int, cb func([]*github.CommitFile, *github.Response) error) error
- func (r Repo) ListAllPullRequests(state string, cb func([]*github.PullRequest, *github.Response) error) error
- func (r Repo) NewClient() (*github.Client, context.Context)
- func (r Repo) PrURL(pr int) string
- type Token
Constants ¶
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
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 (Repo) CheckoutPR ¶ added in v1.0.0
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) 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) 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.