pr

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package pr resolves PR state for a list of (repo, branch) pairs by shelling out to `gh`. It is the source-of-truth in v2 for whether a worktree's branch is open / merged / closed; the per-Phase Status field on the on-disk sandbox record is just a 60-second cache.

The package is deliberately small: one entry point, one shape of answer, and one shim seam (the GHBin variable) for tests. Anything fancier (auth probing, multi-account orchestration) belongs in `gh` itself.

Index

Constants

This section is empty.

Variables

View Source
var GHBin = "gh"

GHBin is the binary runGH execs. A variable, deliberately not an env knob: tests (here and in internal/cli) swap in a fixture shim that prints canned JSON, and no public surface exists to point clawk at a different gh — that's what PATH is for.

Functions

This section is empty.

Types

type Result

type Result struct {
	Branch string `json:"branch"`
	State  State  `json:"state"`
	Number int    `json:"number,omitempty"`
	URL    string `json:"url,omitempty"`
}

Result describes the canonical PR for one (repo, branch). When State is StateUnknown, Number is zero and the rest of the fields are undefined.

func Resolve

func Resolve(repo string, branches []string) ([]Result, error)

Resolve queries `gh pr list` once for the given repo and returns one Result per branch the caller asked about. Branches with no PR are returned with State=StateUnknown rather than omitted, so callers can iterate the slice they passed in lock-step with the response.

gh requires a working directory inside a git repo (it reads the remote URL from there). repo must therefore be the path to a git checkout, not a remote URL.

One process per repo: PR listing is cheap on the GitHub side (single REST call) and avoiding O(branches) processes keeps a 10-branch sandbox snappy.

type State

type State string

State is the PR lifecycle as gh reports it. "unknown" covers the cases where gh failed (network, auth) or returned no rows for a branch — caller decides whether to fall back to a cached value or treat it as "no PR yet".

const (
	StateOpen    State = "open"
	StateMerged  State = "merged"
	StateClosed  State = "closed"
	StateUnknown State = "unknown"
)

Jump to

Keyboard shortcuts

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