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