Documentation
¶
Overview ¶
Package forge binds a forge's CLI, gh or glab. Every call goes through Host, so each CLI's spelling is picked in one place and its JSON read into one shape per noun; a non-zero exit is the CLI's own stderr verbatim, since it names the cause better than any paraphrase.
Index ¶
- Constants
- Variables
- func Names(checks []Check) string
- func PullNumber(url string) string
- func SameLogin(declared, login string) bool
- func Status(state string) string
- type Activity
- type CI
- type Check
- type Child
- type Comment
- type CommitStatus
- type Error
- type Event
- type ForcePush
- type HeadChecks
- type Host
- func (h Host) Activity(ctx context.Context, since time.Time) (Activity, error)
- func (h Host) AllIssues(ctx context.Context) ([]Issue, error)
- func (h Host) At(dir string) Host
- func (h Host) Branches(ctx context.Context) (map[string]bool, error)
- func (h Host) Children(ctx context.Context, number string) ([]Child, error)
- func (h Host) CommentIssue(ctx context.Context, number, body string) (string, error)
- func (h Host) CommitCI(ctx context.Context, sha string) (*CI, error)
- func (h Host) CreateIssue(ctx context.Context, title, body string, labels []string) (string, string, error)
- func (h Host) CreatePull(ctx context.Context, n NewPull) error
- func (h Host) DecidingPull(ctx context.Context, branch string) (PR, bool, error)
- func (h Host) DefaultBranchName(ctx context.Context) (string, error)
- func (h Host) DefaultJob(ctx context.Context, name string) (string, error)
- func (h Host) DeleteBranch(ctx context.Context, branch string) error
- func (h Host) EarlierRequests(ctx context.Context, ids []string) (map[string][]PR, error)
- func (h Host) EditIssue(ctx context.Context, number string, e IssueEdit) error
- func (h Host) EditPull(ctx context.Context, selector, title, body string) error
- func (h Host) FailedLog(ctx context.Context, c Check) (string, error)
- func (h Host) HeadChecks(ctx context.Context, p PR) (HeadChecks, error)
- func (h Host) HeadRef(number string) string
- func (h Host) IsLogin(declared, login string) bool
- func (h Host) Issue(ctx context.Context, number string) (Issue, error)
- func (h Host) IssueWithComments(ctx context.Context, number string) (Issue, error)
- func (h Host) Issues(ctx context.Context, query string, limit int) ([]Issue, error)
- func (h Host) IssuesURL(ctx context.Context) (string, error)
- func (h Host) Item(ctx context.Context, number string) (Issue, error)
- func (h Host) LatestStatus(ctx context.Context, sha, name string) (*CommitStatus, error)
- func (h Host) LinkParent(ctx context.Context, parent, child string) error
- func (h Host) Login(ctx context.Context) (string, error)
- func (h Host) MRForcePushes(ctx context.Context, iid int, since time.Time) ([]ForcePush, error)
- func (h Host) MRReviews(ctx context.Context, iid int) ([]Review, error)
- func (h Host) MergeMethods(ctx context.Context) ([]string, error)
- func (h Host) MergePR(ctx context.Context, p PR, branch, head, method, body string) (PR, error)
- func (h Host) MethodFor(declared string) string
- func (h Host) OpenChecks(ctx context.Context, branch string) (HeadChecks, string, error)
- func (h Host) OpenPRs(ctx context.Context, limit int) ([]PR, error)
- func (h Host) OpenReviews(ctx context.Context, number string) (*ReviewPR, error)
- func (h Host) Owner(ctx context.Context, p PR) (Owner, error)
- func (h Host) PR(ctx context.Context, selector string) (PR, error)
- func (h Host) PRBody(ctx context.Context, branch string) (string, error)
- func (h Host) PRForcePushes(ctx context.Context, number int, login string) ([]ForcePush, error)
- func (h Host) PostComment(ctx context.Context, number int, webURL, thread, body string) (string, error)
- func (h Host) PullComments(ctx context.Context, number int) ([]Comment, error)
- func (h Host) PullCommits(ctx context.Context, number int) ([]PRCommit, error)
- func (h Host) PullDetail(ctx context.Context, prs []*PR, login string, since time.Time) []error
- func (h Host) PullDiff(ctx context.Context, number int) (string, error)
- func (h Host) Pulls(ctx context.Context, login string, since time.Time) ([]PR, error)
- func (h Host) PullsByHead(ctx context.Context, branch string) ([]PR, error)
- func (h Host) PullsSince(ctx context.Context, since time.Time) ([]PR, error)
- func (h Host) PullsURL(ctx context.Context) (string, error)
- func (h Host) Ref(n int) string
- func (h Host) RepoURL(ctx context.Context) (string, error)
- func (h Host) Rerun(ctx context.Context, failed []Check) ([]string, error)
- func (h Host) Retarget(ctx context.Context, number int, base string) error
- func (h Host) SearchPRs(ctx context.Context, query, fields string) ([]PR, error)
- func (h Host) SetIssueOpen(ctx context.Context, number string, open bool) error
- func (h Host) SetStatus(ctx context.Context, sha string, s CommitStatus) error
- func (h Host) SharedNumbers() bool
- func (h Host) ShowPR(ctx context.Context, number string, web bool) error
- func (h Host) Sigil() string
- func (h Host) StackedPRs(ctx context.Context, branch string) ([]PR, error)
- func (h Host) Thread(ctx context.Context, number int, threadURL string) (string, error)
- func (h Host) ThreadComments(ctx context.Context, number int, webURL, thread string) ([]Posted, error)
- func (h Host) Token(ctx context.Context) (string, error)
- func (h Host) Unlink(ctx context.Context, child string) error
- type Issue
- type IssueComment
- type IssueEdit
- type NewPull
- type Note
- type Owner
- type PR
- type PRCommit
- type Posted
- type Review
- type ReviewCommit
- type ReviewPR
- func (p *ReviewPR) Checks(ctx context.Context, name string) ([]Note, error)
- func (p *ReviewPR) Comment(ctx context.Context, text string) (string, time.Time, error)
- func (p *ReviewPR) Comments(ctx context.Context, want func(login string) bool) ([]Note, error)
- func (p *ReviewPR) EditBody(ctx context.Context, n Note, body string) error
- func (p *ReviewPR) FreshReactions(ctx context.Context, n Note) (map[string]bool, error)
- func (p *ReviewPR) InlineReviews(ctx context.Context, want func(login string) bool) ([]Note, error)
- func (p *ReviewPR) React(ctx context.Context, n Note, emoji string) error
- func (p *ReviewPR) RequestReview(ctx context.Context, login string) error
- func (p *ReviewPR) ResolveThreads(ctx context.Context, threads []string) error
- func (p *ReviewPR) ShaBefore(t time.Time) string
- func (p *ReviewPR) ThreadsResolved(ctx context.Context, n Note) (bool, error)
- func (p *ReviewPR) Viewer(ctx context.Context) (string, error)
- type Touched
Constants ¶
const ( EventOpened = "opened" EventReady = "ready" // out of draft EventCommit = "commit" EventMergeFromBase = "merge-from-base" // a commit with more than one parent EventForcePush = "force-push" EventReview = "review" EventReviewRequested = "review-requested" EventMerged = "merged" EventClosed = "closed" )
What happened to a request in a window, one kind per event. Opened is read off the request's creation time; the rest are timeline events.
const ( Open = "open" Merged = "merged" Closed = "closed" )
The three states a request can be in, whichever CLI spelled them.
const ( OwnFields = "number,title,state,isDraft,headRefName,baseRefName,url,author,createdAt,updatedAt,mergedAt,changedFiles,mergeCommit" ForeignFields = "number,title,state,url,author,mergedAt,mergedBy" BoardFields = "number,title,state,isDraft,headRefName,baseRefName,headRefOid,url,author,assignees," + "reviewRequests,reviews,reviewDecision,mergeable,mergeStateStatus,statusCheckRollup," + "createdAt,updatedAt,mergedAt,mergedBy,closedAt,body,mergeCommit" )
The gh field sets: a person's own requests, other people's, and what a board wants to know about every request.
const ( Approved = "approved" ChangesRequested = "changes_requested" ReviewRequired = "review_required" Commented = "commented" Clean = "clean" Conflicts = "conflicts" Blocked = "blocked" // Behind: the host will not merge it until its branch holds the target // (GitHub's require-up-to-date protection, GitLab's fast-forward merge) Behind = "behind" Green = "green" Red = "red" Pending = "pending" )
The vocabularies the host's words are read into.
const ActivityQuery = `` /* 1365-byte string literal not displayed */
ActivityQuery is the GraphQL a GitHub feed reads: requests updated since the window's start with their timeline, and the quiet open ones counted. A timeline keeps its newest 100 events, which a request rarely passes.
const DefaultJobQuery = "query($owner: String!, $name: String!, $check: String!) { repository(owner: $owner, name: $name) " +
"{ defaultBranchRef { target { ... on Commit { history(first: 5) { nodes { checkSuites(first: 50) { nodes " +
"{ checkRuns(first: 1, filterBy: {checkName: $check}) { nodes { status conclusion } } } } } } } } } } }"
DefaultJobQuery reads one check's runs on the default branch's last five commits, newest first, so a tip still running falls back to its parent.
const DetailParallel = 8
DetailParallel is how many requests PullDetail reads at once.
const ForcePushesQuery = "query($owner: String!, $name: String!, $number: Int!) { repository(owner: $owner, name: $name) " +
"{ pullRequest(number: $number) { timelineItems(last: 100, itemTypes: [HEAD_REF_FORCE_PUSHED_EVENT]) " +
"{ nodes { ... on HeadRefForcePushedEvent { createdAt actor { login } beforeCommit { oid } afterCommit { oid } } } } } } }"
ForcePushesQuery is the GraphQL that lists a PR's force-pushes.
const HeadChecksQuery = "query($owner: String!, $name: String!, $number: Int!, $endCursor: String) " +
"{ repository(owner: $owner, name: $name) { pullRequest(number: $number) { " +
"prev: commits(last: 2) { nodes { commit { statusCheckRollup { state } } } } " +
"head: commits(last: 1) { nodes { commit { oid statusCheckRollup { " +
"contexts(first: 100, after: $endCursor) { pageInfo { hasNextPage endCursor } nodes { __typename " +
"... on CheckRun { name status conclusion detailsUrl isRequired(pullRequestNumber: $number) } " +
"... on StatusContext { context state targetUrl isRequired(pullRequestNumber: $number) } " +
"} } } } } } } } }"
HeadChecksQuery reads every check context on a request's head commit, each with whether the request's target branch requires it, a page of 100 at a time; prev is the last two commits' rollups, to tell a head whose checks have not registered yet from a repository with none.
const HeadFields = "number,state,headRefName,headRefOid,baseRefName,url,author,createdAt,mergedAt,closedAt," +
"mergeable,mergeStateStatus"
HeadFields are what the janitor and the watcher read of a branch's requests.
const IssuePath = `(?:-/)?(?:issues|work_items)/`
IssuePath is an issue's url path before its number, on GitHub and on GitLab, which prints work items where it used to print issues.
const PRLimit = 1000
PRLimit caps each gh search. Reaching it is an error rather than a report silently missing the rest.
const (
PullPath = `(?:-/)?(?:` + pullSegment + `|` + mrSegment + `)/`
)
The path segment before a request's number: GitHub's pull, GitLab's merge_requests. PullPath is the regexp of either, as IssuePath is.
Variables ¶
var ( // ErrNotFound is the host saying the issue or request does not exist. ErrNotFound = errors.New("not found") // ErrUnsupported is a host without the feature asked for, such as // GitHub sub-issues or GitLab work items. ErrUnsupported = errors.New("not supported by this host") // ErrTransient is a 5xx from the host's API: a gateway or server error // that may clear on a second try. ErrTransient = errors.New("transient host error") )
The kinds a host failure is classified into; callers test them with errors.Is and never read the CLI's words.
var ErrNoIssueParent = errors.New("GitLab nests no issue under an issue; list the subtasks in the parent's body")
ErrNoIssueParent is GitLab, which nests tasks, not issues, under an issue.
var ErrNoThread = errors.New("the url names no thread to reply in")
ErrNoThread is a url that names no thread to reply in: an issue comment, a review with no inline comments, a check run.
var ErrNotIssue = errors.New("a pull request, not an issue")
ErrNotIssue is a number that names a pull request where an issue was meant: gh numbers both from one counter and answers `issue view` for either.
var RetryPause = 2 * time.Second
RetryPause is the wait before the one retry of a transient failure.
Functions ¶
func PullNumber ¶ added in v0.58.0
PullNumber is a request's url as its host writes the number, for a caller holding only the url: a GitLab merge request's path names it, so `!12`, else `#128`.
Types ¶
type Activity ¶ added in v0.39.0
type Activity struct {
Requests []Touched
QuietCount int
QuietOldest time.Time // the oldest quiet request's creation time
}
Activity is what a repository did since a time: every request touched, and how many open ones nobody touched, with the oldest of them.
type CI ¶
CI is how the checks on a commit ended: Red when any failed, At the time of the last failure.
type Check ¶ added in v0.60.0
type Check struct {
Name string `json:"name"`
URL string `json:"url,omitempty"`
Run string `json:"run,omitempty"`
Cancelled bool `json:"cancelled,omitempty"` // it stopped because another job failed
}
A Check is one check run, status or pipeline job, with its log url. Run is what a rerun names: the Actions run, or the GitLab pipeline.
type Child ¶ added in v0.58.0
type Child struct {
Number string
Title string
URL string
State string
Body string
Labels []string
}
A Child is one issue linked under another.
type CommitStatus ¶ added in v0.49.0
A CommitStatus is one named status on a commit; State is "success", "failure" or the host's own word for anything else.
type Error ¶ added in v0.58.0
type Error struct {
Host string // "gh" or "glab"
Code int
Stderr string
// contains filtered or unexported fields
}
An Error is a host CLI exiting non-zero. Its text is the CLI's own stderr, since that names the cause better than any paraphrase.
type Event ¶ added in v0.39.0
type Event struct {
Kind string
At time.Time
Actor string
Message string // a commit's whole message, trailers included
State string // a review's: Approved, ChangesRequested or Commented
}
An Event is one thing that happened to a request.
type ForcePush ¶
type ForcePush struct {
At time.Time
Before string
After string
// SamePatches is whether every commit kept its patch, nil when git
// cannot tell; the reader that owns the checkout fills it.
SamePatches *bool
}
A ForcePush is one force-push to a PR: the head it replaced and the one it set.
type HeadChecks ¶ added in v0.60.0
type HeadChecks struct {
State string `json:"state"` // Green, Red, Pending or "" with no checks
SHA string `json:"sha"`
Required bool `json:"required"` // the counted set is the target branch's required checks
Failed []Check `json:"failed,omitempty"`
Running []Check `json:"running,omitempty"`
}
HeadChecks is the CI state of a request's head commit, as the checks that count for a merge read it. It belongs to SHA alone, so nothing keeps a copy.
func (*HeadChecks) First ¶ added in v0.60.0
func (hc *HeadChecks) First() (Check, bool)
First is the failure to read first: the first that is not cancelled, since a cancelled job only followed another's failure.
type Host ¶
type Host struct {
Name string // "gh" or "glab"
Dir string // the checkout the CLI reads the remote from
// Repo names the repository when no checkout can: `owner/repo`, or
// `host/owner/repo` off the CLI's default host; set, every command carries it.
Repo string
// RetryTransient retries a command once after a 5xx. Only read-only
// callers set it, because a retried write may already have landed.
RetryTransient bool
}
A Host is one of the two forge CLIs, bound to the checkout it answers for, or to a repository named outright where no checkout exists.
func (Host) Activity ¶ added in v0.39.0
Activity reads what the repository did since since: one paged query on GitHub, on GitLab a list of the updated merge requests read one by one.
func (Host) AllIssues ¶ added in v0.58.0
AllIssues is every issue in any state, numbers and titles only. Neither CLI's issue list includes requests, so nothing here filters them.
func (Host) Branches ¶ added in v0.39.0
Branches is every branch the host has, one paged listing: what the board asks of every merged request at once.
func (Host) Children ¶ added in v0.58.0
Children reads an issue's linked children: GitHub sub-issues, or GitLab work-item children. A host without either answers ErrUnsupported.
func (Host) CommentIssue ¶ added in v0.58.0
CommentIssue posts body on an issue, never a request, and returns the comment's url when the CLI prints one.
func (Host) CommitCI ¶
CommitCI is how the checks on a commit ended, nil when it has none. On GitHub that is its check runs and its commit statuses; on GitLab its last pipeline.
func (Host) CreateIssue ¶ added in v0.58.0
func (h Host) CreateIssue(ctx context.Context, title, body string, labels []string) (string, string, error)
CreateIssue returns the new issue's url and number, read from the url the CLI prints: a list query afterwards could find another create's issue.
func (Host) CreatePull ¶ added in v0.49.0
CreatePull opens a request from a branch already on the remote, so neither CLI stops to ask about pushing it.
func (Host) DecidingPull ¶ added in v0.67.0
DecidingPull is the request that decides branch, by Deciding.
func (Host) DefaultBranchName ¶
DefaultBranchName is the repo's default branch as the host has it.
func (Host) DefaultJob ¶ added in v0.60.0
DefaultJob is how the job named name last ended on the default branch: Green, Red, or "" when none of its recent runs there completed. A cancelled run is skipped, since a newer push cancelling it says nothing of whether the job passes.
func (Host) DeleteBranch ¶ added in v0.58.0
DeleteBranch deletes branch on the host through the API rather than `--delete-branch`, which also deletes the local branch, refused while a worktree holds it, so gh exits non-zero after the merge landed. Unlike the host's delete on merge this closes every request based on branch, so callers retarget them first.
func (Host) EarlierRequests ¶ added in v0.39.0
EarlierRequests is every request that may name each id, to tell a task's first request from a follow-up: one GraphQL call for every id on GitHub, one list per id on GitLab. The searches only narrow; the caller matches.
func (Host) EditPull ¶ added in v0.49.0
EditPull rewrites a request's title, its body, or both; "" leaves one as it is. selector is what the CLI takes: a number or a branch.
func (Host) FailedLog ¶ added in v0.60.0
FailedLog is the log of a failed check's job: on GitHub its failed steps (`gh run view --log-failed`), on GitLab the job's trace.
func (Host) HeadChecks ¶ added in v0.60.0
HeadChecks reads the checks on p's head. On GitHub the target branch's required checks count when it declares any, else all of them, since a branch with no protection would otherwise gate on nothing; on GitLab the head pipeline decides, as GitLab has no required flag. A head with no checks whose previous commit had some is Pending: its CI has not started.
func (Host) HeadRef ¶ added in v0.58.0
HeadRef is the ref a request's head lives under on origin, fetchable after its branch is deleted.
func (Host) IsLogin ¶ added in v0.58.0
IsLogin matches a declared reviewer against a login. GitLab names a bot by username alone, with no suffix anyone could forge, so a declared `[bot]` is dropped there; on GitHub SameLogin's rule stands.
func (Host) IssueWithComments ¶ added in v0.58.0
IssueWithComments is Issue with the issue's comments read too.
func (Host) Issues ¶ added in v0.58.0
Issues lists the open issues, those matching query when one is given.
func (Host) Item ¶ added in v0.58.0
Item reads number whether it names an issue or a request; Pull tells which.
func (Host) LatestStatus ¶ added in v0.49.0
LatestStatus is the newest status named name on sha, nil when it has none.
func (Host) LinkParent ¶ added in v0.58.0
LinkParent puts child under parent, moving it from a parent it already has: GitHub gives an issue one parent, and links by the child's database id, not its number.
func (Host) MRForcePushes ¶
MRForcePushes reads GitLab's MR versions, one per push, since the time: a version whose previous head is not its ancestor replaced commits. GitLab records no pusher, so on the user's own MR each counts as theirs.
func (Host) MRReviews ¶
MRReviews is the notes that count as reviewing: any plain comment, and the system note an approval leaves.
func (Host) MergeMethods ¶ added in v0.58.0
MergeMethods is what the repository allows, as MergePR methods. GitLab fixes one strategy per project: "--squash" when its squash option is on, else "" for its plain merge.
func (Host) MergePR ¶ added in v0.58.0
MergePR merges the request on branch and reads it back, since the merge commit exists only after. method is "--squash", "--merge", "--rebase", or "" for GitLab's plain merge, where the project fixes the strategy. A head pins the merge to that sha, so a push since the checks were read refuses.
Never --admin: a refusing host has a reason. glab's auto-merge is off so a running pipeline refuses rather than queues; its squash message replaces the whole commit message, so the title goes on top. gh's squash gets the title as its subject, else GitHub uses a lone commit's subject.
func (Host) MethodFor ¶ added in v0.58.0
MethodFor is a declared merge method (squash, merge, rebase) as MergePR takes it: GitLab's "merge" is its plain merge, which takes no flag.
func (Host) OpenChecks ¶ added in v0.60.0
OpenChecks reads the checks on branch's open request, with its url; a branch with none open gives "" and no checks.
func (Host) OpenReviews ¶ added in v0.58.0
OpenReviews reads the request number names, or the current branch's.
func (Host) Owner ¶ added in v0.58.0
Owner reads the signed-in login and compares it with p's author; a request with no author is unknown without asking the host.
func (Host) PR ¶ added in v0.58.0
PR reads one request by branch or number. A missing one is ErrNotFound, its text the CLI's own words.
func (Host) PRBody ¶ added in v0.58.0
PRBody is the request's description alone, read fresh right before a write that must not act on a stale one.
func (Host) PRForcePushes ¶
PRForcePushes is the force-pushes the user made to a PR, the last 100: GitHub records each with the head before and after.
func (Host) PostComment ¶ added in v0.49.0
func (h Host) PostComment(ctx context.Context, number int, webURL, thread, body string) (string, error)
PostComment posts body in thread, or as a top-level comment when thread is "", and returns the new comment's url.
func (Host) PullComments ¶ added in v0.49.0
PullComments is the request's conversation; GitLab's system notes (pushes, approvals, label changes) are events, not comments, and are left out.
func (Host) PullCommits ¶
PullCommits is the commits a request lists, one call per request: asked for inside the list query, gh's GraphQL refuses a node count past its limit.
func (Host) PullDetail ¶ added in v0.66.0
PullDetail fills the commits and force-pushes of the user's own requests, a few at a time. Each entry of the result is that request's failure, or nil where it read. One failure leaves the others read.
func (Host) PullDiff ¶ added in v0.49.0
PullDiff is the request's diff as the host has it: what was pushed, not what a checkout holds.
func (Host) Pulls ¶
Pulls is every request a person's standup needs: their own, and others' they reviewed or merged since since. The own requests' commits and force-pushes are PullDetail's, read only for the ones the report shows.
func (Host) PullsByHead ¶ added in v0.45.0
PullsByHead is every request whose head is branch, in any state, newest first. A branch can carry several: one closed, then another opened.
func (Host) PullsSince ¶
PullsSince is what a board reads: every open request, and every one merged since since, each with the board's fields and no commits.
func (Host) RepoURL ¶ added in v0.58.0
RepoURL is the repository's web page, read from the host rather than the remote, so a fork or a self-hosted GitLab gets its own.
func (Host) Rerun ¶ added in v0.60.0
Rerun reruns the failed jobs of each run the failed checks belong to, the way `gh run rerun --failed` does; a check with no run is skipped. It returns the runs it reran.
func (Host) Retarget ¶ added in v0.58.0
Retarget moves a request to base, by number: a stacked request's head is another task's branch.
func (Host) SetIssueOpen ¶ added in v0.58.0
SetIssueOpen reopens the issue, or closes it; both CLIs spell it alike.
func (Host) SetStatus ¶ added in v0.49.0
SetStatus sets a named status on sha; state is "success" or "failure", which GitLab spells "failed".
func (Host) SharedNumbers ¶ added in v0.58.0
SharedNumbers reports whether issues and requests share one counter, so a bare #n may name either; GitLab numbers them apart.
func (Host) ShowPR ¶ added in v0.58.0
ShowPR prints the request to the terminal through the CLI, or opens it in the browser.
func (Host) Sigil ¶ added in v0.58.0
Sigil is how the host writes a request's number: #n, or GitLab's !n.
func (Host) StackedPRs ¶ added in v0.58.0
StackedPRs is every open request based on branch, paged past both CLIs' default 30: one left out would be closed by the branch's delete.
func (Host) Thread ¶ added in v0.49.0
Thread is the thread a url names on request number: GitHub's top-level review comment, which replies attach to (a reply to a reply is refused), or GitLab's discussion. A review url is the url review pick records for an inline review, and names the thread of its first comment.
func (Host) ThreadComments ¶ added in v0.49.0
func (h Host) ThreadComments(ctx context.Context, number int, webURL, thread string) ([]Posted, error)
ThreadComments is every comment in thread, or the request's top-level conversation when thread is "". webURL is the request's own url, which a GitLab note's url hangs off.
type Issue ¶ added in v0.58.0
type Issue struct {
Number string
Title string
State string // as the CLI spells it: OPEN, opened, closed...
URL string
Body string
Labels []string
Assignees []string
CreatedAt time.Time
Comments []IssueComment // read only by IssueWithComments
Pull bool // the number names a pull or merge request
}
An Issue is a task on the host's own tracker, as the host reported it.
type IssueComment ¶ added in v0.58.0
type IssueComment struct {
Author string
Body string
Internal bool // a GitLab internal note, hidden from the issue's public readers
}
An IssueComment is one comment on an issue, by its author's login.
type IssueEdit ¶ added in v0.58.0
type IssueEdit struct {
Title string
AddLabels []string
RemoveLabels []string
// Assignee replaces the issue's assignees, as glab's flag does; on gh,
// which only adds one, the others in Current come off by name.
Assignee string
Current []string
Body *string // the whole body, nil to leave it
}
An IssueEdit is one edit of an issue's title, labels and assignee; the zero value of a field leaves it alone.
type NewPull ¶ added in v0.49.0
A NewPull is a request to open: the branch, the branch it targets, and what the CLIs set on it at creation.
type Note ¶ added in v0.58.0
type Note struct {
ID string
URL string
Author string // "" for GitLab discussions, which the caller names
Body string // an inline review's comments folded in
Stored string // the host's own text, which an edit rewrites
SHA string
CreatedAt time.Time
UpdatedAt time.Time
Inline bool // an inline review or discussion, not an issue comment
CommentID string // inline: the comment a reaction or marker lands on
Threads []string // inline: the threads it opened
ThreadsErr error // inline: why Threads could not be read
Pending bool // inline: not yet submitted
Concluded bool // check: finished; GitLab inline: every thread resolved
}
A Note is one reviewer's artifact as the host keeps it: an issue comment, an inline review (GitLab: the reviewer's open discussions, folded), or a check run (GitLab: a pipeline job).
type Owner ¶ added in v0.58.0
type Owner int
An Owner says whether a request is the signed-in user's.
type PR ¶
type PR struct {
Number int
Title string
URL string
Status string // Open, Merged or Closed
Draft bool
Empty bool // no changes yet: no changed files on GitHub, no commits on GitLab
Head string
HeadSHA string
Base string
Author string
Assignees []string
Reviewers []string // reviewers requested and not yet heard from
CreatedAt time.Time
UpdatedAt time.Time
MergedAt time.Time // zero unless merged
ClosedAt time.Time // zero unless closed
MergedBy string
Body string
Decision string // Approved, ChangesRequested, ReviewRequired or ""
Mergeable string // Clean, Conflicts, Blocked, Behind or ""
Checks string // Green, Red, Pending or "" with none
Commits []PRCommit // the commits the host lists for it, where asked for
MergeSHA []string // the merge and squash commits it landed as
Landed string // the commit it landed as: gh's merge commit, else glab's squash, else its merge
Fork bool // its branch lives in another repository, which origin does not have
Reviews []Review // where asked for
ForcePushes []ForcePush // the requester's own, where asked for
}
A PR is a pull or merge request as the host reported it.
type PRCommit ¶
type PRCommit struct {
SHA string
Subject string
Message string // the whole message, trailers included
Email string // the author's email, as the commit records it
At time.Time
Parents int // more than one is a merge
}
A PRCommit is one commit a PR lists. A rebase merge lands it on the default branch under a new sha, keeping its author date and subject.
type Posted ¶ added in v0.49.0
A Posted comment is one already on a request, as far as a duplicate check needs it.
type Review ¶
type Review struct {
Author string
State string // Approved, ChangesRequested, Commented or ""
At time.Time
}
A Review is one review event on a PR: a submitted review, an approval or a comment, by anyone.
type ReviewCommit ¶ added in v0.58.0
A ReviewCommit is one of the request's commits, by its commit date.
type ReviewPR ¶ added in v0.58.0
type ReviewPR struct {
Number string
HeadSHA string
URL string
Commits []ReviewCommit // oldest first
// contains filtered or unexported fields
}
A ReviewPR is a request opened to read and answer the reviews left on it, with the commits a comment's sha is derived from (an issue comment stores none).
func (*ReviewPR) Checks ¶ added in v0.58.0
Checks is every check run on the head named name, or on GitLab every job of the head pipeline; a finished job's log is its body.
func (*ReviewPR) Comment ¶ added in v0.58.0
Comment posts text on the request and returns the comment's url and the host's time for it, zero when the host gives none.
func (*ReviewPR) Comments ¶ added in v0.58.0
Comments is every issue comment, or merge request note, by an author want accepts. Every page is read: the oldest come first, so a review past the first page is the newest one.
func (*ReviewPR) EditBody ¶ added in v0.58.0
EditBody replaces the text of n, the note's own on GitLab.
func (*ReviewPR) FreshReactions ¶ added in v0.58.0
FreshReactions is the set of reactions the viewer left on n since its last edit; nil for an inline review with no comment to react to.
func (*ReviewPR) InlineReviews ¶ added in v0.58.0
InlineReviews is every submitted or pending review by an author want accepts, its line comments folded into the body. GitLab has no review object, so its reviewer's resolvable discussions fold into one.
func (*ReviewPR) RequestReview ¶ added in v0.58.0
RequestReview asks login for a review of the request.
func (*ReviewPR) ResolveThreads ¶ added in v0.58.0
ResolveThreads resolves each of the threads, stopping at the first failure.
func (*ReviewPR) ShaBefore ¶ added in v0.58.0
ShaBefore is the head a reviewer saw when it posted at t; the head sha when no commit precedes it.
func (*ReviewPR) ThreadsResolved ¶ added in v0.58.0
ThreadsResolved reports whether every thread n opened is resolved. gh threads are read again, since their ids were gathered without their state; glab discussions carry the flag, folded into Concluded.