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

Function CheckForUpdate

internal/update/update.go:92–113  ·  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

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