Documentation
¶
Overview ¶
Package ghops executes the GitHub mechanics of the Delivery workflow (PRD §12 steps 6, 9, 13-17) through the authenticated gh CLI (PRD §5), via an injected execx.Runner: repository resolution, the PRD §13 label taxonomy, issue lifecycle, and PR open, status, required-CI state, and merge.
The package is policy-free like gitops: callers supply issue titles, bodies, branch names, and label values — naming policy belongs to the run engine, and issue and PR bodies (the PRD §13 audit record) are opaque strings here. Every operation fails closed: any gh error propagates, destructive operations require an explicit Confirmation (PRD §15), and merging is only ever invoked after the human merge gate (PRD §8) — ghops itself never decides to merge.
Operations that pre-check and then act (for example EnsureLabelTaxonomy) are not atomic; the run engine serializes potentially conflicting writes (PRD §14), so the gap is not raced in practice.
Index ¶
- Variables
- type CIState
- type CISummary
- type Check
- type Confirmation
- type GH
- func (g *GH) CloseIssue(ctx context.Context, number int, c Confirmation) error
- func (g *GH) ClosePR(ctx context.Context, number int, c Confirmation) error
- func (g *GH) CreateIssue(ctx context.Context, title, body string, labels Labels, ...) (number int, url string, err error)
- func (g *GH) CreatePR(ctx context.Context, spec PRSpec) (number int, url string, err error)
- func (g *GH) EnsureLabelTaxonomy(ctx context.Context) ([]string, error)
- func (g *GH) Issue(ctx context.Context, number int) (Issue, error)
- func (g *GH) MergePR(ctx context.Context, number int, strategy, headOID string, c Confirmation) error
- func (g *GH) MissingLabels(ctx context.Context, names []string) ([]string, error)
- func (g *GH) PR(ctx context.Context, number int) (PR, error)
- func (g *GH) PRForBranch(ctx context.Context, head string) (*PR, error)
- func (g *GH) Repo(ctx context.Context) (Repo, error)
- func (g *GH) RequiredCI(ctx context.Context, number int) (CISummary, error)
- func (g *GH) Root() string
- func (g *GH) SetIssueBody(ctx context.Context, number int, body string) error
- func (g *GH) SetPRBody(ctx context.Context, number int, body string) error
- func (g *GH) SetRole(ctx context.Context, number int, to Role) error
- func (g *GH) SetStatus(ctx context.Context, number int, to Status) error
- type Issue
- type Labels
- type PR
- type PRSpec
- type Repo
- type Risk
- type Role
- type Status
- type Type
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotAuthenticated reports that gh has no usable credentials // (PRD §5: Delivery fails closed unless authentication passes). ErrNotAuthenticated = errors.New("gh is not authenticated") // ErrNoGitHubRepo reports that gh could not resolve a GitHub // repository from this directory (PRD §5: Assist may operate // without a remote; Delivery fails closed). ErrNoGitHubRepo = errors.New("no GitHub repository resolved from this directory") // ErrBadLabels reports labels violating the PRD §13 taxonomy: // exactly one value per group, no reserved or forbidden area // names (models never become GitHub labels). ErrBadLabels = errors.New("labels do not satisfy the label taxonomy") // ErrNotConfirmed reports a destructive operation attempted // without ExplicitConfirmation (PRD §15). ErrNotConfirmed = errors.New("destructive operation requires explicit confirmation") )
Sentinel errors callers test with errors.Is. Each marks an expected fail-closed condition detected by a structured check (exit codes, closed enums, the Confirmation token) — never by parsing gh's human-readable output, whose wording varies across versions.
Functions ¶
This section is empty.
Types ¶
type CIState ¶
type CIState string
CIState is the PRD §16 merge-gate signal over a PR's required checks.
const ( CINoChecks CIState = "no-checks" CIPending CIState = "pending" CIFailing CIState = "failing" CIPassing CIState = "passing" )
The four CI states. CINoChecks is distinct from CIPassing because "if no CI exists, the plan gate states that explicitly" (PRD §16) — green and absent must never be conflated.
type CISummary ¶
CISummary reports the required-CI state of one PR: the derived gate signal, the required checks as evidence (PRD §15: CI state is reported honestly), and the total check count so the engine can phrase "CI exists but none of it is required" explicitly.
type Check ¶
type Check struct {
Name string
// State is the check's own state string as reported by gh.
State string
// Bucket is gh's classification: pass, fail, pending, skipping,
// or cancel.
Bucket string
// Link points at the check's detail page, for the ready-to-merge
// report.
Link string
}
Check is one required check on a PR.
type Confirmation ¶
type Confirmation struct {
// contains filtered or unexported fields
}
Confirmation is a typed approval token for destructive operations. The zero value fails closed; only ExplicitConfirmation produces a confirming token. ghops never prompts — collecting the human's approval is the caller's job (PRD §8, §15).
func ExplicitConfirmation ¶
func ExplicitConfirmation() Confirmation
ExplicitConfirmation returns a token stating the caller obtained explicit approval for a destructive operation.
type GH ¶
type GH struct {
// contains filtered or unexported fields
}
GH executes GitHub operations against one repository through an injected execx.Runner.
func Open ¶
Open binds to the repository whose primary checkout root is repoRoot and verifies gh authentication with a `gh auth status` probe: a non-zero exit means no usable credentials and Open fails closed with ErrNotAuthenticated (PRD §5). The exit code is the structured signal — gh's human-readable status text is never parsed. Repository association is checked separately by Repo, because Assist may operate without a GitHub remote (PRD §5); the Delivery preflight composes Open and Repo.
func (*GH) CloseIssue ¶
CloseIssue closes the issue. Closing is destructive bookkeeping (PRD §12 step 17 confirms closure only after the merge result is recorded), so it requires ExplicitConfirmation.
func (*GH) ClosePR ¶
ClosePR closes a PR without merging; abandoning tracked work is destructive bookkeeping and requires ExplicitConfirmation.
func (*GH) CreateIssue ¶
func (g *GH) CreateIssue(ctx context.Context, title, body string, labels Labels, forbiddenAreas ...string) (number int, url string, err error)
CreateIssue creates an issue carrying the full PRD §13 taxonomy. The body (the audit record) is opaque to ghops and travels over stdin, never the command line. Labels are validated before any gh call; forbiddenAreas is the caller's model-name denylist (PRD §13: models do not become GitHub labels).
func (*GH) CreatePR ¶
CreatePR opens one PR for the issue's feature branch (PRD §12 step 9). The body travels over stdin, never the command line.
func (*GH) EnsureLabelTaxonomy ¶
EnsureLabelTaxonomy lists the repository's labels and creates any missing taxonomy label with its pinned color and description; existing labels are never modified (no --force: repository customizations survive). Idempotent; returns the names it created, in taxonomy order, for the audit trail. The list-then-create gap is not atomic; the run engine serializes conflicting writes (PRD §14).
func (*GH) Issue ¶
Issue reads one issue; the run engine uses it to confirm closure (PRD §12 step 17).
func (*GH) MergePR ¶
func (g *GH) MergePR(ctx context.Context, number int, strategy, headOID string, c Confirmation) error
MergePR merges an approved PR with the configured strategy. It is only ever invoked after the human merge gate (PRD §8) and requires ExplicitConfirmation. headOID pins the commit the human approved (--match-head-commit): if the PR moved after approval, gh refuses and the merge fails mechanically instead of merging unreviewed commits. Remote branch deletion is deliberately separate (gitops.DeleteRemoteBranch, PRD §12 step 18): --delete-branch would also delete the local branch and touch the invoking checkout, and each destructive act carries its own confirmation.
func (*GH) MissingLabels ¶
MissingLabels reports which of names do not exist in the repository, in the order given (case-insensitive, matching GitHub's label-name semantics). Read-only; what a missing label means is the caller's policy — the run engine fails activation closed on absent plan-declared area labels, because area labels are repository-defined (PRD §13) and orch never invents them.
func (*GH) PR ¶
PR reads one pull request; the run engine uses it for the ready-to-merge report (PRD §12 step 14) and to obtain the HeadRefOid a merge approval pins.
func (*GH) PRForBranch ¶
PRForBranch returns the single open pull request whose head branch is head, or nil when none exists (`gh pr list --head <branch> --state open`). pr-open uses it to fail closed on an orphan PR left by a crashed run (PRD §23 reconciliation); more than one open PR for a branch is impossible on GitHub, so a longer list is an error.
func (*GH) Repo ¶
Repo resolves the GitHub repository from the checkout's remotes. Any non-zero gh exit maps to ErrNoGitHubRepo — gh does not distinguish "no remotes" from network failure by exit code, and both fail Delivery closed (PRD §5); the wrapped stderr names the actual cause for humans.
func (*GH) RequiredCI ¶
RequiredCI reports the state of the PR's required checks. Two probes: `pr view --json statusCheckRollup` distinguishes no-CI-at-all (empty rollup — PRD §16's explicit no-CI statement) before `pr checks --required` reads the required subset, whose exit codes 0 (passing), 1 (something failed), and 8 (pending, documented by gh) are all data, not errors.
func (*GH) SetIssueBody ¶
SetIssueBody replaces the issue body (the PRD §13 audit record is updated as routing decisions and verification results accumulate).
func (*GH) SetPRBody ¶
SetPRBody replaces the PR body (the PRD §13 audit record is mirrored onto the PR while it is the active surface). The body travels over stdin, never the command line.
func (*GH) SetRole ¶
SetRole moves the issue to role to, removing every other role label in one edit so the exactly-one-role invariant of PRD §13 survives an escalation that changes the executor role. Removing an absent label is a no-op for gh.
type Issue ¶
type Issue struct {
Number int
// State is GitHub's issue state, "OPEN" or "CLOSED".
State string
Title string
URL string
Labels []string
// Body is the raw issue body (the PRD §13 audit record), which
// resume/recovery parses back into run state (PRD §23).
Body string
}
Issue is the read-back view of a GitHub issue.
type Labels ¶
Labels is the complete PRD §13 taxonomy for one issue: exactly one value per group plus optional repository-defined area labels.
func (Labels) Validate ¶
Validate enforces the taxonomy mechanically: each group value must be a member of its closed set (a zero value fails — exactly one per group), and every area label must be non-empty, unique, not a reserved taxonomy name, and not equal to any caller-supplied forbidden string (all case-insensitive). The run engine passes the configured model names as forbidden, making PRD §13's "models do not become GitHub labels" a mechanical check rather than a convention. All failures wrap ErrBadLabels.
type PR ¶
type PR struct {
Number int
// State is "OPEN", "CLOSED", or "MERGED".
State string
Title string
URL string
// HeadRefName and BaseRefName are the branch names.
HeadRefName, BaseRefName string
// HeadRefOid is the head commit SHA the human's merge approval
// refers to; MergePR pins it (PRD §8).
HeadRefOid string
// MergeStateStatus is GitHub's merge-state summary, for example
// "CLEAN", "BLOCKED", or "DIRTY".
MergeStateStatus string
// MergedAt is the RFC3339 merge time, empty while unmerged.
MergedAt string
// Body is the raw PR body (the PRD §13 audit record), which
// resume/recovery parses back into run state (PRD §23).
Body string
}
PR is the read-back view of a pull request.
type PRSpec ¶
type PRSpec struct {
// Head is the feature branch, Base the merge target.
Head, Base string
Title string
Body string
}
PRSpec describes a PR to open. The body (the PRD §13 audit record) is opaque to ghops.
type Repo ¶
type Repo struct {
// NameWithOwner is the owner/name slug, for example "octo/orch".
NameWithOwner string
// DefaultBranch is the repository's default branch name.
DefaultBranch string
// URL is the repository's web URL.
URL string
}
Repo identifies the GitHub repository gh resolves from the primary checkout's remotes.
type Risk ¶
type Risk string
Risk is the exactly-one risk-class label (PRD §13); risk domains route to critical (PRD §11).
type Status ¶
type Status string
Status is the exactly-one workflow-status label (PRD §13).
const ( StatusReady Status = "ready" StatusInProgress Status = "in-progress" StatusBlocked Status = "blocked" StatusNeedsHuman Status = "needs-human" StatusAwaitingReview Status = "awaiting-review" StatusDelivered Status = "delivered" )
The six status labels. Delivered is terminal: merge sets it just before closing the issue, so a closed delivered issue does not keep wearing the needs-human set at merge-report.