(ctx context.Context, client *http.Client, repo string)
| 112 | } |
| 113 | |
| 114 | func getLatestReleaseInfo(ctx context.Context, client *http.Client, repo string) (*ReleaseInfo, error) { |
| 115 | req, err := http.NewRequestWithContext(ctx, "GET", fmt.Sprintf("https://api.github.com/repos/%s/releases/latest", repo), nil) |
| 116 | if err != nil { |
| 117 | return nil, err |
| 118 | } |
| 119 | res, err := client.Do(req) |
| 120 | if err != nil { |
| 121 | return nil, err |
| 122 | } |
| 123 | defer func() { |
| 124 | _, _ = io.Copy(io.Discard, res.Body) |
| 125 | res.Body.Close() |
| 126 | }() |
| 127 | if res.StatusCode != 200 { |
| 128 | return nil, fmt.Errorf("unexpected HTTP %d", res.StatusCode) |
| 129 | } |
| 130 | dec := json.NewDecoder(res.Body) |
| 131 | var latestRelease ReleaseInfo |
| 132 | if err := dec.Decode(&latestRelease); err != nil { |
| 133 | return nil, err |
| 134 | } |
| 135 | return &latestRelease, nil |
| 136 | } |
| 137 | |
| 138 | func getStateEntry(stateFilePath string) (*StateEntry, error) { |
| 139 | content, err := os.ReadFile(stateFilePath) |
no test coverage detected