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 Create(ctx context.Context, dir, base, head, title, body string, draft bool) (string, error)
- func Merge(ctx context.Context, dir string, number int, head string) (string, error)
- func Ready(ctx context.Context, dir string, number int) error
- func Review(ctx context.Context, dir string, number int, event, body string, ...) error
- type Check
- type Comment
- type FailedRun
- type Issue
- type LineComment
- type PR
- type Reviews
- 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 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 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.
Types ¶
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.
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 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 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.