engine

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package engine keeps the local cache in step with GitHub: it fetches changes, queues the user's edits in the outbox, and sends them.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SortIssues

func SortIssues(issues []issue.Issue)

SortIssues orders issues by most recently updated first.

Types

type Draft

type Draft struct {
	Repo      string
	Title     string
	Body      string
	Type      issue.Type
	Status    issue.Status
	Labels    []string
	Assignees []string
}

Draft describes a new issue.

type Engine

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

Engine coordinates the GitHub client, the cache, and the outbox. Its methods are safe to call from multiple goroutines.

func New

func New(client *gh.Client, st *store.Store, conv issue.Convention) *Engine

func (*Engine) Apply

func (e *Engine) Apply(i issue.Issue, ch issue.Change) ([]store.Op, error)

Apply queues the label and state edits in ch.

func (*Engine) Assign

func (e *Engine) Assign(i issue.Issue, add, remove []string) ([]store.Op, error)

Assign adds and removes assignees.

func (*Engine) CachedComments

func (e *Engine) CachedComments(i issue.Issue) ([]store.Comment, bool)

CachedComments returns cached comments without contacting GitHub, and whether they are current.

func (*Engine) CachedMe

func (e *Engine) CachedMe() string

CachedMe returns the last known login without contacting GitHub.

func (*Engine) Comment

func (e *Engine) Comment(i issue.Issue, body string) ([]store.Op, error)

Comment queues a new comment.

func (*Engine) Comments

func (e *Engine) Comments(ctx context.Context, i issue.Issue) ([]store.Comment, error)

Comments returns an issue's comments, from the cache when the issue hasn't changed on GitHub since they were fetched.

func (*Engine) Convention

func (e *Engine) Convention() issue.Convention

func (*Engine) Create

func (e *Engine) Create(d Draft) ([]store.Op, error)

Create queues a new issue. Statuses that need a closed issue are queued as a follow-up change.

func (*Engine) Discard

func (e *Engine) Discard(op store.Op) error

Discard drops a queued op.

func (*Engine) Edit

func (e *Engine) Edit(i issue.Issue, title, body string) ([]store.Op, error)

Edit queues a title and/or body change. Unchanged fields are left alone.

func (*Engine) Flush

func (e *Engine) Flush(ctx context.Context) (FlushResult, error)

Flush sends queued changes in order. Changes to an issue wait behind any earlier change to the same issue that couldn't be sent. Flushing stops at the first network failure; the rest is retried on the next flush.

func (*Engine) FlushOnly

func (e *Engine) FlushOnly(ctx context.Context, ids ...string) (FlushResult, error)

FlushOnly sends only the ops with the given IDs (and nothing else).

func (*Engine) KeepMine

func (e *Engine) KeepMine(op store.Op) error

KeepMine resolves a conflict by overwriting GitHub's version with the user's edit.

func (*Engine) Me

func (e *Engine) Me(ctx context.Context) string

Me returns the authenticated user's login, from GitHub when possible and from the cache otherwise.

func (*Engine) Online

func (e *Engine) Online() bool

Online reports whether the engine has a GitHub client. Without one it can still read the cache and queue changes.

func (*Engine) Refresh

func (e *Engine) Refresh(ctx context.Context, repo string, full bool) (RefreshResult, error)

Refresh fetches issues changed since the last refresh of repo. With full set, or when the last full check is old, it fetches the complete list and also drops issues that were deleted or transferred away.

func (*Engine) RefreshAll

func (e *Engine) RefreshAll(ctx context.Context, repos []string, full bool) ([]RefreshResult, error)

RefreshAll refreshes repos concurrently and returns the first error. full is passed on to Refresh.

func (*Engine) Restore

func (e *Engine) Restore(opIDs []string, before, current issue.Issue) ([]store.Op, error)

Restore undoes earlier changes to an issue: changes still in the outbox are discarded, and anything already sent is reverted by queueing the opposite change. before is the issue as it was, current as it is now.

func (*Engine) Retry

func (e *Engine) Retry(op store.Op) error

Retry clears a held op's error so the next flush tries it again.

func (*Engine) SetStatus

func (e *Engine) SetStatus(i issue.Issue, s issue.Status) ([]store.Op, error)

func (*Engine) SetType

func (e *Engine) SetType(i issue.Issue, t issue.Type) ([]store.Op, error)

func (*Engine) Snapshot

func (e *Engine) Snapshot(repos []string) (Snapshot, error)

Snapshot loads the cached issues of repos with pending changes applied.

func (*Engine) Store

func (e *Engine) Store() *store.Store

func (*Engine) Submit

func (e *Engine) Submit(op store.Op) (store.Op, error)

Submit queues a change and returns it with its ID.

func (*Engine) TakeTheirs

func (e *Engine) TakeTheirs(op store.Op) error

TakeTheirs resolves a conflict by dropping the user's edit.

type FlushResult

type FlushResult struct {
	Sent    int
	Held    int
	Offline bool
	// Dropped counts changes discarded because their issue was deleted.
	Dropped int
	// Created maps local IDs to the issue numbers GitHub assigned.
	Created map[string]int
	// Err is the most recent failure, for display.
	Err error
}

FlushResult summarizes a flush.

type RefreshResult

type RefreshResult struct {
	Repo string
	// Changed counts new, updated, and removed issues.
	Changed int
	// Removed counts issues that no longer exist on GitHub.
	Removed int
}

RefreshResult describes what a refresh found.

type Snapshot

type Snapshot struct {
	Issues []issue.Issue
	// Pending maps issue keys to the changes still waiting to be sent.
	Pending map[string][]store.Op
	// Labels lists every known label per repo.
	Labels map[string][]gh.Label
	// FetchedAt is the time of each repo's last successful refresh.
	FetchedAt map[string]time.Time
}

Snapshot is the issues triage should display: the cache with every pending change applied on top.

func (Snapshot) LastFetched

func (s Snapshot) LastFetched() time.Time

LastFetched returns the oldest refresh time across repos, or zero if a repo has never been fetched.

func (Snapshot) PendingCount

func (s Snapshot) PendingCount() (total, held int)

PendingCount returns how many ops are queued, and how many of those need the user's attention.

Jump to

Keyboard shortcuts

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