store

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: 14 Imported by: 0

Documentation

Overview

Package store persists cached GitHub data and the outbox of changes that haven't reached GitHub yet.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewID

func NewID() string

NewID returns a sortable unique ID.

Types

type Comment

type Comment struct {
	Author    string    `json:"author"`
	Body      string    `json:"body"`
	CreatedAt time.Time `json:"created_at"`
	URL       string    `json:"url,omitempty"`
}

Comment is a cached issue comment.

type CommentCache

type CommentCache struct {
	IssueUpdatedAt time.Time `json:"issue_updated_at"`
	Comments       []Comment `json:"comments"`
}

CommentCache holds an issue's comments as of the issue's UpdatedAt.

type Conflict

type Conflict struct {
	RemoteTitle *string `json:"remote_title,omitempty"`
	RemoteBody  *string `json:"remote_body,omitempty"`
}

Conflict records the remote values that clash with an edit.

type Meta

type Meta struct {
	Login string `json:"login,omitempty"`

	// The newest triage release seen, and when GitHub was last asked.
	UpdateCheckedAt time.Time `json:"update_checked_at,omitempty"`
	LatestVersion   string    `json:"latest_version,omitempty"`
	LatestNotes     string    `json:"latest_notes,omitempty"`
	LatestURL       string    `json:"latest_url,omitempty"`
	// UpdateNotifiedAt is when the command line last mentioned an update.
	UpdateNotifiedAt time.Time `json:"update_notified_at,omitempty"`
}

Meta is small cached state that isn't tied to a repository.

type Op

type Op struct {
	ID        string    `json:"id"`
	Kind      OpKind    `json:"kind"`
	Repo      string    `json:"repo"`
	Number    int       `json:"number,omitempty"`
	LocalID   string    `json:"local_id,omitempty"`
	CreatedAt time.Time `json:"created_at"`

	// Create and edit. For edits, nil means unchanged and Base* hold the
	// values the user started from, used to detect conflicting remote edits.
	Title     *string  `json:"title,omitempty"`
	Body      *string  `json:"body,omitempty"`
	BaseTitle *string  `json:"base_title,omitempty"`
	BaseBody  *string  `json:"base_body,omitempty"`
	Labels    []string `json:"labels,omitempty"`
	Assignees []string `json:"assignees,omitempty"`

	// Labels and assign.
	Add    []string `json:"add,omitempty"`
	Remove []string `json:"remove,omitempty"`

	// State.
	State       string `json:"state,omitempty"`
	StateReason string `json:"state_reason,omitempty"`

	// Comment.
	Comment string `json:"comment,omitempty"`

	// Error is set when GitHub rejected the op; it's held until the user
	// retries or discards it.
	Error string `json:"error,omitempty"`
	// Conflict is set when the issue changed on GitHub in a way that clashes
	// with this edit.
	Conflict *Conflict `json:"conflict,omitempty"`
	Attempts int       `json:"attempts,omitempty"`
	// contains filtered or unexported fields
}

Op is one change waiting to be sent to GitHub. Ops target an issue by Number, or by LocalID when the issue was created in triage and hasn't reached GitHub yet.

func (Op) Held

func (op Op) Held() bool

Held reports whether the op needs the user's attention before it can be sent.

func (Op) Sending

func (op Op) Sending() bool

Sending reports whether some process is sending the op right now.

func (Op) Target

func (op Op) Target() string

Target identifies the issue an op applies to, matching issue.Issue.Key.

type OpKind

type OpKind string

OpKind is the kind of change an outbox entry makes.

const (
	OpCreate  OpKind = "create"
	OpEdit    OpKind = "edit"
	OpLabels  OpKind = "labels"
	OpState   OpKind = "state"
	OpAssign  OpKind = "assign"
	OpComment OpKind = "comment"
)

type RepoCache

type RepoCache struct {
	Repo string `json:"repo"`
	// ETag and Watermark identify the last issue listing so the next refresh
	// only asks for issues updated since then.
	ETag      string    `json:"etag,omitempty"`
	Watermark time.Time `json:"watermark,omitempty"`
	FetchedAt time.Time `json:"fetched_at,omitempty"`
	// FullETag and FullCheckedAt describe the last complete listing, which
	// is how triage notices issues that were deleted or transferred.
	FullETag      string    `json:"full_etag,omitempty"`
	FullCheckedAt time.Time `json:"full_checked_at,omitempty"`
	// FullListed are the issue numbers in that listing, so a 304 answer
	// still tells triage which cached issues are missing.
	FullListed []int         `json:"full_listed,omitempty"`
	Issues     []issue.Issue `json:"issues"`
	Labels     []gh.Label    `json:"labels,omitempty"`
}

RepoCache is everything triage remembers about one repository.

func (*RepoCache) Merge

func (c *RepoCache) Merge(fetched []issue.Issue)

Merge folds freshly fetched issues into the cache, replacing older copies and advancing the watermark.

func (*RepoCache) Put

func (c *RepoCache) Put(fresh issue.Issue)

Put stores a single issue returned by a write, without moving the watermark: the next listing still has to catch up with other changes.

type Store

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

Store reads and writes triage's local files.

func New

func New(paths config.Paths) *Store

func (*Store) Claim

func (s *Store) Claim(id string) (bool, error)

Claim marks op as being sent by this process. It returns false when the op is already claimed or gone, in which case the caller must leave it alone.

func (*Store) ClaimOp

func (s *Store) ClaimOp(id string) (Op, bool, error)

ClaimOp claims an op and returns its current contents, which may be newer than a copy read earlier by Pending.

func (*Store) Complete

func (s *Store) Complete(id string) error

Complete removes a claimed op from the outbox.

func (*Store) Discard

func (s *Store) Discard(id string) (bool, error)

Discard deletes an op that isn't being sent. It returns false when the op was claimed by someone else or no longer exists.

func (*Store) Enqueue

func (s *Store) Enqueue(op Op) (Op, error)

Enqueue adds op to the outbox, assigning it an ID.

func (*Store) ForgetComments added in v0.3.0

func (s *Store) ForgetComments(repo string, number int)

ForgetComments deletes an issue's cached comments.

func (*Store) ForgetRepo

func (s *Store) ForgetRepo(repo string) error

ForgetRepo deletes everything cached for repo.

func (*Store) LoadComments

func (s *Store) LoadComments(repo string, number int) (CommentCache, bool)

LoadComments returns cached comments; ok is false when nothing is cached.

func (*Store) LoadMeta

func (s *Store) LoadMeta() Meta

func (*Store) LoadRepo

func (s *Store) LoadRepo(repo string) (RepoCache, error)

LoadRepo returns the cached data for repo, or an empty cache.

func (*Store) Paths

func (s *Store) Paths() config.Paths

func (*Store) Pending

func (s *Store) Pending() ([]Op, error)

Pending returns every op in the outbox, oldest first, including ops being sent by another process. Claims that have gone stale are released.

func (*Store) Release

func (s *Store) Release(op Op) error

Release puts a claimed op back, saving any changes made to it.

func (*Store) SaveComments

func (s *Store) SaveComments(repo string, number int, cache CommentCache) error

func (*Store) SaveMeta

func (s *Store) SaveMeta(meta Meta) error

func (*Store) SaveRepo

func (s *Store) SaveRepo(cache RepoCache) error

func (*Store) Update

func (s *Store) Update(op Op) (bool, error)

Update rewrites an op that isn't being sent. It returns false when the op was claimed by someone else or no longer exists.

Jump to

Keyboard shortcuts

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