collect

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: Apache-2.0 Imports: 16 Imported by: 1 module, 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 collect keeps the plugin's store in step with GitHub: a cheap fast sweep that reads only what changed and a slow sweep that rebuilds the scope and catches what the searches no longer return.

Index

Constants

View Source
const TrackMax = 50

TrackMax bounds what every fast sweep reads by reference for tracking alone: three batches of InventoryByRef.

Variables

This section is empty.

Functions

func EventsFrom

func EventsFrom(s api.Snapshot, prevChecks string, now time.Time) []pr.Event

EventsFrom turns a snapshot into GitHub events. prevChecks is the stored checks state, so a check event is produced only when it changes.

func MyTeams

func MyTeams(ctx context.Context, st *store.DB) ([]string, error)

MyTeams are the scope teams the viewer belongs to, as the last slow sweep resolved them; nil before the first one or when the stored scope is unreadable.

func Outcome

func Outcome(rep Report, err error) (summary, skipped string, _ error)

Outcome is a sweep as a job's outcome: truncation and warnings become the skipped text, so they surface in health without failing the job.

func StoredBudget

func StoredBudget(ctx context.Context, st *store.DB) ([]api.Limit, error)

StoredBudget is the GitHub budget the last sweep kept, for the client's Restore; nil when none was kept or it is unreadable.

func UntrackFinished

func UntrackFinished(ctx context.Context, st *store.DB, now func() time.Time, logf func(string, ...any))

UntrackFinished clears the track of pull requests a read showed merged or closed; from then on they are followed like any finished pull request.

Types

type Collector

type Collector struct {
	Store *store.DB
	GH    GitHub
	// WS lists the host's workspaces; nil when it lists none.
	WS Listings
	// Cfg is the configuration in force at each call.
	Cfg      func() Config
	Now      func() time.Time
	MaxPages int // per query, default 10
	Log      func(format string, args ...any)
	// Changed tells the host that host-visible state the snapshots do not
	// carry changed, such as the viewer's teams; nil tells nothing.
	Changed func(ctx context.Context, topics ...sdk.Topic)
	// contains filtered or unexported fields
}

func (*Collector) DetailMaxAge

func (c *Collector) DetailMaxAge() time.Duration

DetailMaxAge is how old a stored detail may grow before a fast run reads its pull request again: the slow interval.

func (*Collector) Fast

func (c *Collector) Fast(ctx context.Context) (Report, error)

Fast is one fast pass: the two-phase pass of the GitHub source, then the reads no stub can stand for, tracked and workspace-linked pull requests the store lacks, and the workspaces' links.

func (*Collector) ReadOne

func (c *Collector) ReadOne(ctx context.Context, ref api.Ref) (Read, error)

ReadOne reads ref in full at the priority ctx carries and stores nothing: ErrNotFound when GitHub has no such pull request or will not show it, ErrUnavailable when the read failed.

func (*Collector) Refresh

func (c *Collector) Refresh(ctx context.Context, ref api.Ref) error

Refresh reads ref in full at the priority ctx carries and stores the read.

func (c *Collector) Relink(ctx context.Context) error

Relink links each workspace the host lists to its pull request, as the end of a fast pass does, without reading GitHub.

func (*Collector) Save

func (c *Collector) Save(ctx context.Context, r Read) error

Save stores r.

func (*Collector) Slow

func (c *Collector) Slow(ctx context.Context) (Report, error)

type Config

type Config struct {
	Scope        scope.Config
	ReviewPrefix string
	// RateLimitFraction is the share of the rate limit the sweeps may spend.
	RateLimitFraction float64
	// Slow is the slow sweep's period, which bounds a detail's age.
	Slow time.Duration
	// NeedsMe are the board columns a workspace waiting on the user sits in.
	NeedsMe []string
}

Config is what the collector reads of the configuration in force.

type Follows

type Follows struct {
	Store *store.DB
	// Read reads a pull request about to be tracked; nil tracks it unread.
	Read func(ctx context.Context, ref api.Ref) (Read, error)
	// Save stores a read.
	Save func(ctx context.Context, r Read) error
	Now  func() time.Time
	// Name is what the refusals call the loop.
	Name string
	// contains filtered or unexported fields
}

Follows track and untrack the pull requests the user follows by hand, in two phases: a read, which stores nothing, and a follow, which admits the read and stores it.

func (*Follows) Follow

func (f *Follows) Follow(ctx context.Context, ref api.Ref) (src.Tracked, error)

Follow tracks ref once its slot and its state allow it, storing the read ReadTrack kept of it first; a refused track leaves no row.

func (*Follows) ReadTrack

func (f *Follows) ReadTrack(ctx context.Context, ref api.Ref) (src.Tracked, error)

ReadTrack reads a pull request about to be tracked, so a nudge right after the track finds its situation, and names it as GitHub does. It refuses a new track past TrackMax. The read runs without the lock, so a slow read stalls no other track, and is kept for Follow.

func (*Follows) Untrack

func (f *Follows) Untrack(ctx context.Context, ref api.Ref) error

Untrack stops tracking ref, the tracked pull request it names under any case.

type GitHub

type GitHub interface {
	SearchStubs(ctx context.Context, q, after string) (api.StubPage, error)
	SearchStubsFirst(ctx context.Context, qs []string, first int) ([]api.StubPage, []error, error)
	StubsByRef(ctx context.Context, refs []api.Ref) (map[api.Ref]api.Stub, map[api.Ref]error, error)
	InventoryByRef(ctx context.Context, refs []api.Ref) (map[api.Ref]api.Snapshot, map[api.Ref]error, api.RateLimit, error)
	Threads(ctx context.Context, refs map[api.Ref]int) (map[api.Ref][]pr.Thread, map[api.Ref]error, error)
	TeamMembers(ctx context.Context, org, slug string) ([]string, error)
	Viewer(ctx context.Context) (string, error)
	Allow(p api.Priority) bool
	Budget() map[api.Resource]api.Limit
	FindByBranch(ctx context.Context, queries []api.BranchQuery) (map[api.BranchQuery][]api.BranchMatch, error)
}

type Listings

type Listings interface {
	Workspaces(ctx context.Context, repo string) (src.Listing, error)
}

Listings are the host's workspaces, as the broker lists them.

type Read

type Read struct {
	Snapshot api.Snapshot
	// contains filtered or unexported fields
}

Read is a pull request read in full and not yet stored.

type Report

type Report struct {
	Queries   int
	Stubs     int
	Fetched   int // full snapshots read
	Events    int
	Failed    int // searches and reads that errored
	Truncated []string
	RateLimit api.Limit // the GraphQL budget once the sweep ended
	Skipped   string    // non-empty when the sweep did not run (budget)
	Warnings  []string
}

Jump to

Keyboard shortcuts

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