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

Function CheckForUpdate

internal/update/update.go:93–114  ·  view source on GitHub ↗

CheckForUpdate checks whether an update exists for the GitHub CLI based on recency of last check within past 24 hours.

(ctx context.Context, client *http.Client, stateFilePath, repo, currentVersion string)

Source from the content-addressed store, hash-verified

91
92// CheckForUpdate checks whether an update exists for the GitHub CLI based on recency of last check within past 24 hours.
93func CheckForUpdate(ctx context.Context, client *http.Client, stateFilePath, repo, currentVersion string) (*ReleaseInfo, error) {
94 stateEntry, _ := getStateEntry(stateFilePath)
95 if stateEntry != nil && time.Since(stateEntry.CheckedForUpdateAt).Hours() < 24 {
96 return nil, nil
97 }
98
99 releaseInfo, err := getLatestReleaseInfo(ctx, client, repo)
100 if err != nil {
101 return nil, err
102 }
103
104 err = setStateEntry(stateFilePath, time.Now(), *releaseInfo)
105 if err != nil {
106 return nil, err
107 }
108
109 if versionGreaterThan(releaseInfo.Version, currentVersion) {
110 return releaseInfo, nil
111 }
112
113 return nil, nil
114}
115
116func getLatestReleaseInfo(ctx context.Context, client *http.Client, repo string) (*ReleaseInfo, error) {
117 owner, name, err := safeurl.RepoPartsFromNWO(repo)

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