CheckForExtensionUpdate checks whether an update exists for a specific extension based on extension type and recency of last check within past 24 hours.
(em extensions.ExtensionManager, ext extensions.Extension, now time.Time)
| 50 | |
| 51 | // CheckForExtensionUpdate checks whether an update exists for a specific extension based on extension type and recency of last check within past 24 hours. |
| 52 | func CheckForExtensionUpdate(em extensions.ExtensionManager, ext extensions.Extension, now time.Time) (*ReleaseInfo, error) { |
| 53 | // local extensions cannot have updates, so avoid work that ultimately returns nothing. |
| 54 | if ext.IsLocal() { |
| 55 | return nil, nil |
| 56 | } |
| 57 | |
| 58 | stateFilePath := filepath.Join(em.UpdateDir(ext.Name()), "state.yml") |
| 59 | stateEntry, _ := getStateEntry(stateFilePath) |
| 60 | if stateEntry != nil && now.Sub(stateEntry.CheckedForUpdateAt).Hours() < 24 { |
| 61 | return nil, nil |
| 62 | } |
| 63 | |
| 64 | releaseInfo := &ReleaseInfo{ |
| 65 | Version: ext.LatestVersion(), |
| 66 | URL: ext.URL(), |
| 67 | } |
| 68 | |
| 69 | err := setStateEntry(stateFilePath, now, *releaseInfo) |
| 70 | if err != nil { |
| 71 | return nil, err |
| 72 | } |
| 73 | |
| 74 | if ext.UpdateAvailable() { |
| 75 | return releaseInfo, nil |
| 76 | } |
| 77 | |
| 78 | return nil, nil |
| 79 | } |
| 80 | |
| 81 | // ShouldCheckForUpdate decides whether we check for updates for the GitHub CLI based on user preferences and current execution context. |
| 82 | func ShouldCheckForUpdate() bool { |