github

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2026 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package github reads GitHub state through the gh CLI for loom's session cards and issue picker. It is standalone: no app, ui, or session imports. Every entry point fails closed — when gh is missing, unauthenticated, or offline the caller gets an error and renders nothing, never a guess.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckCLI

func CheckCLI(r internalexec.Executor) error

CheckCLI reports whether gh is installed and authenticated. The messages are user-facing (they surface in the picker and the push error path).

func ParseShorthand

func ParseShorthand(prompt string) (n int, rest string, ok bool)

ParseShorthand recognizes a prompt whose first token is "#<n>" and returns the number and the remaining text (trimmed). ok is false for anything else, including "#0".

func SeedPrompt

func SeedPrompt(is Issue) string

SeedPrompt composes the agent's initial prompt from an issue: a preamble naming the issue and URL, the title as a heading, then the body verbatim.

func SlugTitle

func SlugTitle(is Issue) string

SlugTitle yields the session title for an issue: "gh-<n>-<slug>", where slug is the lowercased title with every non-alphanumeric run collapsed to one dash, capped at slugMax and trimmed of a trailing dash. A title with no usable characters yields "gh-<n>".

Types

type Checks

type Checks int

Checks is the folded CI status of a pull request's head commit.

const (
	ChecksNone Checks = iota
	ChecksPending
	ChecksPassing
	ChecksFailing
)

type Issue

type Issue struct {
	Number int
	Title  string
	Body   string
	URL    string
	Labels []string
	Closed bool
}

Issue is one GitHub issue. Body is empty in list results and populated by View.

func View

func View(ctx context.Context, repoDir string, number int, r internalexec.Executor) (Issue, error)

View fetches one issue with its body, for the picker and the #123 prompt shorthand.

type PR

type PR struct {
	Number int
	State  PRState
	Review Review
	Checks Checks
}

PR is one pull request keyed by its head branch in Snapshot.PRs.

type PRState

type PRState int

PRState is the folded pull-request lifecycle state.

const (
	PRNone PRState = iota
	PRDraft
	PROpen
	PRMerged
	PRClosed
)

type Review

type Review int

Review is the folded review decision on a pull request.

const (
	ReviewNone Review = iota
	ReviewApproved
	ReviewChangesRequested
)

type Snapshot

type Snapshot struct {
	PRs       map[string]PR // keyed by head branch name
	Issues    map[int]Issue // keyed by issue number
	FetchedAt time.Time
}

Snapshot is one repo's GitHub state at FetchedAt.

func Query

func Query(ctx context.Context, repoDir string, linked []int, r internalexec.Executor) (Snapshot, error)

Query fetches repoDir's PRs (all states, reduced to one per head branch) and open issues. linked lists issue numbers loom sessions reference; any of them absent from the open list (i.e. closed) is backfilled with one `gh issue view` each — a backfill failure only omits that issue. A pr/issue list failure is fatal: the caller must drop its cached snapshot rather than keep a stale one.

type State

type State struct {
	Known       bool
	IssueNumber int
	// IssueTitle is empty until a snapshot resolves the number, so ""
	// means "not resolved yet", not "an issue with a blank title".
	// IssueClosed is likewise only meaningful once the title is set.
	IssueTitle  string
	IssueClosed bool
	HasPR       bool
	PRNumber    int
	// PRState, Review and Checks are meaningless unless HasPR: they sit
	// at their None zero values for a session with no PR, which is not
	// a state any real PR can be in. Always branch on HasPR first.
	PRState PRState
	Review  Review
	Checks  Checks
}

State is the per-session join of a Snapshot, ready for rendering. Known=false means the repo was not (successfully) queried and the UI must render nothing; Known=true with HasPR=false means "no PR" — the two must never be conflated.

func StateFor

func StateFor(snap Snapshot, known bool, branch string, issue int) State

StateFor joins snap onto one session: its PR by branch, its issue by the linked number (0 = none). known reports whether snap is real.

Jump to

Keyboard shortcuts

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