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)
| 90 | |
| 91 | // CheckForUpdate checks whether an update exists for the GitHub CLI based on recency of last check within past 24 hours. |
| 92 | func 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 | |
| 115 | func getLatestReleaseInfo(ctx context.Context, client *http.Client, repo string) (*ReleaseInfo, error) { |
| 116 | owner, name, err := safeurl.RepoPartsFromNWO(repo) |