pullrequests

package
v0.21.1 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: MIT Imports: 22 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 pullrequests reads the open pull requests on the repos a registry names, from each provider that hosts one.

GitHub is read in-process through go-gh, with the token gh holds or GH_TOKEN, so prs keeps no credentials of its own. Bitbucket is read through bbkt, which holds its own.

Index

Constants

View Source
const ReposPerSearch = 20

ReposPerSearch is how many repos one search names. Each search has its own page of 100, so a few busy repos fill their own page rather than every repo's.

View Source
const ViewerOwner = "@me"

ViewerOwner is the owner GitHub's search reads as the token's own account.

Variables

View Source
var ErrNoAnswer = errors.New("no answer")

ErrNoAnswer is a client killed at its timeout, which errors.Is finds whatever the timeout was. A client that changes a pull request may have changed it by then.

View Source
var Providers = []Provider{
	{
		Name:      registry.GitHub,
		Standings: map[string]Standing{"OPEN": Open, "MERGED": Merged, "CLOSED": Closed},

		PagePath: func(parts []string) (string, string, bool) {
			if len(parts) < 4 || parts[2] != "pull" {
				return "", "", false
			}
			return parts[0] + "/" + parts[1], parts[3], true
		},
		Read:        ReadGitHub,
		ReadClosed:  ReadGitHubClosed,
		Detail:      readGitHubDetail,
		ReadOne:     readGitHubReference,
		Diff:        readGitHubDiff,
		ReadsOwners: true,
		Head:        func(pr PullRequest) string { return fmt.Sprintf("pull/%d/head", pr.Number) },
		Browse: func(pr PullRequest) ([]string, bool) {
			return []string{"gh", "pr", "view", strconv.Itoa(pr.Number), "--repo", pr.Slug, "--web"}, false
		},

		Merge: func(pr PullRequest, head string) ([]string, bool) {
			argv := []string{"gh", "pr", "merge", strconv.Itoa(pr.Number), "--repo", pr.Slug, "--merge"}
			if head != "" {
				argv = append(argv, "--match-head-commit", head)
			}
			return argv, false
		},
		Close: func(pr PullRequest) ([]string, bool) {
			return []string{"gh", "pr", "close", strconv.Itoa(pr.Number), "--repo", pr.Slug}, false
		},
		Comment: func(pr PullRequest, path string) ([]string, bool) {
			return []string{"gh", "pr", "comment", strconv.Itoa(pr.Number), "--repo", pr.Slug, "--body-file", path}, false
		},
		UpdateBranch: func(pr PullRequest) ([]string, bool) {
			return []string{"gh", "pr", "update-branch", strconv.Itoa(pr.Number), "--repo", pr.Slug}, false
		},
		Ready: func(pr PullRequest) ([]string, bool) {
			return []string{"gh", "pr", "ready", strconv.Itoa(pr.Number), "--repo", pr.Slug}, false
		},
		Rerun: func(pr PullRequest, run string) ([]string, bool) {
			return []string{"gh", "run", "rerun", run, "--failed", "--repo", pr.Slug}, false
		},
		FailedLog: func(pr PullRequest, run string) ([]string, bool) {
			return []string{"gh", "run", "view", run, "--log-failed", "--repo", pr.Slug}, false
		},
		CheckRun: func(url string) string {
			if found := actionsRun.FindStringSubmatch(url); found != nil {
				return found[1]
			}
			return ""
		},
	},
	{
		Name: registry.Bitbucket,

		Standings: map[string]Standing{"OPEN": Open, "MERGED": Merged, "DECLINED": Closed, "SUPERSEDED": Closed},

		PagePath: func(parts []string) (string, string, bool) {
			switch {
			case len(parts) >= 6 && parts[0] == "projects" && parts[2] == "repos" && parts[4] == "pull-requests":
				return parts[1] + "/" + parts[3], parts[5], true
			case len(parts) >= 4 && parts[2] == "pull-requests":
				return parts[0] + "/" + parts[1], parts[3], true
			}
			return "", "", false
		},
		Read: ReadBitbucket,

		ReadOne: readBitbucketReference,

		Head: func(pr PullRequest) string { return pr.Branch },

		Browse: func(pr PullRequest) ([]string, bool) {
			return []string{"bbkt", "pr", "open", strconv.Itoa(pr.Number)}, true
		},

		Merge: func(pr PullRequest, _ string) ([]string, bool) {
			return []string{"bbkt", "pr", "merge", strconv.Itoa(pr.Number), "--yes"}, true
		},
		Comment: func(pr PullRequest, path string) ([]string, bool) {
			return []string{"bbkt", "pr", "comment", "create", strconv.Itoa(pr.Number), "--body-file", path}, true
		},
	},
}

Providers is a Provider for each name registry.Providers holds.

Functions

func BaseMergedSince added in v0.14.0

func BaseMergedSince(ctx context.Context, t LocalDiff, commit string) (bool, error)

BaseMergedSince says the branch took in commits from origin/<base> after commit, as a merge of its base into it or GitHub's update of the branch does. A diff from commit to the head would then show the base's changes as the branch's own. Where the head holds commit, the two meet origin/<base> at the same commit unless such a merge came between them.

func CheckoutOf added in v0.10.0

func CheckoutOf(pr PullRequest) (string, error)

CheckoutOf is the pull request's checkout on this disk, which d, a window action and bbkt each run in.

func ConflictingFiles added in v0.17.0

func ConflictingFiles(ctx context.Context, t LocalDiff) ([]string, error)

ConflictingFiles is each file a merge of origin/<base> into the head fetched into the target's Ref conflicts in, from git merge-tree, which checks nothing out. The catch-up merge stops on the same files. It is empty where git merges the two cleanly here. merge-tree exits 1 both for a conflict and for a ref it cannot read, so a conflict is the one that wrote a tree.

func HeadHolds added in v0.14.0

func HeadHolds(ctx context.Context, t LocalDiff, commit string) (bool, error)

HeadHolds says the head fetched into the target's Ref has commit in its history, and fails where git could not answer. A commit git does not have here is in no history the fetch brought. git says each answer by its exit status, 1 for no, so a failure never reads as no.

func ParseUntil added in v0.15.0

func ParseUntil(text string, now time.Time, loc *time.Location) (time.Time, error)

ParseUntil reads --until in --since's grammar, as the instant a window ends before. A span counts back from now, and an instant is itself. A day takes in the whole of it, so the window ends at the next day's first instant in loc.

func ReadGitHubPullRequest added in v0.4.0

func ReadGitHubPullRequest(ctx context.Context, slug string, number int) (PullRequest, Detail, error)

ReadGitHubPullRequest is one pull request's row and detail, read by its owner/name slug and number, open or not. The row has no Path or AgeDays until Finish sets them.

func Run added in v0.3.0

func Run(ctx context.Context, dir string, argv ...string) ([]byte, error)

Run runs a client a key uses as a read runs one, and returns its stdout. It fails with the first line the client said, or with ErrNoAnswer.

func RunDetached added in v0.16.0

func RunDetached(dir, log string, argv ...string) error

RunDetached runs a command that is to finish whether or not prs is still open, such as one waiting on a model call, and returns when it ends. It runs as run runs a client, in a session of its own with stdin closed, with its output written to the file at log in place of a pipe, so neither prs exiting nor its terminal closing stops it, and nothing bounds it. It fails with the last line the command wrote.

func RunWithin added in v0.17.0

func RunWithin(ctx context.Context, within time.Duration, dir string, argv ...string) ([]byte, error)

RunWithin is Run, bounded by within rather than a read's timeout.

Types

type CatchUp added in v0.20.0

type CatchUp int

CatchUp is where the merge in a CatchUpWorktree stands.

const (
	// NoCatchUp is no worktree, or one with no merge under way and nothing to push.
	NoCatchUp CatchUp = iota
	// MergeStopped is a merge under way, stopped for a person to resolve its conflicts.
	MergeStopped
	// MergeUnpushed is a merge committed and not pushed yet.
	MergeUnpushed
)

type CatchUpWorktree added in v0.20.0

type CatchUpWorktree struct {
	Target LocalDiff
	Path   string
	// Branch is the head branch on origin the merge starts from and is pushed to.
	Branch string
}

CatchUpWorktree is a worktree of a pull request's checkout, detached at its head branch on origin, where the fix menu merges origin/<base> into the head for a person to resolve its conflicts. Detached, it moves no local branch, so a worktree a session holds on the head branch, or a local branch with commits not pushed, is left as it is. A merge only adds commits, so the head branch on origin fast-forwards to it, and no push is forced.

func CatchUpWorktreeAt added in v0.20.0

func CatchUpWorktreeAt(root string, t LocalDiff, branch string) CatchUpWorktree

CatchUpWorktreeAt is where the fix menu catches the target's head up: pr-<number>-catch-up in the directory under root named for the checkout's own directory. A tool keeping its own worktree of the pull request beside it more likely names it pr-<number>.

func (CatchUpWorktree) Abort added in v0.20.0

func (w CatchUpWorktree) Abort(ctx context.Context) (bool, error)

Abort abandons any merge under way and removes the worktree, and says whether a merge was.

func (CatchUpWorktree) Commits added in v0.20.0

func (w CatchUpWorktree) Commits(ctx context.Context) ([]string, error)

Commits is each commit the push adds to the head branch as last fetched, the merge first, as git log --oneline prints it.

func (CatchUpWorktree) Continue added in v0.20.0

func (w CatchUpWorktree) Continue(ctx context.Context) (CatchUp, error)

Continue commits the merge once its conflicts are resolved and staged, with the message Start gave it, and says where it then stands. The commit runs the checkout's hooks. A merge git cannot commit with nothing unmerged, such as one a hook refuses, stays stopped, and git's words say why.

func (CatchUpWorktree) Exists added in v0.20.0

func (w CatchUpWorktree) Exists() bool

Exists says something is at the worktree's path.

func (CatchUpWorktree) Push added in v0.20.0

func (w CatchUpWorktree) Push(ctx context.Context) (Pushed, error)

Push pushes the merge to the head branch on origin, then removes the worktree. The merge's first parent is the head it started from, so the push fast-forwards the branch and carries no force. Origin refuses it where anyone pushed to the branch since, and a refused push leaves the merge where it is.

func (CatchUpWorktree) Remove added in v0.20.0

func (w CatchUpWorktree) Remove(ctx context.Context) error

Remove removes the worktree from the checkout, which git refuses while it holds changes.

func (CatchUpWorktree) Start added in v0.20.0

func (w CatchUpWorktree) Start(ctx context.Context) (CatchUp, error)

Start merges origin/<base> into the head branch in the worktree, and says where the merge then stands. The head branch is fetched into origin/<branch> first, and the worktree added there, or moved there where it holds no merge. A merge already under way in it, or committed and not pushed, is kept as it is. A worktree holding changes is refused rather than lost, and one on a branch is no worktree prs added. A head that already holds the base needs no merge, and the worktree goes again.

func (CatchUpWorktree) State added in v0.20.0

func (w CatchUpWorktree) State(ctx context.Context) CatchUp

State is where a merge in the worktree stands.

func (CatchUpWorktree) Unmerged added in v0.20.0

func (w CatchUpWorktree) Unmerged(ctx context.Context) ([]string, error)

Unmerged is each path the merge left conflicted that is not resolved and staged yet.

type Check added in v0.4.0

type Check struct {
	Name  string `json:"name"`
	State string `json:"state"`
	URL   string `json:"url"`
}

Check is one check run or commit status on the head commit. State is a run's conclusion once it has one and its status before, or a status's state.

type Comment added in v0.4.0

type Comment struct {
	Author            string    `json:"author"`
	AuthorType        string    `json:"author_type"`
	AuthorAssociation string    `json:"author_association"`
	Body              string    `json:"body"`
	CreatedAt         time.Time `json:"created_at"`
	URL               string    `json:"url"`
}

Comment is one comment, on the conversation or in a review thread. AuthorType and AuthorAssociation are as on a Review.

type Commit added in v0.4.0

type Commit struct {
	OID         string    `json:"oid"`
	Headline    string    `json:"headline"`
	Author      string    `json:"author"`
	CommittedAt time.Time `json:"committed_at"`
}

Commit is one commit on the branch, newest last.

type Detail added in v0.4.0

type Detail struct {
	// HeadOID, UpdatedAt and ChecksRollup are the pull request's as this read found them. A
	// listing whose row differs in any reads it again. A check finishing moves neither the
	// head nor the update time, so the rollup is what reads checks again once they finish.
	HeadOID        string    `json:"head_oid"`
	UpdatedAt      time.Time `json:"updated_at"`
	ChecksRollup   string    `json:"checks_rollup"`
	ReadAt         time.Time `json:"read_at"`
	ReviewRequests []string  `json:"review_requests"`
	Reviews        []Review  `json:"reviews"`
	ReviewCount    int       `json:"review_count"`
	Comments       []Comment `json:"comments"`
	CommentCount   int       `json:"comment_count"`
	Threads        []Thread  `json:"threads"`
	ThreadCount    int       `json:"thread_count"`
	Files          []File    `json:"files"`
	FileCount      int       `json:"file_count"`
	Commits        []Commit  `json:"commits"`
	CommitCount    int       `json:"commit_count"`
	Checks         []Check   `json:"checks"`
}

Detail is what a pull request's own read adds to its row: who reviewed it at which commit, its conversation, its files, its commits and its head's checks. Each list holds as many as its query asks for, and each count is the whole.

func (Detail) NewestReview added in v0.14.0

func (d Detail) NewestReview() (Review, bool)

NewestReview is the review submitted last, and false where none was. A pending review has no time yet, so it is not one.

func (Detail) SinceReview added in v0.14.0

func (d Detail) SinceReview() SinceReview

SinceReview is how many commits came after the one the newest review read, or that it is gone from the branch. The commits the read holds end at the head, so a reviewed commit missing from a whole list is not on the branch.

type DetailState added in v0.4.0

type DetailState struct {
	Detail Detail
	// Held says Detail was read. A read under way or failed keeps the last one held.
	Held    bool
	Reading bool
	// Fault is why the newest read failed, and empty where it read.
	Fault string
}

DetailState is how one pull request's detail stands.

type Details added in v0.4.0

type Details struct {
	// contains filtered or unexported fields
}

Details holds each pull request's Detail in memory, by Key, read in the background after a listing lands, so moving the cursor never waits on the network. An entry is read again when its row's head commit, update time or checks rollup moves, or when its last read failed, so a pull request that reads cleanly and stays unchanged is asked for once.

func NewDetails added in v0.4.0

func NewDetails() *Details

NewDetails is an empty cache.

func (*Details) Of added in v0.4.0

func (d *Details) Of(pr PullRequest) DetailState

Of is how the pull request's detail stands now.

func (*Details) Prefetch added in v0.4.0

func (d *Details) Prefetch(ctx context.Context, provider Provider, prs []PullRequest) <-chan struct{}

Prefetch reads, in the background and detailsAtOnce at a time, the detail of each of provider's pull requests in prs whose held detail is missing, failed or older than its row. prs is that provider's whole listing, so it also drops the detail of each of the provider's pull requests prs does not hold. It returns at once, and the channel closes when every read it started has ended.

type Diff added in v0.10.0

type Diff struct {
	// Head is the commit it was read at, and empty where its source does not say.
	Head string
	// Lines is how many lines it adds and removes, together.
	Lines int
	// Whole says Files holds every file. It is false where Lines ran past the limit.
	Whole  bool
	Files  []FileDiff
	ReadAt time.Time
}

Diff is one pull request's changes as git prints them, from where its branch left its base, split by file. Where they change more lines than its reader keeps whole, Files is empty and Lines says how many they change.

type DiffState added in v0.10.0

type DiffState struct {
	Diff Diff
	// Held says Diff was read. A read under way or failed keeps the last one held.
	Held    bool
	Reading bool
	// Fault is why the newest read failed, and empty where it read.
	Fault string
	// Cannot is why prs reads no diff of it here, and empty where it can.
	Cannot string
	// InCheckout says it is read in its repo's checkout here rather than from its host.
	InCheckout bool
	// CheckedOut says its repo is checked out here, which is what d needs to open it.
	CheckedOut bool
	// Limit is the most lines a Diff changes for Files to be kept.
	Limit int
}

DiffState is how one pull request's diff stands.

type Diffs added in v0.10.0

type Diffs struct {
	// contains filtered or unexported fields
}

Diffs holds each pull request's Diff in memory, by Key, read in the background after a listing lands, so the Diff section never waits on the network. A diff comes from its host where the host's client has one, and from the repo's checkout otherwise, its head fetched by FetchHead. One is read again when its row's head commit or base moves, or once a failed read has waited out its retry. A row naming no head commit is read again when its update time moves.

func NewDiffs added in v0.10.0

func NewDiffs(limit int) *Diffs

NewDiffs is an empty cache whose diffs keep their files up to limit changed lines.

func (*Diffs) Of added in v0.10.0

func (d *Diffs) Of(pr PullRequest) DiffState

Of is how the pull request's diff stands now.

func (*Diffs) Prefetch added in v0.10.0

func (d *Diffs) Prefetch(ctx context.Context, from string, prs []PullRequest)

Prefetch reads, in the background, the diff of each of prs whose held diff is missing, older than its row, or failed and waited out. Each carries its Path, as Finish sets it. from names who listed prs, a provider or a read of one pull request, and Prefetch drops the diff of each pull request from listed that prs leaves out.

type Fetched added in v0.10.0

type Fetched struct {
	// Head is the commit the target's Ref holds.
	Head string
	// BaseFault is why fetching the base failed. A diff then runs against the origin/<base>
	// an earlier fetch left.
	BaseFault string
}

Fetched is what a fetch left in the checkout.

func Fetch added in v0.10.0

func Fetch(ctx context.Context, t LocalDiff) (Fetched, error)

Fetch is d's fetch, which the person asked for: the target's head into its Ref, then its base, as their own git fetch would move origin/<base>. It never checks the branch out, which would abort on uncommitted work and disturb the tree where there is none.

func FetchHead added in v0.10.0

func FetchHead(ctx context.Context, t LocalDiff) (Fetched, error)

FetchHead is the Diff section's fetch, which nobody asked for: the target's head into its Ref and nothing more. It writes no FETCH_HEAD and starts no maintenance, so every ref and file another program reads stays as it was, and the diff runs against the origin/<base> already there.

type File added in v0.4.0

type File struct {
	Path      string `json:"path"`
	Additions int    `json:"additions"`
	Deletions int    `json:"deletions"`
	Change    string `json:"change"`
}

File is one changed file. Change is the provider's word, such as MODIFIED or ADDED.

type FileDiff added in v0.10.0

type FileDiff struct {
	Path string
	// OldPath is where a renamed or copied file came from, and empty otherwise.
	OldPath string
	// Change is added, deleted, renamed, copied or modified.
	Change string
	// Binary says git found the content binary, so there are no hunks to show.
	Binary bool
	// Hunks is each @@ hunk and its lines, as git printed them.
	Hunks string
}

FileDiff is one file's part of a Diff: its hunks, without the header git writes above them.

type HistoryRecord added in v0.15.0

type HistoryRecord struct {
	Slug   string
	Number int
	Title  string
	URL    string
	// Author is the login that opened it, empty for a deleted account, and Bot whether an app
	// did, nil where the account is gone.
	Author string
	Bot    *bool
	// State is OPEN, MERGED or CLOSED. MergedAt is nil until it merges, and ClosedAt until it
	// merges or closes.
	State     string
	CreatedAt time.Time
	UpdatedAt time.Time
	MergedAt  *time.Time
	ClosedAt  *time.Time
	// ReviewRound says its first review was a review round's.
	ReviewRound bool
}

HistoryRecord is a pull request as the history read it, open, merged or closed.

func ReadGitHubHistory added in v0.15.0

func ReadGitHubHistory(ctx context.Context, scope Scope, from, to time.Time, roundPost func(Review) bool) ([]HistoryRecord, error)

ReadGitHubHistory is every pull request in the scope, in any state, last updated from from through to, or from from on where to is zero. Updated rather than closed, because GitHub's closed: qualifier leaves out some pull requests that closed within its range, and a pull request is never last updated before it closed. So it holds every one closed within the range, and a reopened one comes back open. roundPost says whether a review is a review round's. It reads every page of each search, and splits a search whose matches pass the most GitHub's search returns into halves of its stretch, as often as it takes. It fails where any search fails, so a caller keeping what it read never takes a stretch with a hole in it for one read whole.

func (HistoryRecord) IsBot added in v0.15.0

func (r HistoryRecord) IsBot() bool

IsBot says an app opened it, and false where the account is gone.

func (HistoryRecord) Merged added in v0.15.0

func (r HistoryRecord) Merged() bool

Merged says it merged.

type Listing

type Listing struct {
	PullRequests []PullRequest
	Notes        []string
}

Listing is what one provider's read found: its pull requests, and what it could not cover while still reading.

func ReadBitbucket

func ReadBitbucket(ctx context.Context, scope Scope, last Listing) (Listing, error)

ReadBitbucket lists each repo's open pull requests with bbkt, one call per repo, run in the repo's checkout because that is how bbkt finds the repo. The calls run at the same time, and their rows keep the registry's order.

A repo bbkt cannot list keeps its rows from last, the previous good listing, with a note saying so, so one repo's failure does not take the others' rows with it. A repo not checked out here cannot be read, and the notes name it.

func ReadGitHub

func ReadGitHub(ctx context.Context, scope Scope, last Listing) (Listing, error)

ReadGitHub is every open pull request in the scope, in one request. A search GitHub refused while others answered keeps the rows it found in last.

func ReadGitHubClosed added in v0.8.0

func ReadGitHubClosed(ctx context.Context, scope Scope, since time.Time, last Listing) (Listing, error)

ReadGitHubClosed is every pull request in the scope merged or closed at or after since, in one request, as ReadGitHub reads the open ones.

func (Listing) Note

func (l Listing) Note() string

Note is the listing's notes as one line.

type LocalDiff added in v0.10.0

type LocalDiff struct {
	Number   int
	Repo     string
	Checkout string
	// Head is the pull request's head on origin, as its provider names it.
	Head string
	// Base is the branch the listing says it targets, or origin's default where it names none.
	Base string
}

LocalDiff is a pull request as git diffs it in its checkout here: its head fetched into a ref of its own, diffed three-dot from origin/<base>, from where the branch left its base, which is what the provider shows. d opens it, and the Diff section reads it where the host's client has no diff.

func LocalDiffOf added in v0.10.0

func LocalDiffOf(ctx context.Context, pr PullRequest) (LocalDiff, error)

LocalDiffOf is the pull request's LocalDiff, or why it has none. The base is the one the listing reports, because a pull request stacked on another targets its parent, and a diff against main would show both as one change.

func (LocalDiff) Range added in v0.10.0

func (t LocalDiff) Range() string

Range is what git diffs: three-dot, from where the branch left origin/<base>.

func (LocalDiff) RangeFrom added in v0.14.0

func (t LocalDiff) RangeFrom(commit string) string

RangeFrom is what git diffs from commit, which the head holds, to the head: what was pushed after it.

func (LocalDiff) Ref added in v0.10.0

func (t LocalDiff) Ref() string

Ref is where the head is fetched to. It sits under refs/remotes/origin, so it never shows as a branch.

type Named added in v0.5.0

type Named struct {
	PullRequest PullRequest
	Detail      *Detail
	Standing    Standing
}

Named is one pull request a reference names, as its own read found it. Detail is nil where the provider reads none.

func ReadReference added in v0.5.0

func ReadReference(ctx context.Context, ref Reference, repos []registry.Repo) (Named, error)

ReadReference reads the pull request ref names, open or not. owner/name#number is the registry's repo of that slug, on whichever provider hosts it, and GitHub where the registry names none. A URL whose host is not the one the pull request was read from is refused, because a repo of the same name there holds a different pull request.

type Provider

type Provider struct {
	Name string
	// Standings is each state word the host's client prints, and where it puts the pull
	// request.
	Standings map[string]Standing
	// PagePath reads owner/name and the number out of the path of a pull request's page,
	// split at its slashes, and is false for a path that is not one.
	PagePath func(parts []string) (slug, number string, ok bool)
	// Read lists the open pull requests in the scope. last is the previous good listing,
	// for a reader that can keep one repo's rows when only that repo failed.
	Read func(ctx context.Context, scope Scope, last Listing) (Listing, error)
	// ReadClosed lists the pull requests in the scope merged or closed at or after since, as
	// Read lists the open ones. Nil where the host's client cannot say when one closed.
	ReadClosed func(ctx context.Context, scope Scope, since time.Time, last Listing) (Listing, error)
	// Detail reads what the listing leaves out of one pull request. Nil where the host's
	// client reads no more than its listing.
	Detail func(ctx context.Context, pr PullRequest) (Detail, error)
	// ReadOne reads the one pull request ref names, open or not, with its detail where the
	// host has one.
	ReadOne func(ctx context.Context, ref Reference) (PullRequest, *Detail, error)
	// Diff reads the pull request's diff in git's format from the host, for one whose repo is
	// not checked out here. Nil where the host's client has no diff.
	Diff func(ctx context.Context, pr PullRequest) (string, error)
	// ReadsOwners says Read can read an owner whole, for a config that names owners.
	ReadsOwners bool
	// Head is what git fetches from origin as the pull request's head.
	Head func(PullRequest) string
	// Browse is the command that opens the pull request in the browser, and whether it
	// runs in the checkout.
	Browse func(PullRequest) (argv []string, inCheckout bool)
	// Merge, Close and Comment are the commands that change the pull request, and whether
	// each runs in the checkout. Each runs with no terminal, so none may prompt. Where head
	// is not empty and the client can pin a commit, Merge refuses a head other than head.
	// Comment posts the file at path.
	Merge   func(pr PullRequest, head string) (argv []string, inCheckout bool)
	Close   func(PullRequest) (argv []string, inCheckout bool)
	Comment func(pr PullRequest, path string) (argv []string, inCheckout bool)
	// UpdateBranch, Ready, Rerun and FailedLog are the fix menu's commands, and run with no
	// terminal as Merge does. UpdateBranch merges the base into the head branch on the host,
	// and Ready takes a draft out of draft. Rerun runs a run's failed jobs again, and FailedLog
	// prints what they logged, for a run CheckRun reads from a check's URL, empty for a check
	// that is not one.
	UpdateBranch func(PullRequest) (argv []string, inCheckout bool)
	Ready        func(PullRequest) (argv []string, inCheckout bool)
	Rerun        func(pr PullRequest, run string) (argv []string, inCheckout bool)
	FailedLog    func(pr PullRequest, run string) (argv []string, inCheckout bool)
	CheckRun     func(url string) string
}

Provider is everything prs does differently by host, so a host is added in one place. Name, Standings, PagePath, Read and Head every host has. Every other function is a verb a host's client may lack, and is nil there. The key for a nil verb says the host cannot do it.

func ProviderOf

func ProviderOf(name string) (Provider, error)

ProviderOf is the Provider named name.

func (Provider) Word added in v0.8.0

func (p Provider) Word(standing Standing) string

Word is the state word the host prints for standing, the first in sorted order where it prints several, such as Bitbucket's DECLINED and SUPERSEDED.

type PullRequest

type PullRequest struct {
	// Provider says who hosts it. Every action but the local diff dispatches on it.
	Provider string `json:"provider"`
	// Repo is the bare name and only a label, since two repositories can share one. Slug
	// identifies the repository.
	Repo   string `json:"repo"`
	Slug   string `json:"slug"`
	Number int    `json:"number"`
	Title  string `json:"title"`
	// Author is the login that opened it, and empty for a deleted account.
	Author string `json:"author"`
	// Bot is true where the provider says an app opened it, and null where its listing
	// does not say.
	Bot    *bool  `json:"bot"`
	Body   string `json:"body"`
	URL    string `json:"url"`
	Branch string `json:"branch"`
	Base   string `json:"base"`
	Draft  bool   `json:"draft"`
	// HeadInFork says the head branch is in another repo than the pull request's, which
	// origin is not, so the fix menu pushes no merge to it. Bitbucket's listing does not say,
	// so it stays out of --json rather than reading false there.
	HeadInFork bool      `json:"-"`
	CreatedAt  time.Time `json:"created_at"`
	// The diff counts are null, never 0, from a provider whose listing does not count
	// them. A pull request nobody counted is not one that changed nothing.
	Additions    *int `json:"additions"`
	Deletions    *int `json:"deletions"`
	ChangedFiles *int `json:"changed_files"`
	// Review is the provider's decision, and Reviews how many were submitted. A review can
	// set no decision, so the two disagree routinely. Both review and checks are empty
	// until a review is requested and a workflow has run.
	Review  string `json:"review"`
	Reviews int    `json:"reviews"`
	Checks  string `json:"checks"`
	// AgeDays is how long it has been open, and Path where its repo is checked out here.
	AgeDays int    `json:"age_days"`
	Path    string `json:"path"`
	// State is OPEN, MERGED or CLOSED on GitHub, and bbkt's word on Bitbucket.
	State string `json:"state"`
	// The times are null until they happen, and UpdatedAt where the listing omits it.
	MergedAt  *time.Time `json:"merged_at"`
	ClosedAt  *time.Time `json:"closed_at"`
	UpdatedAt *time.Time `json:"updated_at"`
	// Mergeable and MergeStateStatus are GitHub's enums, which read UNKNOWN until GitHub has
	// computed them. They, InMergeQueue and HeadOID are null where the listing does not
	// carry them, as bbkt's does not.
	Mergeable        *string `json:"mergeable"`
	MergeStateStatus *string `json:"merge_state_status"`
	InMergeQueue     *bool   `json:"in_merge_queue"`
	HeadOID          *string `json:"head_oid"`
}

PullRequest is one pull request, in the fields `prs list --json` prints, in the order it prints them. cmd/prs/list.schema.json is that shape.

func Finish

func Finish(prs []PullRequest, repos []registry.Repo, now time.Time) []PullRequest

Finish sets each pull request's age and its repo's checkout, and sorts them oldest first, because a backlog is a gauge and age is what it measures. A slug matches in any case, as GitHub matches owners and names.

func (PullRequest) IsBot added in v0.15.0

func (pr PullRequest) IsBot() bool

IsBot says an app opened it. One whose listing does not say, or whose account is gone, counts as a person's.

func (PullRequest) Key

func (pr PullRequest) Key() string

Key names a pull request across reads, when its position and every field can change. It carries the provider, because a GitHub repo and a Bitbucket one can share owner/name.

func (PullRequest) Standing added in v0.5.0

func (pr PullRequest) Standing() (Standing, error)

Standing is where the pull request stands, by its provider's Standings. A word the provider does not name is refused, because a guess would draw a declined pull request as open, or the reverse.

type Pushed added in v0.17.0

type Pushed struct {
	Commit   string
	Unremove string
}

Pushed is what Push left: the merge on the head branch, and why the worktree is still there where removing it failed.

type Reference added in v0.5.0

type Reference struct {
	// Provider is empty for owner/name#number, which the registry resolves.
	Provider string
	// Host is the URL's, and empty for owner/name#number.
	Host   string
	Slug   string
	Number int
}

Reference names one pull request as a person or another program hands it to prs.

func ParseReference added in v0.5.0

func ParseReference(text string) (Reference, error)

ParseReference reads owner/name#number, or the URL of a pull request's page on a host whose PagePath reads it.

func (Reference) String added in v0.5.0

func (r Reference) String() string

type Review added in v0.4.0

type Review struct {
	Author string `json:"author"`
	// AuthorType is the author's kind, such as User or Bot, and AuthorAssociation what the
	// author is to the repo, such as OWNER or NONE, in the provider's words. Both are empty
	// where the provider does not say.
	AuthorType        string `json:"author_type"`
	AuthorAssociation string `json:"author_association"`
	State             string `json:"state"`
	Body              string `json:"body"`
	// SubmittedAt is null for a review still pending, and CommitOID empty where the commit
	// is gone from the branch.
	SubmittedAt *time.Time `json:"submitted_at"`
	CommitOID   string     `json:"commit_oid"`
	URL         string     `json:"url"`
}

Review is one submitted review, and the commit it was submitted against, which is what says how much changed since.

type Scope added in v0.4.0

type Scope struct {
	Repos []registry.Repo
	// Owners are GitHub owners searched whole. ViewerOwner stands for whoever the token is.
	Owners []string
}

Scope is what one provider's read covers: the registry's repos it hosts, each asked for by name, or with no registry the whole of some owners.

func (Scope) Empty added in v0.4.0

func (s Scope) Empty() bool

Empty says the scope names nothing to read.

func (Scope) Names added in v0.15.0

func (s Scope) Names() (repos, owners []string)

Names are the scope's repos as owner/name and its owners, each in lower case, sorted and named once, because GitHub matches both in any case. A search asks for them, and a cache of what the scope read is named by them, so a registry edit that changes neither keeps its cache. Neither is nil.

type Since added in v0.8.0

type Since struct {
	// contains filtered or unexported fields
}

Since is where the recently closed pull requests start: a span back from each read, so a board left open keeps the same stretch behind it, or a fixed instant.

func ParseSince added in v0.8.0

func ParseSince(text string, loc *time.Location) (Since, error)

ParseSince reads --since: a span such as 30m, 12h, 2d or 1w, a day such as 2026-10-01, whose first instant in loc it starts at, or an RFC 3339 instant.

func (Since) From added in v0.8.0

func (s Since) From(now time.Time) time.Time

From is the first instant inside the window for a read at now.

func (Since) String added in v0.8.0

func (s Since) String() string

type SinceReview added in v0.14.0

type SinceReview struct {
	// Commits is how many commits came after the reviewed one, where Known.
	Commits int
	// Gone says the branch does not hold the reviewed commit, as after a rebase.
	Gone bool
	// Known is false where no review was submitted, or the reviewed commit is older than the
	// commits the read holds, so neither Commits nor Gone can be told.
	Known bool
}

SinceReview is how the head stands against the commit the newest review read.

type Standing added in v0.5.0

type Standing int

Standing is where a pull request stands, in the three words prs acts on, whatever word its host prints for it.

const (
	Open Standing = iota
	Merged
	Closed
)

func (Standing) String added in v0.5.0

func (s Standing) String() string

type Thread added in v0.4.0

type Thread struct {
	Path         string    `json:"path"`
	Line         *int      `json:"line"`
	Side         string    `json:"side"`
	Resolved     bool      `json:"resolved"`
	Outdated     bool      `json:"outdated"`
	Comments     []Comment `json:"comments"`
	CommentCount int       `json:"comment_count"`
}

Thread is one review thread on a line of a file. Line is null where the thread's line is gone from the diff. Side is LEFT where Line counts in the base's copy of the file and RIGHT where it counts in the head's.

Jump to

Keyboard shortcuts

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