ghx

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: Apache-2.0 Imports: 12 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 ghx reads pull requests through the GitHub CLI, so conch uses the user's existing gh login and never handles tokens itself.

Index

Constants

View Source
const (
	ChecksPass    = "pass"
	ChecksFail    = "fail"
	ChecksPending = "pending"
)

Check summaries.

Variables

View Source
var ErrNoFailedRun = errors.New("no failed GitHub Actions run on this branch")

ErrNoFailedRun means nothing on the branch failed in GitHub Actions: the check that failed is someone else's (a status from another service), or the run has since been retried.

View Source
var ErrNoGH = errors.New("gh (GitHub CLI) is not installed; pull requests, CI and issues need it: https://cli.github.com")

ErrNoGH means the gh binary is not installed.

Functions

func API added in v0.2.0

func API(ctx context.Context, method, path string, body any) ([]byte, error)

API calls GitHub's REST API through gh, with body sent as JSON when there is one, and returns the reply.

func Binary added in v0.1.9

func Binary() string

Binary is the gh conch runs: $CONCH_GH when set.

func ByBranch

func ByBranch(prs []PR) map[string]PR

ByBranch picks one pull request per head branch: an open one when there is one, else the most recently updated. A fork's pull request is left out: its branch is another repository's, and anyone can name one after a branch here — conch would then show its checks as this branch's, send its CI log to this branch's agent, and the autopilot merge it.

func CommentIssue added in v0.2.1

func CommentIssue(ctx context.Context, dir string, number int, body string) error

CommentIssue adds a comment to issue number of the repository at dir.

func Create added in v0.1.1

func Create(ctx context.Context, dir, base, head, title, body string, draft bool) (string, error)

Create opens a pull request from head into base in the repository at dir and returns its URL. The branch must already be pushed. An empty title fills the title and body from the branch's commits.

func EditLabels added in v0.2.1

func EditLabels(ctx context.Context, dir string, number int, add, remove []string) error

EditLabels adds and removes labels on issue number.

func EnsureLabel added in v0.2.1

func EnsureLabel(ctx context.Context, dir, label, color, about string) error

EnsureLabel makes label in the repository at dir unless it is there: gh will not add a label a repository has not got.

func FailedRunID added in v0.2.1

func FailedRunID(ctx context.Context, dir, branch, head string) (int64, error)

FailedRunID is the newest failed Actions run on branch — at commit head when given — for a re-run asked for by branch rather than by run.

func IssueCount added in v0.2.1

func IssueCount(ctx context.Context, dir string, mine bool, limit int) (int, error)

IssueCount counts the open issues of the repository at dir, up to limit; mine counts those assigned to the person gh is signed in as.

func Merge added in v0.1.9

func Merge(ctx context.Context, dir string, number int, head string) (string, error)

Merge merges pull request number on GitHub, the way the repository allows — a merge commit, else a squash, else a rebase, which is the order GitHub's own button offers them — and returns the way it used. head, when given, is the commit the pull request must still be at: a push after its checks passed is not what they passed for, and gh then refuses. The branch itself is left alone, since a worktree may be on it.

func NoRepository added in v0.2.1

func NoRepository(err error) bool

NoRepository says whether err is gh finding no GitHub repository in the checkout: a project with no GitHub remote has no issues to list, which is not a failure.

func Ready added in v0.1.9

func Ready(ctx context.Context, dir string, number int) error

Ready takes pull request number out of draft.

func Rerun added in v0.2.1

func Rerun(ctx context.Context, dir string, id int64) error

Rerun runs a run's failed jobs again, as a new attempt of the same run.

func Review added in v0.1.9

func Review(ctx context.Context, dir string, number int, event, body string, comments []LineComment) error

Review submits a review of pull request number. event is approve, request_changes or comment; the last two need a body or a comment, as GitHub insists.

func Whoami added in v0.2.1

func Whoami(ctx context.Context, dir string) (string, error)

Whoami is the GitHub login gh is signed in as, asked in dir (any folder will do: the login is gh's, not the repository's).

Types

type CIDay added in v0.2.1

type CIDay struct {
	Date           string // YYYY-MM-DD in the server's time zone
	Passed, Failed int
}

CIDay is one day's finished runs.

type CIFlaky added in v0.2.1

type CIFlaky struct {
	Name  string
	Times int
	How   string
	Last  time.Time
}

CIFlaky is a job (or a whole run) that failed and passed with nothing changed: on the same commit, or on a second attempt of the same run.

type CIJob added in v0.2.1

type CIJob struct {
	Name                      string
	Runs, Failed              int
	MedianSeconds, P90Seconds int
}

CIJob is one job's record over the period.

type CIStats added in v0.2.1

type CIStats struct {
	Days int
	// Finished runs that passed or failed in the period (a cancelled or
	// skipped run is neither), and the same for the period before it.
	Runs, Passed, Failed int
	PrevRuns, PrevPassed int
	// Medians, in seconds, of a run's time from start to finish and of
	// its wait in the queue; the run time also for the period before.
	MedianSeconds, PrevMedianSeconds, QueueSeconds int
	// How long a branch stayed red: from a failed run to the next passing
	// run of the same workflow on the same branch, median, and how many.
	RedToGreenSeconds, RedToGreenCount int
	// One entry a day, the oldest first and today last.
	Daily []CIDay
	// Each job, the slowest (by median) first.
	Jobs []CIJob
	// Jobs and runs that failed and then passed without a change.
	Flaky []CIFlaky
	// The newest run of each workflow on each branch, where it failed:
	// what can be run again.
	Failing []Run
	// How many of the period's runs had their jobs read.
	JobsRead int
}

CIStats is what the CI panel shows for a period of whole days.

func ComputeStats added in v0.2.1

func ComputeStats(runs []Run, jobs map[int64][]Job, now time.Time, days int, loc *time.Location) CIStats

ComputeStats works out a period's statistics: the days days up to and including now's (in loc), and the same number before them. jobs holds the jobs of whichever runs have been read.

type Check added in v0.1.9

type Check struct {
	Name  string // the job's name, or the status's context
	State string // ChecksPass, ChecksFail or ChecksPending
	URL   string
}

Check is one of a pull request's checks: a job of a workflow run, or a commit status another service set.

type Comment added in v0.1.9

type Comment struct {
	ID     int64
	Author string
	Body   string
	URL    string
	At     time.Time
	State  string // a review's: CHANGES_REQUESTED, COMMENTED
}

Comment is one comment of a thread, or a review's own words.

type FailedRun added in v0.1.9

type FailedRun struct {
	ID       int64
	Workflow string
	URL      string
	Log      string // the failed steps' output, as gh prints it
}

FailedRun is a GitHub Actions run that failed on a branch, with the log of its failed steps.

func FailedLog added in v0.1.9

func FailedLog(ctx context.Context, dir, branch, head string) (FailedRun, error)

FailedLog finds the newest failed Actions run on branch in the repository at dir — at commit head when given, so a run about older work is not mistaken for this one — and fetches its failed steps' log.

func RerunFailed added in v0.2.1

func RerunFailed(ctx context.Context, dir, branch, head string) ([]FailedRun, error)

RerunFailed re-runs the failed jobs of every failed Actions run on branch at head — or, with no head, at the commit of the newest failure — one `gh run rerun --failed` per run, and says which runs those were, newest first. Several workflows fail at one commit (test and lint, say), and re-running only the newest left the rest red. Each workflow's newest failure is the one re-run. The runs re-run are returned even when another could not be, with that error.

type Issue added in v0.1.9

type Issue struct {
	Number int      `json:"number"`
	Title  string   `json:"title"`
	Body   string   `json:"body"`
	URL    string   `json:"url"`
	Labels []string `json:"labels,omitempty"`
}

Issue is a GitHub issue, as much of it as a task needs.

func IssueByNumber added in v0.1.9

func IssueByNumber(ctx context.Context, dir string, number int) (Issue, error)

IssueByNumber reads one issue of the repository at dir.

func Issues added in v0.1.9

func Issues(ctx context.Context, dir string, limit int) ([]Issue, error)

Issues lists the open issues of the repository at dir, newest first, up to limit.

func IssuesLabelled added in v0.2.1

func IssuesLabelled(ctx context.Context, dir, label string, limit int) ([]Issue, error)

IssuesLabelled lists the open issues of the repository at dir that carry label, oldest first — the order a backlog is worked in — up to limit.

type IssueRow added in v0.2.1

type IssueRow struct {
	Number    int
	Title     string
	URL       string
	Labels    []string
	Assignees []string
}

IssueRow is an issue as a list of them shows it: no body, and who it is assigned to.

func IssueRows added in v0.2.1

func IssueRows(ctx context.Context, dir string, limit int) ([]IssueRow, error)

IssueRows lists the open issues of the repository at dir, newest first, up to limit, without their bodies.

type Job added in v0.2.1

type Job struct {
	Name       string
	Conclusion string
	Started    time.Time
	Completed  time.Time
}

Job is one job of a run.

func RunJobs added in v0.2.1

func RunJobs(ctx context.Context, dir string, id int64) ([]Job, error)

RunJobs lists a run's jobs. A finished run's jobs never change, so a caller may keep them.

type LineComment added in v0.1.9

type LineComment struct {
	Path string `json:"path"`
	Line int    `json:"line"`
	Side string `json:"side"`
	Body string `json:"body"`
}

LineComment is a comment on one line of a pull request's diff, on its new side.

type PR

type PR struct {
	Number int
	Title  string
	State  string // OPEN, MERGED, CLOSED
	Draft  bool
	URL    string
	Branch string // head branch
	// Fork says the head branch is another repository's: Branch then names
	// a branch there, which only shares its name with any branch here.
	Fork   bool
	Base   string // the branch it merges into
	Head   string // head commit
	Review string // APPROVED, CHANGES_REQUESTED, REVIEW_REQUIRED or ""
	// Conflicting is GitHub saying the branch cannot merge into its base
	// as it stands. GitHub works it out after a push, so until then it is
	// false: unknown is not a conflict.
	Conflicting bool
	Checks      string // ChecksPass, ChecksFail, ChecksPending or "" when none
	Passed      int    // checks that passed
	Total       int    // checks reported
	Updated     time.Time
	// Runs are the checks one by one, in GitHub's order: what is running,
	// what failed, and where to see it.
	Runs []Check
}

PR is a pull request.

func List

func List(ctx context.Context, dir string) ([]PR, error)

List returns recent pull requests of the repository in dir. The gh binary is $CONCH_GH when set.

func Parse

func Parse(data []byte) ([]PR, error)

Parse decodes `gh pr list --json` output.

type Reviews added in v0.1.9

type Reviews struct {
	Threads []Thread
	Reviews []Comment
}

Reviews is what reviewers said on a pull request that is still open to act on: the threads nobody resolved, and the reviews that said something besides approving.

func PRReviews added in v0.1.9

func PRReviews(ctx context.Context, dir string, number int) (Reviews, error)

PRReviews reads what reviewers said on pull request number of the repository in dir. gh fills in the repository from the checkout.

func ParseReviews added in v0.1.9

func ParseReviews(data []byte) (Reviews, error)

ParseReviews decodes PRReviews' answer, keeping what is still to act on.

type Run added in v0.2.1

type Run struct {
	ID         int64
	Workflow   string
	Branch     string
	Sha        string
	Event      string
	Status     string // queued, in_progress, completed
	Conclusion string // success, failure, cancelled, timed_out, skipped… once completed
	Attempt    int
	URL        string
	Created    time.Time
	Started    time.Time
	Updated    time.Time
}

Run is one workflow run, at its latest attempt.

func Runs added in v0.2.1

func Runs(ctx context.Context, dir string, limit int) ([]Run, error)

Runs lists the repository's newest workflow runs, up to limit.

type Thread added in v0.1.9

type Thread struct {
	Path     string
	Line     int
	Outdated bool
	Hunk     string // the diff GitHub shows above the comment, ending at its line
	Comments []Comment
}

Thread is an unresolved conversation on a line of a pull request's diff. Line is where it is now; an outdated thread — its lines changed since — has only the line it was written on.

Jump to

Keyboard shortcuts

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