pullrequests

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: MIT Imports: 11 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, through the provider's own command-line client.

gh and bbkt are run rather than replaced with an HTTP client, because they hold the credentials.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoAnswer = fmt.Errorf("no answer in %s", readTimeout)

ErrNoAnswer is a client killed at its timeout. A client that changes a pull request may have changed it by then.

View Source
var Providers = []Provider{
	{
		Name: registry.GitHub,
		Read: ReadGitHub,
		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
		},

		Page: func(pr PullRequest) (string, []string) {
			return fmt.Sprintf("GH_FORCE_TTY=$(tput cols) gh pr view %d --repo %s --comments | less -R", pr.Number, pr.Slug),
				[]string{"gh", "tput", "less"}
		},

		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
		},
	},
	{
		Name: registry.Bitbucket,
		Read: ReadBitbucket,

		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 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.

Types

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, repos []registry.Repo, 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.

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, repos []registry.Repo, _ Listing) (Listing, error)

ReadGitHub is every open pull request on the registry's GitHub repos, in one request.

func (Listing) Note

func (l Listing) Note() string

Note is the listing's notes as one line.

type Provider

type Provider struct {
	Name string
	// Read lists the open pull requests on the repos it hosts. 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, repos []registry.Repo, last Listing) (Listing, error)
	// 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)
	// Page is a shell command paging the pull request with its comments, and the programs
	// it runs.
	Page func(PullRequest) (command string, needs []string)
	// 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)
}

Provider is everything prs does differently by host, so a host is added in one place. Every field after Head 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.

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"`
	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"`
}

PullRequest is one open pull request, in the fields `prs tui --json` prints.

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) Key

func (pr PullRequest) Key() string

Key names a pull request across reads, when its position and every field can change.

Jump to

Keyboard shortcuts

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