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