gh

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2026 License: MIT Imports: 9 Imported by: 0

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

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.

func (*AuthError) Error

func (e *AuthError) Error() string

func (*AuthError) Unwrap

func (e *AuthError) Unwrap() error

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 New

func New(repo Repo) (*GitHub, error)

New builds a client using gh's stored credentials and host config.

func NewWithOptions

func NewWithOptions(repo Repo, opts api.ClientOptions) (*GitHub, error)

NewWithOptions exists for tests, which inject a Transport.

func (*GitHub) AddAssignee

func (g *GitHub) AddAssignee(ctx context.Context, number int, login string) error

func (*GitHub) AddBlockedBy

func (g *GitHub) AddBlockedBy(ctx context.Context, number, blockingNumber int) error

func (*GitHub) AddLabels

func (g *GitHub) AddLabels(ctx context.Context, number int, labels []string) error

func (*GitHub) AddSubIssue

func (g *GitHub) AddSubIssue(ctx context.Context, parentNumber, childNumber int, replaceParent bool) error

func (*GitHub) CloseIssue

func (g *GitHub) CloseIssue(ctx context.Context, number int, reason CloseReason) error

func (*GitHub) Comment

func (g *GitHub) Comment(ctx context.Context, number int, body string) error

func (*GitHub) CreateIssue

func (g *GitHub) CreateIssue(ctx context.Context, title, body string, labels []string) (model.Issue, error)

func (*GitHub) CreateLabel

func (g *GitHub) CreateLabel(ctx context.Context, label Label) error

func (*GitHub) CreatePullRequest

func (g *GitHub) CreatePullRequest(ctx context.Context, pr NewPullRequest) (PullRequest, error)

func (*GitHub) EditBody

func (g *GitHub) EditBody(ctx context.Context, number int, body string) error

func (*GitHub) EditTitle

func (g *GitHub) EditTitle(ctx context.Context, number int, title string) error

func (*GitHub) GetIssue

func (g *GitHub) GetIssue(ctx context.Context, number int) (model.Issue, error)

func (*GitHub) ListIssues

func (g *GitHub) ListIssues(ctx context.Context, states []IssueState) ([]model.Issue, error)

func (*GitHub) ListLabels

func (g *GitHub) ListLabels(ctx context.Context) ([]Label, error)

func (*GitHub) PullRequestContext

func (g *GitHub) PullRequestContext(ctx context.Context, head string) (PRContext, error)

func (*GitHub) RemoveAssignees

func (g *GitHub) RemoveAssignees(ctx context.Context, number int, logins []string) error

func (*GitHub) RemoveBlockedBy

func (g *GitHub) RemoveBlockedBy(ctx context.Context, number, blockingNumber int) error

func (*GitHub) RemoveLabel

func (g *GitHub) RemoveLabel(ctx context.Context, number int, label string) error

func (*GitHub) RemoveSubIssue

func (g *GitHub) RemoveSubIssue(ctx context.Context, parentNumber, childNumber int) error

func (*GitHub) ReopenIssue added in v0.10.0

func (g *GitHub) ReopenIssue(ctx context.Context, number int) error

func (*GitHub) SearchIssues

func (g *GitHub) SearchIssues(ctx context.Context, terms string) ([]model.Issue, int, error)

func (*GitHub) Viewer

func (g *GitHub) Viewer(ctx context.Context) (string, error)

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 Label

type Label struct {
	Name        string
	Color       string
	Description string
}

Label mirrors a repository label for init's bootstrap pass.

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

type PullRequest struct {
	Number int
	URL    string
	Draft  bool
}

PullRequest is a pull request, reduced to what the pr command reports.

type Repo

type Repo struct {
	Owner string
	Name  string
}

Repo identifies the target repository.

func (Repo) String

func (r Repo) String() string

Jump to

Keyboard shortcuts

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