MCPcopy Index your code
hub / github.com/cli/cli / CheckForUpdate

Function CheckForUpdate

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

89
90// CheckForUpdate checks whether an update exists for the GitHub CLI based on recency of last check within past 24 hours.
91func CheckForUpdate(ctx context.Context, client *http.Client, stateFilePath, repo, currentVersion string) (*ReleaseInfo, error) {
92 stateEntry, _ := getStateEntry(stateFilePath)
93 if stateEntry != nil && time.Since(stateEntry.CheckedForUpdateAt).Hours() < 24 {
94 return nil, nil
95 }
96
97 releaseInfo, err := getLatestReleaseInfo(ctx, client, repo)
98 if err != nil {
99 return nil, err
100 }
101
102 err = setStateEntry(stateFilePath, time.Now(), *releaseInfo)
103 if err != nil {
104 return nil, err
105 }
106
107 if versionGreaterThan(releaseInfo.Version, currentVersion) {
108 return releaseInfo, nil
109 }
110
111 return nil, nil
112}
113
114func getLatestReleaseInfo(ctx context.Context, client *http.Client, repo string) (*ReleaseInfo, error) {
115 req, err := http.NewRequestWithContext(ctx, "GET", fmt.Sprintf("https://api.github.com/repos/%s/releases/latest", repo), nil)

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