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