update

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 15 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 update finds ytrack releases on GitHub, compares versions, keeps the once-a-day update check state, and tells which package manager owns an installed binary.

Index

Constants

View Source
const (
	// Repo is the GitHub repository that publishes ytrack releases.
	Repo = "BrainerVirus/youtrack-cli"
	// DefaultAPIURL is the GitHub REST API root.
	DefaultAPIURL = "https://api.github.com"
)
View Source
const CheckInterval = 24 * time.Hour

CheckInterval is how long a release check is reused before asking again.

View Source
const StateFile = "state.yml"

StateFile is the file in the state directory that records the last check.

Variables

View Source
var ErrReleaseNotFound = errors.New("release not found")

ErrReleaseNotFound is returned when the requested release does not exist.

Functions

func Due

func Due(statePath string, now time.Time) bool

Due reports whether the last check recorded at statePath is older than CheckInterval, so a new one may go to the network.

func IsRelease

func IsRelease(s string) bool

IsRelease reports whether s is a semantic version (with or without "v"). Development builds ("dev", "test", a git describe string) are not.

func MarkNotified

func MarkNotified(statePath, version string, now time.Time)

MarkNotified records that the notice for version was printed at now.

func Newer

func Newer(a, b string) bool

Newer reports whether version a is newer than b. It is false when either is not a semantic version.

func StatePath

func StatePath() (string, error)

StatePath returns the path of the check state file in the state directory.

func WriteState

func WriteState(path string, s State) error

WriteState saves the check state to path.

Types

type Asset

type Asset struct {
	Name string `json:"name"`
	URL  string `json:"browser_download_url"`
	Size int64  `json:"size"`
}

Asset is a file attached to a release.

type Client

type Client struct {
	HTTP       *http.Client
	APIURL     string // DefaultAPIURL when empty
	UserAgent  string
	Repository string // Repo when empty
}

Client reads releases from the GitHub REST API without credentials.

func (*Client) Latest

func (c *Client) Latest(ctx context.Context) (*Release, error)

Latest returns the newest release that is neither a draft nor a prerelease.

func (*Client) Tag

func (c *Client) Tag(ctx context.Context, tag string) (*Release, error)

Tag returns the release for tag (with or without the leading "v").

type Manager

type Manager struct {
	Name    string // "Homebrew", "Scoop", "WinGet"
	Command string // the command that upgrades ytrack with it
}

Manager is a package manager that owns an installed ytrack binary.

func DetectManager

func DetectManager(paths ...string) *Manager

DetectManager returns the package manager that installed the binary at any of paths (typically the executable path and its symlink target), or nil when none did.

type Notice

type Notice struct {
	Current, Latest, URL string
}

Notice is a newer release worth telling the user about.

func CheckDaily

func CheckDaily(ctx context.Context, c *Client, statePath, current string, now time.Time) (*Notice, error)

CheckDaily asks for the latest release when the last check recorded at statePath is older than CheckInterval, records this check (also when it fails, so an offline machine asks once a day, not on every run; a failed check keeps the release cached before it) and returns a Notice when that release is newer than current. It returns nil without any network call when a check already happened within the interval. A check cancelled through ctx (abandoned by the caller) records nothing, so the next run asks again.

func Pending

func Pending(statePath, current string, now time.Time) *Notice

Pending returns the cached release at statePath as a Notice when it is newer than current and was not announced within CheckInterval. It reads only the state file, never the network.

type Release

type Release struct {
	Tag        string  `json:"tag_name"`
	URL        string  `json:"html_url"`
	Prerelease bool    `json:"prerelease"`
	Draft      bool    `json:"draft"`
	Assets     []Asset `json:"assets"`
}

Release is a published GitHub release.

func (*Release) Asset

func (r *Release) Asset(name string) *Asset

Asset returns the asset called name, or nil.

func (*Release) Version

func (r *Release) Version() string

Version returns the tag without its leading "v".

type State

type State struct {
	CheckedAt     time.Time `yaml:"checked_at"`
	LatestVersion string    `yaml:"latest_version,omitempty"`
	LatestURL     string    `yaml:"latest_url,omitempty"`
	// NotifiedAt and NotifiedVersion record the last notice printed, so a
	// cached newer release is announced once per CheckInterval.
	NotifiedAt      time.Time `yaml:"notified_at,omitempty"`
	NotifiedVersion string    `yaml:"notified_version,omitempty"`
}

State is what the daily check remembers between runs.

func ReadState

func ReadState(path string) State

ReadState loads the check state from path. A missing or unreadable file is an empty state.

Jump to

Keyboard shortcuts

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