Documentation
¶
Overview ¶
Package gh is the thin GitHub API layer: one interface the commands are written against, and a go-gh-backed implementation that reuses gh's stored credentials.
Index ¶
- type AuthError
- type Client
- type CloseReason
- type GitHub
- func (g *GitHub) AddAssignee(ctx context.Context, number int, login string) error
- func (g *GitHub) AddBlockedBy(ctx context.Context, number, blockingNumber int) error
- func (g *GitHub) AddLabels(ctx context.Context, number int, labels []string) error
- func (g *GitHub) AddSubIssue(ctx context.Context, parentNumber, childNumber int, replaceParent bool) error
- func (g *GitHub) CloseIssue(ctx context.Context, number int, reason CloseReason) error
- func (g *GitHub) Comment(ctx context.Context, number int, body string) error
- func (g *GitHub) CreateIssue(ctx context.Context, title, body string, labels []string) (model.Issue, error)
- func (g *GitHub) CreateLabel(ctx context.Context, label Label) error
- func (g *GitHub) CreatePullRequest(ctx context.Context, pr NewPullRequest) (PullRequest, error)
- func (g *GitHub) EditBody(ctx context.Context, number int, body string) error
- func (g *GitHub) EditTitle(ctx context.Context, number int, title string) error
- func (g *GitHub) GetIssue(ctx context.Context, number int) (model.Issue, error)
- func (g *GitHub) ListIssues(ctx context.Context, states []IssueState) ([]model.Issue, error)
- func (g *GitHub) ListLabels(ctx context.Context) ([]Label, error)
- func (g *GitHub) PullRequestContext(ctx context.Context, head string) (PRContext, error)
- func (g *GitHub) RemoveAssignees(ctx context.Context, number int, logins []string) error
- func (g *GitHub) RemoveBlockedBy(ctx context.Context, number, blockingNumber int) error
- func (g *GitHub) RemoveLabel(ctx context.Context, number int, label string) error
- func (g *GitHub) RemoveSubIssue(ctx context.Context, parentNumber, childNumber int) error
- func (g *GitHub) ReopenIssue(ctx context.Context, number int) error
- func (g *GitHub) SearchIssues(ctx context.Context, terms string) ([]model.Issue, int, error)
- func (g *GitHub) Viewer(ctx context.Context) (string, error)
- type IssueState
- type Label
- type NewPullRequest
- type PRContext
- type PullRequest
- type Repo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AuthError ¶
type AuthError struct{ Err error }
AuthError marks failures that mean "run gh auth login", mapped to a distinct exit code by main.
type Client ¶
type Client interface {
// Viewer returns the authenticated user's login.
Viewer(ctx context.Context) (string, error)
// ListIssues fetches all issues in the given states with body, labels,
// assignees, parent, sub-issues, and blockers, paginating the outer
// connection. Nested connections are capped (see query).
ListIssues(ctx context.Context, states []IssueState) ([]model.Issue, error)
// GetIssue fetches one issue in any state, including body and recent
// comments.
GetIssue(ctx context.Context, number int) (model.Issue, error)
// SearchIssues runs a repo-scoped text search over issues in both
// states, in the API's best-match order. Results are capped (see
// searchCap); total is the server's full match count so callers can
// warn on truncation.
SearchIssues(ctx context.Context, terms string) (issues []model.Issue, total int, err error)
CreateIssue(ctx context.Context, title, body string, labels []string) (model.Issue, error)
EditTitle(ctx context.Context, number int, title string) error
EditBody(ctx context.Context, number int, body string) error
AddLabels(ctx context.Context, number int, labels []string) error
RemoveLabel(ctx context.Context, number int, label string) error
AddAssignee(ctx context.Context, number int, login string) error
RemoveAssignees(ctx context.Context, number int, logins []string) error
Comment(ctx context.Context, number int, body string) error
// Every method below identifies issues by number; the GraphQL-backed
// implementations resolve node IDs internally, so callers never juggle
// two identifier families.
CloseIssue(ctx context.Context, number int, reason CloseReason) error
// ReopenIssue reopens a closed issue. There is no reason enum to pass:
// GitHub records the reopen itself as the state reason.
ReopenIssue(ctx context.Context, number int) error
// AddBlockedBy marks number as blocked by blockingNumber.
AddBlockedBy(ctx context.Context, number, blockingNumber int) error
RemoveBlockedBy(ctx context.Context, number, blockingNumber int) error
AddSubIssue(ctx context.Context, parentNumber, childNumber int, replaceParent bool) error
RemoveSubIssue(ctx context.Context, parentNumber, childNumber int) error
ListLabels(ctx context.Context) ([]Label, error)
CreateLabel(ctx context.Context, label Label) error
// PullRequestContext fetches the default branch and any open pull
// request whose head is the given branch.
PullRequestContext(ctx context.Context, head string) (PRContext, error)
CreatePullRequest(ctx context.Context, pr NewPullRequest) (PullRequest, error)
}
Client is the API surface the commands use; the tests fake it.
type CloseReason ¶
type CloseReason string
CloseReason is why an issue is closed, matching GitHub's IssueClosedStateReason enum.
const ( CloseCompleted CloseReason = "COMPLETED" CloseNotPlanned CloseReason = "NOT_PLANNED" CloseDuplicate CloseReason = "DUPLICATE" )
type GitHub ¶
type GitHub struct {
// contains filtered or unexported fields
}
GitHub implements Client against the real API via go-gh.
func NewWithOptions ¶
func NewWithOptions(repo Repo, opts api.ClientOptions) (*GitHub, error)
NewWithOptions exists for tests, which inject a Transport.
func (*GitHub) AddAssignee ¶
func (*GitHub) AddBlockedBy ¶
func (*GitHub) AddSubIssue ¶
func (*GitHub) CloseIssue ¶
func (*GitHub) CreateIssue ¶
func (*GitHub) CreatePullRequest ¶
func (g *GitHub) CreatePullRequest(ctx context.Context, pr NewPullRequest) (PullRequest, error)
func (*GitHub) ListIssues ¶
func (*GitHub) PullRequestContext ¶
func (*GitHub) RemoveAssignees ¶
func (*GitHub) RemoveBlockedBy ¶
func (*GitHub) RemoveLabel ¶
func (*GitHub) RemoveSubIssue ¶
func (*GitHub) ReopenIssue ¶ added in v0.10.0
func (*GitHub) SearchIssues ¶
type IssueState ¶
type IssueState string
IssueState is a GitHub issue state, used to filter list queries. Typed so callers can't misspell the wire enum.
const ( StateOpen IssueState = "OPEN" StateClosed IssueState = "CLOSED" )
type NewPullRequest ¶
type NewPullRequest struct {
Title string
Body string
// Head and Base are branch names in this repo; cross-fork heads are out
// of scope (the workflow branches in place).
Head string
Base string
Draft bool
}
NewPullRequest is the pr command's creation payload.
type PRContext ¶
type PRContext struct {
DefaultBranch string
Existing *PullRequest
}
PRContext is the repo-side state pr needs before creating: the branch to target, and the open pull request already on the head branch, if any. Both come from one query — a second PR on a branch is the failure the command must name, not discover from a 422.
type PullRequest ¶
PullRequest is a pull request, reduced to what the pr command reports.