Documentation
¶
Overview ¶
Package store is the GitHub plugin's own database, in the state directory the host gives it: the pull requests it reads, their sightings and details, the workspaces' fetches, its meta values and the overrides it keeps of what the user set.
Index ¶
- Constants
- func FactsOf(p pr.PR, d Detail, viewer string) pr.Facts
- type Change
- type DB
- func (db *DB) Adopted(ctx context.Context) (map[pr.Ref]bool, error)
- func (db *DB) Close() error
- func (db *DB) DetailStamps(ctx context.Context, refs []pr.Ref) (map[pr.Ref]Detail, error)
- func (db *DB) Details(ctx context.Context, refs []pr.Ref) (map[pr.Ref]Detail, error)
- func (db *DB) HostEvents(ctx context.Context, refs []pr.Ref, since time.Time, kinds ...string) ([]pr.Event, error)
- func (db *DB) LastEvent(ctx context.Context, ref pr.Ref, kind string) (pr.Event, bool, error)
- func (db *DB) LastFetch(ctx context.Context, id string) (time.Time, error)
- func (db *DB) ListPRs(ctx context.Context, open bool) ([]pr.PR, error)
- func (db *DB) MarkFetch(ctx context.Context, id string, at time.Time) error
- func (db *DB) Meta(ctx context.Context, key string) (string, error)
- func (db *DB) MetaPrefixed(ctx context.Context, prefix string) (map[string]string, error)
- func (db *DB) OnChange(f func(Change))
- func (db *DB) Override(ctx context.Context, ref pr.Ref) (pr.Override, error)
- func (db *DB) PR(ctx context.Context, ref pr.Ref) (pr.PR, bool, error)
- func (db *DB) PRs(ctx context.Context, refs []pr.Ref) (map[pr.Ref]pr.PR, error)
- func (db *DB) RecordEvents(ctx context.Context, evs []pr.Event) error
- func (db *DB) ReplaceWorkspaces(ctx context.Context, links map[pr.Ref]pr.Workspace) error
- func (db *DB) Retain(ctx context.Context, endedBefore, fetchesBefore time.Time) ([]pr.Ref, error)
- func (db *DB) SaveDetail(ctx context.Context, ref pr.Ref, d Detail) error
- func (db *DB) SaveSnapshots(ctx context.Context, snaps []Snapshot, seenAt time.Time) (map[pr.Ref]int, error)
- func (db *DB) SeeRefs(ctx context.Context, refs []pr.Ref, at time.Time) error
- func (db *DB) Seen(ctx context.Context) (map[pr.Ref]time.Time, error)
- func (db *DB) SetAdopted(ctx context.Context, ref pr.Ref) error
- func (db *DB) SetMeta(ctx context.Context, key, value string) error
- func (db *DB) SetMetas(ctx context.Context, kv map[string]string) error
- func (db *DB) SetReasons(ctx context.Context, ref pr.Ref, reasons []string) error
- func (db *DB) SetTracked(ctx context.Context, ref pr.Ref, tracked bool) (changed bool, err error)
- func (db *DB) SetViewer(ctx context.Context, login string) error
- func (db *DB) SetWorkspace(ctx context.Context, ref pr.Ref, ws pr.Workspace) error
- func (db *DB) StoredFacts(ctx context.Context, refs []pr.Ref) (map[pr.Ref]StoredFacts, error)
- func (db *DB) TouchStubs(ctx context.Context, stubs []Stub, seenAt time.Time) error
- func (db *DB) Track(ctx context.Context, ref pr.Ref, tracked bool, at time.Time, data string) (changed bool, err error)
- func (db *DB) Tracked(ctx context.Context) ([]pr.Ref, error)
- func (db *DB) UpsertPR(ctx context.Context, p pr.PR) error
- func (db *DB) UseClock(now func() time.Time)
- func (db *DB) UseHost(h Host)
- func (db *DB) Viewer(ctx context.Context) (string, error)
- func (db *DB) Write(ctx context.Context, fn func(tx *Tx) error) (Change, error)
- type Detail
- type Host
- type Snapshot
- type StoredFacts
- type Stub
- type Tx
Constants ¶
const DetailVersion = 2
DetailVersion is the shape of Detail this release reads; a stored detail of another version is read again by the next fast run.
const TimeLayout = "2006-01-02T15:04:05.000000000Z"
TimeLayout is how the store writes a time, the host's layout, so an imported time reads and its text sorts as the store's own.
const ViewerKey = "viewer:" + "github"
ViewerKey is the meta key of the viewer's login, as the host's store kept it before the plugin had a store.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Change ¶
Change is what one write transaction changed: the pull requests whose reported facts it moved.
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
DB is the plugin's store. Every write runs under one lock, and each commit that changed pull requests is heard by the OnChange listeners, in commit order.
func Open ¶
Open opens dir's store, creating it with the plugin's schema, and imports the import.db the host's store migration exported once.
func (*DB) DetailStamps ¶
DetailStamps are the version and read time of each ref's stored detail, without its body.
func (*DB) Details ¶
Details returns the stored detail of each ref that has one, one query per 500 refs.
func (*DB) HostEvents ¶
func (db *DB) HostEvents(ctx context.Context, refs []pr.Ref, since time.Time, kinds ...string) ([]pr.Event, error)
HostEvents reads the host's events of refs of kinds, every kind when empty, at or after since, oldest first.
func (*DB) ListPRs ¶
ListPRs reads every stored pull request, or the open ones, the most recently updated first.
func (*DB) MarkFetch ¶
MarkFetch records a fetch of workspace id at at, which changes no reported fact.
func (*DB) MetaPrefixed ¶
MetaPrefixed is every meta value whose key starts with prefix, by key.
func (*DB) RecordEvents ¶
RecordEvents records evs on the host. A keyed event is kept once per pull request, kind and key.
func (*DB) ReplaceWorkspaces ¶
ReplaceWorkspaces makes links the set of linked pull requests in one transaction, so readers never see the links blank. It writes only the links that differ from the stored ones, recording on the host first the followed or unfollowed events of the scope flips.
func (*DB) Retain ¶
Retain drops what the host's retention ends: every row of a pull request merged or closed before endedBefore, and the fetches before fetchesBefore, in one transaction. It returns the pull requests it dropped, which no later report names.
func (*DB) SaveDetail ¶
SaveDetail stores d as ref's detail unless it equals the stored one.
func (*DB) SaveSnapshots ¶
func (db *DB) SaveSnapshots(ctx context.Context, snaps []Snapshot, seenAt time.Time) (map[pr.Ref]int, error)
SaveSnapshots stores snaps. The events, host data, go to the host first: the timeline events the host does not hold yet, the merges that fill a stored one, and a followed or unfollowed event for each pull request whose scope flips, derived from a read of the stored rows. Then one write transaction rewrites a row only when a column differs, records every ref as seen, and writes a detail only when it differs from the stored one. A write that fails after the host took the events leaves the rows as they were, so the next save derives the same events again and the host keeps each once. seenAt dates the sighting, a new conflict, the flips and a detail without ReadAt. It returns the events added per ref that gained any.
func (*DB) SeeRefs ¶
SeeRefs records that a search or a read returned refs at at. A sighting changes no reported fact.
func (*DB) SetAdopted ¶
SetAdopted marks ref taken over, writing that column alone.
func (*DB) SetReasons ¶
SetReasons replaces ref's follow reasons, keeping ReasonTracked while its override tracks it, and recording on the host first the followed or unfollowed event of a scope flip.
func (*DB) SetTracked ¶
SetTracked tracks or untracks ref, keeping its reasons in step and recording on the host first the followed or unfollowed event of a scope flip; changed says the override moved.
func (*DB) SetWorkspace ¶
SetWorkspace links ref to ws, recording on the host first the followed or unfollowed event of a scope flip.
func (*DB) StoredFacts ¶
StoredFacts reads the facts of refs: the stored pull requests, then their pushes and unfilled merges from the host's events.
func (*DB) TouchStubs ¶
TouchStubs refreshes the review requests, the review decision, the sighting and the mergeable state of pull requests a search returned unchanged, in one transaction. A closed pull request's mergeable state is not followed.
func (*DB) Track ¶
func (db *DB) Track(ctx context.Context, ref pr.Ref, tracked bool, at time.Time, data string) (changed bool, err error)
Track tracks or untracks ref, recording the tracked or untracked event of the move on the host, at at with data, before its write, as a scope flip is: a move the host refused leaves the row as it was, and a retry after a write that failed finds the host's last event of the kind it records and records none. Changed says the override moved.
func (*DB) UseHost ¶
UseHost makes h the host the store records its events to and reads them from; a store with no host refuses every write that derives an event.
type Detail ¶
type Detail struct {
Version int `json:"-"`
ReadAt time.Time `json:"-"`
AuthorAssociation string
Visibility string // the repository's: public, private or internal
Labels []string
Commits []pr.Commit // the newest 50, oldest first
Reviews []pr.Review // the newest 100, oldest first; HasContent set, ByViewer unset
LatestReviews []pr.Review // latestReviews(first: 20)
NewestChangesRequestOid string
Comments []pr.Comment // the newest 100, oldest first
Checks []pr.Check // the head's contexts, first 50
ThreadsTotal int
// OpenThreads holds the unresolved threads among the newest 50 when
// ThreadsRead: read for a pull request with ThreadsTotal > 0 the viewer
// authored or develops in a workspace, and known empty when ThreadsTotal
// is 0.
OpenThreads []pr.Thread
ThreadsRead bool
}
Detail is what deciding on a pull request reads beyond its row: the collector's full read, stored as GitHub returned it.
type Host ¶
type Host interface {
RecordEvents(ctx context.Context, events []src.Event) error
Events(ctx context.Context, q src.EventQuery) ([]src.Event, error)
}
Host is where the events of the store's pull requests live: the host's event log, written and read through the broker.
type Snapshot ¶
type Snapshot struct {
PR pr.PR // Reasons are merged with the stored ones; LastSeenAt and Workspace are ignored
Events []pr.Event // the timeline; those the host holds already are ignored
Merges []pr.Event // merged events that fill a stored one lacking the merger or the commit
Detail *Detail // nil keeps the stored one
}
Snapshot is one pull request as GitHub returned it, ready to store.
type StoredFacts ¶
type StoredFacts struct {
PR pr.PR // zero when not Found
Found bool
Pushes map[string]time.Time // push key -> at
UnfilledMerges []time.Time // merged events lacking the merger or the commit
}
StoredFacts is what storing a fresh GitHub snapshot needs of the stored one.