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
- Variables
- func Due(statePath string, now time.Time) bool
- func IsRelease(s string) bool
- func MarkNotified(statePath, version string, now time.Time)
- func Newer(a, b string) bool
- func StatePath() (string, error)
- func WriteState(path string, s State) error
- type Asset
- type Client
- type Manager
- type Notice
- type Release
- type State
Constants ¶
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" )
const CheckInterval = 24 * time.Hour
CheckInterval is how long a release check is reused before asking again.
const StateFile = "state.yml"
StateFile is the file in the state directory that records the last check.
Variables ¶
var ErrReleaseNotFound = errors.New("release not found")
ErrReleaseNotFound is returned when the requested release does not exist.
Functions ¶
func Due ¶
Due reports whether the last check recorded at statePath is older than CheckInterval, so a new one may go to the network.
func IsRelease ¶
IsRelease reports whether s is a semantic version (with or without "v"). Development builds ("dev", "test", a git describe string) are not.
func MarkNotified ¶
MarkNotified records that the notice for version was printed at now.
func Newer ¶
Newer reports whether version a is newer than b. It is false when either is not a semantic version.
func WriteState ¶
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.
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 ¶
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.
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.
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.