ghops

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2026 License: MIT Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

Constants

This section is empty.

Variables

View Source
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

type CISummary struct {
	State    CIState
	Required []Check
	Total    int
}

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

func Open(ctx context.Context, r execx.Runner, repoRoot string) (*GH, error)

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

func (g *GH) CloseIssue(ctx context.Context, number int, c Confirmation) error

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

func (g *GH) ClosePR(ctx context.Context, number int, c Confirmation) error

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

func (g *GH) CreatePR(ctx context.Context, spec PRSpec) (number int, url string, err error)

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

func (g *GH) EnsureLabelTaxonomy(ctx context.Context) ([]string, error)

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

func (g *GH) Issue(ctx context.Context, number int) (Issue, error)

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

func (g *GH) MissingLabels(ctx context.Context, names []string) ([]string, error)

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

func (g *GH) PR(ctx context.Context, number int) (PR, error)

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

func (g *GH) PRForBranch(ctx context.Context, head string) (*PR, error)

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

func (g *GH) Repo(ctx context.Context) (Repo, error)

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

func (g *GH) RequiredCI(ctx context.Context, number int) (CISummary, error)

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) Root

func (g *GH) Root() string

Root returns the canonical primary-checkout root.

func (*GH) SetIssueBody

func (g *GH) SetIssueBody(ctx context.Context, number int, body string) error

SetIssueBody replaces the issue body (the PRD §13 audit record is updated as routing decisions and verification results accumulate).

func (*GH) SetPRBody

func (g *GH) SetPRBody(ctx context.Context, number int, body string) error

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

func (g *GH) SetRole(ctx context.Context, number int, to Role) error

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.

func (*GH) SetStatus

func (g *GH) SetStatus(ctx context.Context, number int, to Status) error

SetStatus moves the issue to status to, removing every other status label in one edit so the exactly-one-status invariant of PRD §13 is restored even if it was violated out-of-band. 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

type Labels struct {
	Status Status
	Type   Type
	Role   Role
	Risk   Risk
	Areas  []string
}

Labels is the complete PRD §13 taxonomy for one issue: exactly one value per group plus optional repository-defined area labels.

func (Labels) Validate

func (l Labels) Validate(forbiddenAreas ...string) error

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).

const (
	RiskStandard Risk = "standard"
	RiskCritical Risk = "critical"
)

The two risk labels.

type Role

type Role string

Role is the exactly-one executor-role label (PRD §13).

const (
	RoleImplementer Role = "implementer"
	RoleSpecialist  Role = "specialist"
)

The two role labels.

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.

type Type

type Type string

Type is the exactly-one change-type label (PRD §13).

const (
	TypeFeature  Type = "feature"
	TypeBug      Type = "bug"
	TypeChore    Type = "chore"
	TypeInfra    Type = "infra"
	TypeDocs     Type = "docs"
	TypeResearch Type = "research"
)

The six type labels.

Jump to

Keyboard shortcuts

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