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
- Variables
- func API(ctx context.Context, method, path string, body any) ([]byte, error)
- func Binary() string
- func ByBranch(prs []PR) map[string]PR
- func CommentIssue(ctx context.Context, dir string, number int, body string) error
- func Create(ctx context.Context, dir, base, head, title, body string, draft bool) (string, error)
- func EditLabels(ctx context.Context, dir string, number int, add, remove []string) error
- func EnsureLabel(ctx context.Context, dir, label, color, about string) error
- func FailedRunID(ctx context.Context, dir, branch, head string) (int64, error)
- func IssueCount(ctx context.Context, dir string, mine bool, limit int) (int, error)
- func Merge(ctx context.Context, dir string, number int, head string) (string, error)
- func NoRepository(err error) bool
- func Ready(ctx context.Context, dir string, number int) error
- func Rerun(ctx context.Context, dir string, id int64) error
- func Review(ctx context.Context, dir string, number int, event, body string, ...) error
- func Whoami(ctx context.Context, dir string) (string, error)
- type CIDay
- type CIFlaky
- type CIJob
- type CIStats
- type Check
- type Comment
- type FailedRun
- type Issue
- type IssueRow
- type Job
- type LineComment
- type PR
- type Reviews
- type Run
- type Thread
Constants ¶
const ( ChecksPass = "pass" ChecksFail = "fail" ChecksPending = "pending" )
Check summaries.
Variables ¶
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.
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
API calls GitHub's REST API through gh, with body sent as JSON when there is one, and returns the reply.
func ByBranch ¶
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
CommentIssue adds a comment to issue number of the repository at dir.
func Create ¶ added in v0.1.1
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
EditLabels adds and removes labels on issue number.
func EnsureLabel ¶ added in v0.2.1
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
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
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
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
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 Rerun ¶ added in v0.2.1
Rerun runs a run's failed jobs again, as a new attempt of the same run.
Types ¶
type CIFlaky ¶ added in v0.2.1
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 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
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
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
IssueByNumber reads one issue of the repository at dir.
type IssueRow ¶ added in v0.2.1
IssueRow is an issue as a list of them shows it: no body, and who it is assigned to.
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.
type Reviews ¶ added in v0.1.9
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
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
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.
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.