pushwatch

package
v0.9.2 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: MIT Imports: 14 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 pushwatch notices a push made on this Mac to a pull request the inbox lists, so its card catches up at once rather than at the next refresh.

Git runs no hook after a push, but a push that lands leaves a trace in the clone: git moves the clone's own copy of the branch on the remote, refs/remotes/origin/<branch>, to the commit it pushed, whichever program ran the push (a terminal, an editor, an agent). A Watcher, a desktop worker, follows that ref for each open pull request whose head branch is in its own repository (Targets), in every clone whose origin is that repository, and when it moves to a commit GitHub hasn't reported for the pull request, hands the item to the inbox to read again (Rereader): one GraphQL point. A fetch that brings someone else's push moves the ref the same way, and the card catches up the same way. GitHub takes in a push's pull request a moment after the push, so the read waits Settle, and is made again, at most twice more, while GitHub still reports the old head.

It costs little and changes nothing. Each Tick it stats the ref file of each pull request watched, and reads one only once it changed: no process starts, and nothing is asked of GitHub until a branch moves. A clone's origin is read with git once, and again only when the clone's config file changes; the clones are listed again every IndexEvery. A clone that keeps its refs in reftable, which has no file per ref, is read with one allowlisted rev-parse (Git, gitread's) once its table list changes. Nothing is written to a clone or installed in it: no hook, no config.

It can't see a push made from another machine or on GitHub (the refresh brings those), a push to a URL rather than to origin, which moves no ref, a fork's branch, or a gh command that changes a pull request without git; a session the app launched is followed for those by the sessions' Watcher.

Index

Constants

View Source
const (
	// DefaultTick is how often the refs of the pull requests watched are looked at while
	// any has a clone: a stat each.
	DefaultTick = 3 * time.Second

	// DefaultSettle is how long after its branch moved a pull request is read again, so
	// GitHub has taken in the push by then.
	DefaultSettle = 2 * time.Second

	// DefaultIndexEvery is how often the clones are listed again, for a clone added or
	// removed, or an origin changed: a stat or two each, and git only for a clone whose
	// config changed.
	DefaultIndexEvery = 5 * time.Minute

	// DefaultTargetsEvery is how often the pull requests watched, and the switch, are read
	// again when nothing woke the Watcher sooner: the inbox wakes it whenever it changes.
	DefaultTargetsEvery = time.Minute

	// MaxTargets is the most pull requests watched at once, the first the Targets list.
	MaxTargets = 200
)

The Watcher's pace.

Variables

This section is empty.

Functions

This section is empty.

Types

type Clones

type Clones interface {
	CloneDirs(ctx context.Context) ([]string, error)
}

Clones lists the folders of the user's clones, in the clone root and the other repository locations, reading no git. Core implements it over the settings.

type Config

type Config struct {
	Targets  Targets
	Clones   Clones
	Origins  Origins
	Rereader Rereader

	// Switch is the user's switch; without it, the watch is always on.
	Switch Switch

	// Git reads a reftable clone's refs; without it, such a clone isn't watched.
	Git Git

	// Clock tells the time; it defaults to the system clock.
	Clock clock.Clock

	Logger *slog.Logger

	// Tick, Settle, IndexEvery, and TargetsEvery default to the Default constants.
	Tick         time.Duration
	Settle       time.Duration
	IndexEvery   time.Duration
	TargetsEvery time.Duration
}

Config holds a Watcher's dependencies. Targets, Clones, Origins, and Rereader are required.

type Git

type Git interface {
	Run(ctx context.Context, dir string, args ...string) (stdout, stderr []byte, err error)
}

Git runs an allowlisted, read-only git command in the clone at dir; *gitread.Git implements it. Only a clone that keeps its refs in reftable needs it.

type Origins

type Origins interface {
	Origin(ctx context.Context, dir string) (repo.Name, bool, error)
}

Origins reads which GitHub repository the origin of the clone at dir points at, and whether it is one. Core implements it with localrepos.Inspect.

type Rereader

type Rereader interface {
	Reread(itemID int64)
}

Rereader reads an item again from GitHub. Reread must not block. The inbox's Rereads implements it.

type Switch

type Switch interface {
	WatchPushes(ctx context.Context) (bool, error)
}

Switch reads whether the user watches for pushes. The settings service implements it.

type Target

type Target struct {
	// ItemID is the inbox item the Rereader reads again.
	ItemID int64

	// Repo is the pull request's repository, whose clones the watch looks in.
	Repo repo.Name

	// Branch is the head branch, followed as origin's in each clone.
	Branch string

	// Head is the head commit GitHub last reported, "" before it was read.
	Head string
}

Target is a pull request the watch follows: an open pull request whose head branch is in its own repository.

type Targets

type Targets interface {
	PushTargets(ctx context.Context) ([]Target, error)
}

Targets lists the pull requests to watch, the ones a push most likely moves first. The inbox implements it, through core.

type Watcher

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

Watcher follows the branches of the inbox's pull requests in the user's clones, a desktop.Worker that runs while the app is open, and has a pull request read again once its branch moves to a commit GitHub hasn't reported for it.

func NewWatcher

func NewWatcher(cfg Config) *Watcher

NewWatcher returns a Watcher over cfg that has not started.

func (*Watcher) Run

func (w *Watcher) Run(ctx context.Context)

Run watches until ctx ends: it reads the switch and the pull requests at once, and again whenever woken or once DefaultTargetsEvery passed, lists the clones, and then looks at the refs once a Tick while any pull request has a clone. While the switch is off, it looks at nothing and waits to be woken.

func (*Watcher) Wake

func (w *Watcher) Wake()

Wake asks the Watcher to read the switch and the pull requests again now, as a change to the inbox or to the settings does. It never waits.

Jump to

Keyboard shortcuts

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