MCPcopy Create free account
hub / github.com/algolia/cli / CheckForUpdate

Function CheckForUpdate

internal/update/update.go:36–60  ·  view source on GitHub ↗

CheckForUpdate checks whether this software has had a newer release on GitHub

(
	client *http.Client,
	stateFilePath, currentVersion string,
)

Source from the content-addressed store, hash-verified

34
35// CheckForUpdate checks whether this software has had a newer release on GitHub
36func CheckForUpdate(
37 client *http.Client,
38 stateFilePath, currentVersion string,
39) (*ReleaseInfo, error) {
40 stateEntry, _ := getStateEntry(stateFilePath)
41 if stateEntry != nil && time.Since(stateEntry.CheckedForUpdateAt).Hours() < 24 {
42 return nil, nil
43 }
44
45 releaseInfo, err := getLatestReleaseInfo(client)
46 if err != nil {
47 return nil, err
48 }
49
50 err = setStateEntry(stateFilePath, time.Now(), *releaseInfo)
51 if err != nil {
52 return nil, err
53 }
54
55 if versionGreaterThan(releaseInfo.Version, currentVersion) {
56 return releaseInfo, nil
57 }
58
59 return nil, nil
60}
61
62func getLatestReleaseInfo(client *http.Client) (*ReleaseInfo, error) {
63 var latestRelease ReleaseInfo

Callers 2

checkForUpdateFunction · 0.92
TestCheckForUpdateFunction · 0.85

Calls 4

getStateEntryFunction · 0.85
getLatestReleaseInfoFunction · 0.85
setStateEntryFunction · 0.85
versionGreaterThanFunction · 0.85

Tested by 1

TestCheckForUpdateFunction · 0.68