ghthreads

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: MIT Imports: 27 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 ghthreads mirrors the user's GitHub notifications, which GitHub's REST API calls threads, as the web inbox lists them (read and unread, not done), in the gh_threads table it owns, one row per account and thread, so the window counts and lists them without asking GitHub, and clears them by the user's rules (clear.go): it marks a thread done, or read, once the work behind it is finished. Its writes, each through the GitHub client's chore lane, mark a thread done or read: a clear, which it makes none of until the user turns clearing on or clears one by hand, and the panel's own clicks (mark.go), opening a notification, which marks it read, and its Done.

A pass reads them, never two at once. With reading turned off (threadrules' Read), a pass sends nothing and borrows no token. Otherwise it learns the token's account (one GraphQL point per new token) and lists the notifications: page 1 is sent with the ETag its last answer carried, and GitHub's 304 Not Modified costs nothing and ends the listing; a 200 reads on, page by page, until a page whose oldest thread is no newer than the newest the last pass saw (the high-water mark). A 304 says nothing of the later pages, so a thread read or marked done there shows only on a walk of every page: at the first pass after the app starts, every FullWalkEvery, after the account changes, and once reading comes back on. A walk reads at most github.MaxThreadPages pages, the newest MaxThreads threads. A 200 deletes the account's rows it didn't list within the span it read, done on GitHub: every one for a walk, and those updated after the oldest thread on its last page for a pass that stopped at the mark. A pass stores what it read in one transaction at its end, so one that fails partway stores nothing, and never an ETag or a high-water mark the pages it meant to read don't back.

GitHub refusing the listing (github.NotificationsRefused: 403 or 404, as for a fine-grained token) is remembered, and no listing is sent again for RefusedFor, unless CheckNow asks. Then the pass checks the state of the pull requests and issues its threads are about, in one batched request: those never checked, those whose thread changed since, and those not known finished that were checked StateRecheck ago. Releases, discussions, check suites, and the other subjects are mirrored and counted, never checked.

The Syncer runs a pass as often as the notifications' refresh setting says, never sooner than GitHub's X-Poll-Interval asks, and the window reads the mirror through Snapshot (the counts, the newest unread, and the clears) and List (every thread, read and unread, for the Notifications page), neither of which asks GitHub anything. Each pass that changes what either shows emits event.GHThreadsUpdated: Snapshot holds a fingerprint of every thread List shows, so a change past the newest unread counts too. A pass then decides which threads clear, queues them in the gh_thread_clears ledger, and sends the ones due; the Syncer also runs a pass when the inbox tells of something the user finished (Settler), when the rules change, and when a queued clear comes due.

Index

Constants

View Source
const (
	// StateFreshFor is how recently GitHub's state of an item must have been read for a
	// merge or a close it says to clear a thread: never a guess, and an item reopened
	// stops counting once its state is read again.
	StateFreshFor = time.Hour

	// MinHold is the least time a clear chosen by the user's own action in the app waits
	// before it is sent, and HoldPad the time it waits past the toast that offers its
	// Undo (Hold).
	MinHold = 15 * time.Second
	HoldPad = 3 * time.Second

	// FirstCap is the most clears the first pass after clearing turns on, or after the
	// rules change, queues by itself, and Cap the most any later pass does: more wait for
	// the user to review them.
	FirstCap = 25
	Cap      = 150

	// QueuedFor is how long a clear stays queued before it is decided again instead of
	// sent.
	QueuedFor = 24 * time.Hour

	// MaxAttempts is how many failed sends make a clear failed, and FailedRetry how long
	// after a failed send the next is tried.
	MaxAttempts = 3
	FailedRetry = time.Minute

	// MinNudgeListing is the least time since the last listing after which a nudged run
	// lists first, when GitHub's poll interval asks for less.
	MinNudgeListing = time.Minute

	// MomentsKept is how long a moment is kept after the app heard of it, and ClearsKept
	// how long a clear is kept after it settled.
	MomentsKept = 30 * 24 * time.Hour
	ClearsKept  = 30 * 24 * time.Hour

	// MaxRecent is how many settled clears Snapshot lists.
	MaxRecent = 50

	// MaxCommentChecks is the most latest-comment reads one pass sends to learn who acted
	// on the threads held back; the rest wait for the next pass.
	MaxCommentChecks = 150
)
View Source
const (
	// SkipNone is no reason: the clear wasn't skipped.
	SkipNone SkipReason = ""

	// SkipOff is reading the notifications, or clearing on its own, turned off.
	SkipOff = SkipReason(threadrules.ReasonOff)

	// SkipRuleOff is the trigger turned off, or a watched repository's thread left alone.
	SkipRuleOff = SkipReason(threadrules.ReasonRuleOff)

	// SkipStillOpen is an item GitHub no longer says is finished: reopened.
	SkipStillOpen = SkipReason(threadrules.ReasonStillOpen)

	// SkipNewActivity is a thread that changed after the moment, which the user may not
	// have seen.
	SkipNewActivity = SkipReason(threadrules.ReasonNewActivity)

	// SkipAlreadyRead is a thread already read while clearing marks one read.
	SkipAlreadyRead = SkipReason(threadrules.ReasonAlreadyRead)

	// SkipNotItem is a thread about neither a pull request nor an issue.
	SkipNotItem = SkipReason(threadrules.ReasonNotItem)

	// SkipNotListed is a thread the mirror no longer lists: done elsewhere, or dropped for
	// one pass by a listing that raced its update. A later pass queues it again if it
	// still clears.
	SkipNotListed SkipReason = "not_listed"

	// SkipChanged is a thread updated since the clear was decided: it was decided again.
	SkipChanged SkipReason = "changed"

	// SkipStale is a clear queued more than QueuedFor ago: it was decided again.
	SkipStale SkipReason = "stale"

	// SkipKept is a thread the user kept (Undo) at its update: it waits until it moves.
	SkipKept SkipReason = "kept"

	// SkipFailed is a thread whose clear failed MaxAttempts times at its update: it waits
	// until it moves, or the user clears it by hand.
	SkipFailed SkipReason = "failed"
)

The reasons a clear is skipped. Those threadrules.Decide gives keep its words.

View Source
const (
	// FullWalkEvery is how long after a walk of every page another is due.
	FullWalkEvery = 6 * time.Hour

	// RefusedFor is how long after GitHub refused the listing it is sent again, unless the
	// user asks first (CheckNow).
	RefusedFor = 6 * time.Hour

	// StateRecheck is how long a thread's item, not known to be merged or closed, goes
	// before its state is checked again, though its thread didn't change: how a merge on a
	// thread that didn't move is caught.
	StateRecheck = 30 * time.Minute

	// OtherAccountsKept is how long the threads of an account other than the one read last
	// are kept, unseen, before a walk of every page drops them.
	OtherAccountsKept = 30 * 24 * time.Hour

	// MaxUnread is how many unread threads Snapshot lists, the newest first.
	MaxUnread = 20

	// MaxThreads is the most threads the mirror holds: every page a walk reads, full.
	MaxThreads = github.MaxThreadPages * github.ThreadsPerPage
)
View Source
const (
	// FollowUpFor is how long after the inbox told of an item merged or closed the Syncer
	// keeps looking for its thread coming back.
	FollowUpFor = 10 * time.Minute

	// FollowUpEvery is how often a follow-up run lists the notifications and decides the
	// threads followed up, while any is: never sooner than GitHub's poll interval, as a
	// nudged run lists only once the mirror is that old.
	FollowUpEvery = 2 * time.Minute
)

The follow-up of an item the inbox told of merged or closed. Its thread is cleared as soon as the state says so, but GitHub tells of the merge or the close itself a little after it, and of what follows it (a bot's comment, a release noted), and each brings a thread marked done back to the user's inbox on GitHub. A timed pass, every few minutes, and GitHub's own lag on the listing would leave it there for ten minutes or more, which is how long the user would see a notification of something they know is finished.

View Source
const DefaultInterval = 5 * time.Minute

DefaultInterval is how often the Syncer runs a pass when it is given no interval: the inbox's default refresh.

View Source
const KeySync = "ghthreads.sync"

KeySync is the preference that holds the state of the passes, as JSON: whose notifications the last pass read, where the next one starts, and how the last one went. Only this package writes it.

View Source
const (
	// MaxPaceWait is the longest a mark the user clicked waits, in all, for the chore lane's
	// pace before it gives up and says so; a wait the lane asks for past what is left fails
	// at once.
	MaxPaceWait = 5 * time.Second
)

Variables

This section is empty.

Functions

func Hold

func Hold(toastSeconds int) time.Duration

Hold is how long a clear chosen by the user's own action in the app waits before it is sent, so its toast's Undo can keep it, for toasts that stay toastSeconds: the toast's time and HoldPad more, never less than MinHold.

Types

type Access

type Access string

Access is whether GitHub lets the token read the user's notifications.

const (
	// AccessUnchecked is no listing answered yet, for this account.
	AccessUnchecked Access = "unchecked"

	// AccessOK is GitHub answering the last listing.
	AccessOK Access = "ok"

	// AccessRefused is GitHub refusing the last listing (403 or 404), as it does a
	// fine-grained token: none is sent again for RefusedFor, unless CheckNow asks.
	AccessRefused Access = "refused"
)

The answers about access.

type ClearState

type ClearState string

ClearState is where a clear stands in the ledger.

const (
	// ClearQueued is a clear waiting to be sent.
	ClearQueued ClearState = "queued"

	// ClearSent is a clear GitHub took, or one GitHub no longer had the thread of.
	ClearSent ClearState = "sent"

	// ClearKept is a clear the user undid (Keep), or one a restore after a dismissal took
	// back.
	ClearKept ClearState = "kept"

	// ClearFailed is a clear whose sends failed MaxAttempts times.
	ClearFailed ClearState = "failed"

	// ClearSkipped is a clear not sent, for its SkipReason.
	ClearSkipped ClearState = "skipped"
)

The states of a clear.

type Client

type Client interface {
	FetchViewer(ctx context.Context, tok github.Token) (string, error)
	ListThreads(ctx context.Context, tok github.Token, q github.ThreadQuery) (*github.ThreadPage, error)
	FetchItemStates(ctx context.Context, tok github.Token, refs []item.Ref) (map[string]github.ItemState, error)
	FetchLatestComment(ctx context.Context, tok github.Token, rawURL string) (*github.CommentAuthor, error)
	ParseSubject(raw string) (item.Ref, bool)
	MarkThreadDone(ctx context.Context, tok github.Token, id int64) error
	MarkThreadRead(ctx context.Context, tok github.Token, id int64) error
}

Client is what a pass asks GitHub: the token's account, a page of the notifications, the state of pull requests and issues, and who wrote a thread's latest comment; and what it sends: a thread marked done or read, through the chore lane. ParseSubject reads an API URL GitHub gave and sends nothing. *github.Client implements it.

type Config

type Config struct {
	// Pool is the database, which holds the threads, the ledger of clears, and the state of
	// the passes.
	Pool *sql.DB

	// Tokens lends the token a pass reads and clears with; a token GitHub refuses is
	// borrowed again once (github.WithToken).
	Tokens github.Tokens
	Client Client

	// Rules says whether the user's notifications are read at all, and when they clear.
	Rules RuleSource

	// Holds says how long the window's toasts stay, which the Undo hold follows; nil, or
	// one that can't be read, holds MinHold.
	Holds HoldSource

	// Clock stamps the passes and the rows; nil is the system clock. The Syncer's waits
	// run on the real clock.
	Clock clock.Clock

	// Events hears event.GHThreadsUpdated; nil drops it.
	Events event.Sink

	// Logger receives the passes' failures; nil discards them.
	Logger *slog.Logger
}

Config holds a Service's dependencies. Pool, Tokens, Client, and Rules are required.

type HoldSource

type HoldSource interface {
	ToastSeconds(ctx context.Context) (int, error)
}

HoldSource reads how long, in seconds, the window's toasts stay (the toast setting), which the Undo hold follows (Hold); core adapts the settings.

type Outcome

type Outcome struct {
	Kind OutcomeKind

	// Login is the account whose inbox lists the item.
	Login string

	// Ref names the item, its kind included.
	Ref item.Ref

	// At is when it happened: the user's click, or the review's own time.
	At time.Time
}

Outcome is what happened to one item, as the inbox tells it.

type OutcomeKind

type OutcomeKind string

OutcomeKind is what happened to an item the user finished in the app, or that the inbox saw close or leave its lists. Its values are the inbox's own, which core adapts.

const (
	// OutcomeMerged is a pull request the user merged in the app, and OutcomeClosed a pull
	// request or an issue they closed.
	OutcomeMerged OutcomeKind = "merged"
	OutcomeClosed OutcomeKind = "closed"

	// OutcomeReviewed is a pull request the user approved or requested changes of in the
	// app.
	OutcomeReviewed OutcomeKind = "reviewed"

	// OutcomeDismissed is an item the user dismissed in the app, and OutcomeRestored one
	// they brought back, which takes the dismissal's clears back.
	OutcomeDismissed OutcomeKind = "dismissed"
	OutcomeRestored  OutcomeKind = "restored"

	// OutcomeUnassigned is an item the user took themselves off the assignees of, and
	// OutcomeUnrequested a pull request they took themselves off the reviewers of.
	OutcomeUnassigned  OutcomeKind = "unassigned"
	OutcomeUnrequested OutcomeKind = "unrequested"

	// OutcomeSeenClosed is an item the inbox found merged or closed, by anyone, and
	// OutcomeUnlisted one it found in none of its lists: the item's state is checked again.
	OutcomeSeenClosed OutcomeKind = "seen_closed"
	OutcomeUnlisted   OutcomeKind = "unlisted"
)

Kinds of outcome.

type Preview

type Preview struct {
	// Reading is whether the app reads the user's notifications; off, nothing would clear.
	Reading bool `json:"reading"`

	// Auto is whether clearing on its own is on, and Action what clearing does.
	Auto   bool               `json:"auto"`
	Action threadrules.Action `json:"action"`

	// Count is how many threads would clear.
	Count int `json:"count"`

	// Repos are the threads that would clear, by repository, in the order of each one's
	// most recently updated thread.
	Repos []PreviewRepo `json:"repos"`

	// Held are the threads a moment finished but that would not clear now, by reason, in
	// the order each reason is first met.
	Held []PreviewHeld `json:"held"`
}

Preview is what clearing would do now, for the cleanup sheet and the card that first offers it: the threads that would clear, by repository, and those held back, by reason. It is decided as if clearing on its own were on, so it counts the candidates while it is off, and it takes GitHub's last word on an item's state however old it is: a pass reads a state again before it clears on it.

type PreviewHeld

type PreviewHeld struct {
	Reason  SkipReason      `json:"reason"`
	Count   int             `json:"count"`
	Threads []PreviewThread `json:"threads"`
}

PreviewHeld is the threads held back from clearing for one reason.

type PreviewRepo

type PreviewRepo struct {
	Owner   string          `json:"owner"`
	Name    string          `json:"name"`
	Threads []PreviewThread `json:"threads"`
}

PreviewRepo is one repository's threads that would clear.

type PreviewThread

type PreviewThread struct {
	// ID is GitHub's ID of the thread, which Clear takes.
	ID int64 `json:"id"`

	// Owner and Name are its repository, Kind and Number the item it is about.
	Owner  string    `json:"owner"`
	Name   string    `json:"name"`
	Kind   item.Kind `json:"kind"`
	Number int       `json:"number"`

	// Title is the item's title, Reason GitHub's reason for the thread, and Unread whether
	// it is unread.
	Title  string `json:"title"`
	Reason string `json:"reason"`
	Unread bool   `json:"unread"`

	// UpdatedAt is when it last changed on GitHub, as RFC 3339.
	UpdatedAt string `json:"updatedAt"`

	// Trigger is the moment that finished its item.
	Trigger threadrules.Trigger `json:"trigger"`
}

PreviewThread is one thread in a Preview.

type QueuedClear

type QueuedClear struct {
	// ID is the clear's, which Keep takes, and ThreadID GitHub's ID of the thread.
	ID       int64 `json:"id"`
	ThreadID int64 `json:"threadId"`

	// Owner and Name are the thread's repository, Kind and Number its item, and Title the
	// item's title.
	Owner  string    `json:"owner"`
	Name   string    `json:"name"`
	Kind   item.Kind `json:"kind"`
	Number int       `json:"number"`
	Title  string    `json:"title"`

	// SendAfter is when it may be sent, as RFC 3339: the Undo hold's end, or when it was
	// queued.
	SendAfter string `json:"sendAfter"`

	// Trigger is the moment that chose it, and Action what it does.
	Trigger threadrules.Trigger `json:"trigger"`
	Action  threadrules.Action  `json:"action"`
}

QueuedClear is a clear waiting to be sent.

type RuleSource

type RuleSource interface {
	ThreadRules(ctx context.Context) (threadrules.Rules, error)
}

RuleSource reads the user's rules for their GitHub notifications, as stored now; core adapts the preferences settings writes.

type Service

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

Service mirrors the user's GitHub notifications and serves the window what it holds. It is safe for concurrent use.

func NewService

func NewService(cfg Config) *Service

NewService returns a Service over cfg.

func (*Service) CheckNow

func (s *Service) CheckNow(ctx context.Context) (Snapshot, error)

CheckNow runs a pass now, once any pass already running has ended, then returns the Snapshot: the window's Check again, and its first look once reading is turned on. It sends the listing even while a refused one waits RefusedFor, and whatever GitHub's poll interval says; with reading turned off, it sends nothing. A pass that fails is told in the Snapshot's status, which the window shows, so only a call the window gave up on, or a Snapshot that can't be read, is an error.

func (*Service) Clear

func (s *Service) Clear(ctx context.Context, threadIDs []int64) (Snapshot, error)

Clear clears the threads with threadIDs by the user's own hand, the cleanup sheet's button: each one the mirror lists for the account the last pass read is queued to go at once, with no hold and whether clearing on its own is on or off, and a clear already queued for it goes at once instead. A thread about neither a pull request nor an issue, one already read while clearing marks one read, and any while reading is off are left alone. It returns the Snapshot, whose Queued lists them until they are sent.

func (*Service) ClearItem

func (s *Service) ClearItem(ctx context.Context, owner, name string, number int) (Snapshot, error)

ClearItem clears, by the user's own hand, every thread about the pull request or issue owner/name#number that the mirror lists for the account the last pass read, as Clear does: the card's menu action.

func (*Service) ClearItemThreads added in v0.4.0

func (s *Service) ClearItemThreads(ctx context.Context, owner, name string, number int) (int, error)

ClearItemThreads clears the threads about the pull request or issue owner/name#number as ClearItem does, and returns how many clears it queued: none while reading is off, before a pass read the account, or when the mirror lists no thread about it that the rules don't leave alone. Autopilot's Mark the GitHub notification done runs it, as the card's menu runs ClearItem.

func (*Service) Keep

func (s *Service) Keep(ctx context.Context, clearIDs []int64) (Snapshot, error)

Keep takes back the queued clears with clearIDs, the toast's Undo: each one still queued is kept, and never sent. A clear kept stays kept: its thread isn't queued again on its own until it changes on GitHub. It returns the Snapshot.

func (*Service) List

func (s *Service) List(ctx context.Context) (ThreadList, error)

List returns every thread the mirror holds for the account the last pass read, read and unread, the most recently updated first, with the Snapshot's status, from the database alone: it never asks GitHub. With reading turned off, or before a pass read an account, its status says so and its list is empty.

func (*Service) MarkDone

func (s *Service) MarkDone(ctx context.Context, ids []int64) (Snapshot, error)

MarkDone marks the threads with ids done on GitHub at the user's click, the panel's Done, which takes them out of the user's inbox there: any thread the mirror lists for the account the last pass read, whatever its subject and whatever the rules say clearing does, and, for one about a pull request or an issue, every thread the mirror lists about that item, since the panel's line stands for the item. Each one GitHub took, or no longer had, leaves the mirror, and a clear queued for it is settled. With reading off, or before a pass read an account, it sends nothing. It returns the Snapshot.

func (*Service) MarkRead

func (s *Service) MarkRead(ctx context.Context, ids []int64) (Snapshot, error)

MarkRead marks the threads with ids read on GitHub as the user opens them from the panel, as GitHub's own inbox does, and in the mirror: any unread thread it lists for the account the last pass read, whatever its subject, and, for one about a pull request or an issue, every unread thread it lists about that item. With reading off, or before a pass read an account, it sends nothing. It returns the Snapshot.

func (*Service) Preview

func (s *Service) Preview(ctx context.Context) (Preview, error)

Preview returns what clearing would do now, from the database alone: it never asks GitHub.

func (*Service) Snapshot

func (s *Service) Snapshot(ctx context.Context) (Snapshot, error)

Snapshot returns what the window shows of the user's GitHub notifications, for the account the last pass read, from the database alone: it never asks GitHub. With reading turned off, its status says so and its lists are empty.

type SettledClear

type SettledClear struct {
	// ID is the clear's, and ThreadID GitHub's ID of the thread.
	ID       int64 `json:"id"`
	ThreadID int64 `json:"threadId"`

	// Owner and Name are the thread's repository, Kind and Number its item, and Title the
	// item's title.
	Owner  string    `json:"owner"`
	Name   string    `json:"name"`
	Kind   item.Kind `json:"kind"`
	Number int       `json:"number"`
	Title  string    `json:"title"`

	// Trigger is the moment that chose it, Action what it did or was to do, and State how
	// it settled.
	Trigger threadrules.Trigger `json:"trigger"`
	Action  threadrules.Action  `json:"action"`
	State   ClearState          `json:"state"`

	// At is when it settled, as RFC 3339.
	At string `json:"at"`

	// Error is the last failure, in a sentence, for a failed clear, and Reason why a
	// skipped one was.
	Error  string     `json:"error"`
	Reason SkipReason `json:"reason"`
}

SettledClear is a clear that left the queue.

type Settler

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

Settler hears what the user finished in the app from the inbox, and records the moments that clear the threads about it. It is the inbox's OutcomeSink, wired by core, and is never bound to the window.

func NewSettler

func NewSettler(svc *Service) *Settler

NewSettler returns the Settler of svc.

func (*Settler) Settle

func (st *Settler) Settle(ctx context.Context, outcomes []Outcome)

Settle records outcomes in one transaction, then nudges the Syncer to decide the threads about their items soon, follows up the items merged or closed, or that left the inbox's lists (see FollowUpFor), and returns without waiting for it. A merge or a close records its moment, and GitHub's state of the item as it answered the user's merge or close (merged or closed then, read now), so the moment needs no state check; a review that decides, a dismissal, and taking oneself off record their moments; a restore takes the dismissal's moment back, and keeps its queued clears; and an item the inbox saw close or leave its lists has its state checked first. A failure is logged: the inbox's work is done either way.

type SkipReason

type SkipReason string

SkipReason is why a clear was skipped, or a thread held back from clearing.

type Snapshot

type Snapshot struct {
	// Status is how reading the notifications goes, and how many there are.
	Status Status `json:"status"`

	// Unread are the newest MaxUnread unread threads, whatever their subject, the newest
	// first.
	Unread []Thread `json:"unread"`

	// Queued are the clears waiting to be sent, the one due first first, each of which Keep
	// takes back.
	Queued []QueuedClear `json:"queued"`

	// Backlog is how many clears the last pass held back, more than clear on their own, for
	// the user to review (Preview, then Clear); 0 when none waits.
	Backlog int `json:"backlog"`

	// Recent are the latest MaxRecent clears that settled, the latest first.
	Recent []SettledClear `json:"recent"`
	// contains filtered or unexported fields
}

Snapshot is what the window shows of the user's GitHub notifications. No URL GitHub gave is in it: the window builds a link to an item from its repository and number.

type Status

type Status struct {
	// Reading is whether the app reads them (the Read rule). Off, the lists are empty and
	// the counts zero.
	Reading bool `json:"reading"`

	// Account is the login whose notifications the last pass read, "" before the first.
	Account string `json:"account"`

	// Access is whether GitHub lets the token read them.
	Access Access `json:"access"`

	// LastPassAt is when GitHub last answered a listing, and LastFullWalkAt when a listing
	// last read every page, as RFC 3339, "" for never.
	LastPassAt     string `json:"lastPassAt"`
	LastFullWalkAt string `json:"lastFullWalkAt"`

	// LastError is what went wrong with the last pass, in a sentence, "" when it went
	// through.
	LastError string `json:"lastError"`

	// AskAgainAt is when a listing GitHub refused is sent again, as RFC 3339, "" unless
	// Access is AccessRefused.
	AskAgainAt string `json:"askAgainAt"`

	// Count is how many notifications the user's GitHub inbox holds (read and unread, not
	// done), and Unread how many of them are unread.
	Count  int `json:"count"`
	Unread int `json:"unread"`

	// Truncated is whether GitHub lists more than the app reads: it holds the newest
	// MaxThreads only.
	Truncated bool `json:"truncated"`
}

Status is how reading the user's GitHub notifications goes, for the account the last pass read, and how many there are.

type Syncer

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

Syncer runs a pass when it starts, then again as often as its every says (the notifications' refresh setting), but never sooner than GitHub's poll interval asks, from the end of the last pass, its own or CheckNow's. Wake makes it read the interval again at once. Between passes it runs what it is nudged to at once (what the inbox tells the Settler, and the rules changing, RulesChanged), a follow-up run of the items merged or closed every FollowUpEvery for FollowUpFor, and a run that sends the queued clears as soon as the next may go, so an Undo hold of seconds is never stretched into the interval's wait. A pass that fails is logged, and one that panics is recovered and logged, so the Syncer keeps going until its context is canceled.

func NewSyncer

func NewSyncer(svc *Service, every periodic.Every, logger *slog.Logger) *Syncer

NewSyncer returns a Syncer that runs svc's passes as often as every says, logging failures to logger. A nil every runs one every DefaultInterval, and a nil logger discards the failures.

func (*Syncer) RulesChanged

func (s *Syncer) RulesChanged()

RulesChanged has the Syncer decide every thread again soon, under the rules as they are now, as when the user changed them: clearing turned off skips the queued clears, and turned on, or changed, clears what it now finds finished, FirstCap at most.

func (*Syncer) Run

func (s *Syncer) Run(ctx context.Context)

Run runs a pass now, then whenever one is due, until ctx is canceled, and returns once the pass running has returned. While every says zero or less, no timed pass runs, the first included, until a wake finds it positive; what it is nudged to, and the sends, run all the same.

func (*Syncer) Wake

func (s *Syncer) Wake()

Wake has the Syncer read how often to run a pass again, as when the user changed it.

type Thread

type Thread struct {
	// ID is GitHub's ID of the thread.
	ID int64 `json:"id"`

	// Owner and Name are its repository, "" when GitHub named none.
	Owner string `json:"owner"`
	Name  string `json:"name"`

	// Kind and Number are the pull request or issue it is about, "" and 0 for any other
	// subject.
	Kind   item.Kind `json:"kind"`
	Number int       `json:"number"`

	// SubjectType is what it is about, in GitHub's words (PullRequest, Issue, Release,
	// CheckSuite, Discussion, ...), and Title the subject's title.
	SubjectType string `json:"subjectType"`
	Title       string `json:"title"`

	// Reason is why the user got it, in GitHub's words.
	Reason string `json:"reason"`

	// UpdatedAt is when it last changed on GitHub, as RFC 3339.
	UpdatedAt string `json:"updatedAt"`

	// Unread is whether it is unread on GitHub.
	Unread bool `json:"unread"`

	// State is its pull request's or issue's state as the last state check read it,
	// StateUnknown until one did and for any other subject.
	State threadrules.State `json:"state"`
}

Thread is one notification.

type ThreadList

type ThreadList struct {
	// Status is the Snapshot's: how reading goes, and how many there are.
	Status Status `json:"status"`

	// Threads are every one, the most recently updated first.
	Threads []Thread `json:"threads"`
}

ThreadList is every thread the mirror holds for the account the last pass read, read and unread, as the Notifications page lists them. No URL GitHub gave is in it either.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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