pulls

package
v0.0.0-...-6f1d02b Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2026 License: Apache-2.0 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 pulls keeps every repository's open pull requests and says for each whose turn it is (design/pulls.md, P-68).

Index

Constants

View Source
const (

	// ConfirmAfter is when a run caused by an event reads again: GitHub's listing can be a few seconds behind the event.
	ConfirmAfter = 30 * time.Second
)
View Source
const Kind = "pulls"

Kind is the job kind that reads a repository's open pull requests.

Variables

View Source
var Events = []sync.Event{sync.EventPush, sync.EventOpen, "pull_request", "pull_request_review"} //nolint:gochecknoglobals // a constant list

Events are the webhook deliveries that re-read a repository's pull requests (webhook.Normalise passes them by their names). Not check_suite or status: they fire on every CI update of every commit; running checks are asked again on their own steps.

View Source
var States = []State{StateDraft, StateConflicts, StateFailing, StateChanges, StateReview, StateChecks, StateReady, StateUnknown} //nolint:gochecknoglobals // a constant list

States are the states in the order whose turn is told.

Functions

func Badge

func Badge(e *snapshot.RepoEntry) (open, review int)

Badge is a repository's open pull requests and how many wait for a review (open -1 when not read yet), for its badge.

func Counts

func Counts(refs []Ref, by By) oapi.PullCounts

Counts are the open pull requests of refs that by keeps.

func Dashboard

func Dashboard(s *snapshot.Snapshot, d *oapi.Dashboard)

Dashboard adds the open pull requests of the fleet and of each group, of the work that counts.

func Feeds

func Feeds() snapshot.Indexer

Feeds is the indexer of the merged pull requests, for snapshot.NewPublisher.

func Open

func Open(e *snapshot.RepoEntry) int

Open is the open pull requests of a repository (-1 when not read yet).

func PullOf

func PullOf(r Ref) oapi.PullRequest

PullOf is a pull request in its API form.

func Repo

func Repo(_ *snapshot.Snapshot, e *snapshot.RepoEntry, r *oapi.Repo)

Repo adds the open pull requests to a repository summary.

func Waiting

func Waiting(e *snapshot.RepoEntry, old time.Duration, now time.Time) (review time.Duration, stale int)

Waiting is what a repository's health reads of its pull requests: how long the person's pull request that waits longest for a review has been idle, and how many of automation's are older than old.

Types

type API

type API struct {
	Current func(context.Context) *snapshot.Snapshot // the viewer's view
	Off     bool                                     // switched off (features.pulls): every request is answered 404
}

API serves the open pull requests from the current snapshot. It implements the pulls method of the strict server.

type By

type By uint8

By selects whose pull requests count.

const (
	ByAll        By = iota
	ByPeople        // people's only
	ByAutomation    // automation's only
)

func ByWork

func ByWork(w oapi.Work) By

ByWork is whose pull requests the work that counts holds: automation's only when it names automation.

type Detail

type Detail struct {
	Review    string // APPROVED, CHANGES_REQUESTED, REVIEW_REQUIRED, or empty when no review is required
	Approved  bool   // a reviewer's latest opinion approves
	Changes   bool   // a reviewer's latest opinion asks for changes
	Checks    string // the head commit's rollup: SUCCESS, FAILURE, ERROR, PENDING, EXPECTED, or empty for none
	Mergeable string // MERGEABLE, CONFLICTING, UNKNOWN
	Stats     Stats
}

Detail is what GraphQL adds to a pull request: its review decision, the reviews that hold an opinion, its checks, whether it merges and its diff stats.

type Fetcher

type Fetcher interface {
	// Open lists the first 100 open pull requests, the most recently updated first.
	Open(ctx context.Context, owner, name string) ([]Listed, error)
	// Details asks at most maxAsk pull requests by number, and the total of open pull requests when total is set (-1 otherwise).
	Details(ctx context.Context, owner, name string, numbers []int, total bool) (map[int]Detail, int, error)
}

Fetcher reads a repository's open pull requests.

func FromGitHub

func FromGitHub(src REST) Fetcher

FromGitHub reads pull requests through src.

type Label

type Label = untrusted.Label

Label is a pull request's label.

type Listed

type Listed struct {
	Number              int
	Title, URL, Author  string
	AuthorBot           bool // the author's account type is Bot
	Draft, Fork         bool
	Created, Updated    time.Time
	Base, Head, HeadSHA string
	Labels              []Label
	Requested           int // reviewers and teams asked
	Reviewers           []string
	// contains filtered or unexported fields
}

Listed is an open pull request as GitHub's REST listing gives it.

type Options

type Options struct {
	// Repo is the catalogued repository at a key: an archived one is read once.
	Repo func(snapshot.RepoKey) (snapshot.Repo, bool)
	Now  func() time.Time
}

Options are what the job reads of the catalogue.

type Pull

type Pull struct {
	Number    int       `json:"n"`
	Title     string    `json:"title"`
	URL       string    `json:"url"`
	Author    string    `json:"author"`
	Bot       bool      `json:"bot,omitempty"`
	Draft     bool      `json:"draft,omitempty"`
	Fork      bool      `json:"fork,omitempty"`
	Created   time.Time `json:"created"`
	Updated   time.Time `json:"updated"`
	Base      string    `json:"base"`
	Head      string    `json:"head"`
	HeadSHA   string    `json:"sha"`
	Labels    []Label   `json:"labels,omitempty"`
	Requested int       `json:"requested,omitempty"`
	Reviewers []string  `json:"reviewers,omitempty"` // the first maxReviewers people asked, by login (teams are only counted)
	Review    string    `json:"review,omitempty"`
	Approved  bool      `json:"approved,omitempty"`
	Changes   bool      `json:"changes,omitempty"`
	Checks    string    `json:"checks,omitempty"`
	Mergeable string    `json:"mergeable,omitempty"`
	Stats     *Stats    `json:"stats,omitempty"`
	Asked     time.Time `json:"asked,omitzero"`
}

Pull is an open pull request: the REST listing's fields, and GraphQL's from when it was asked (Asked zero: never).

type Pulls

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

Pulls is the pull requests feature.

func New

func New(sources map[string]Fetcher, o Options) *Pulls

New returns the feature for one Fetcher per source id.

func (*Pulls) Spec

func (p *Pulls) Spec() sync.Spec

Spec is the per-repository pull requests job.

type REST

type REST interface {
	REST(ctx context.Context, owner, name string) (*gh.Client, error)
	GraphQLURL() string
}

REST is a source's GitHub API client per owner and its GraphQL endpoint; *github.Source implements it.

type Ref

type Ref struct {
	Repo  snapshot.RepoKey
	Pull  *Pull
	State State
}

Ref is an open pull request of a repository with its state.

func All

func All(s *snapshot.Snapshot) []Ref

All is every open pull request of s, whose turn first.

func OfGroup

func OfGroup(s *snapshot.Snapshot, id string) []Ref

OfGroup is a group's open pull requests in s, whose turn first; OfRepo a repository's; All the fleet's.

func OfRepo

func OfRepo(s *snapshot.Snapshot, k snapshot.RepoKey) []Ref

OfRepo is a repository's open pull requests in s, whose turn first.

type Set

type Set struct {
	Total     int       `json:"total"` // open on GitHub: len(Pulls) unless there are more than 100
	Pulls     []Pull    `json:"pulls"`
	Full      time.Time `json:"full,omitzero"`      // when every pull request was last asked
	Pending   int       `json:"pending,omitempty"`  // the step of pendingSteps the waiting ones are at
	PendingAt time.Time `json:"pendingAt,omitzero"` // when the waiting ones were last asked
}

Set is a repository's open pull requests, the most recently updated first.

func Of

Of is a repository's open pull requests (nil when not read yet) with their freshness.

type State

type State string

State is whose turn a pull request is, the first that holds.

const (
	StateDraft     State = "draft"     // the author: still a draft
	StateConflicts State = "conflicts" // the author: it does not merge
	StateFailing   State = "failing"   // the author: its checks fail
	StateChanges   State = "changes"   // the author: a reviewer asked for changes
	StateReview    State = "review"    // reviewers: a review is required, or none approved yet
	StateChecks    State = "checks"    // CI: its checks run
	StateReady     State = "ready"     // a maintainer: approved or no review required, checks pass
	StateUnknown   State = "unknown"   // not asked yet
)

func StateOf

func StateOf(p *Pull) State

StateOf is whose turn p is.

func (State) Waits

func (s State) Waits() string

Waits is the party a state waits for.

type Stats

type Stats struct {
	Additions int `json:"additions"`
	Deletions int `json:"deletions"`
	Files     int `json:"files"`
}

Stats is what a pull request changes.

Jump to

Keyboard shortcuts

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