MCPcopy Create free account
hub / github.com/cli/cli / fetchReleasePath

Function fetchReleasePath

pkg/cmd/release/shared/fetch.go:281–306  ·  view source on GitHub ↗
(ctx context.Context, httpClient *http.Client, url safeurl.SafeURL)

Source from the content-addressed store, hash-verified

279}
280
281func fetchReleasePath(ctx context.Context, httpClient *http.Client, url safeurl.SafeURL) (*Release, error) {
282 req, err := http.NewRequestWithContext(ctx, "GET", url.String(), nil)
283 if err != nil {
284 return nil, err
285 }
286
287 resp, err := httpClient.Do(req)
288 if err != nil {
289 return nil, err
290 }
291 defer resp.Body.Close()
292
293 if resp.StatusCode == http.StatusNotFound {
294 _, _ = io.Copy(io.Discard, resp.Body)
295 return nil, ErrReleaseNotFound
296 } else if resp.StatusCode > 299 {
297 return nil, api.HandleHTTPError(resp)
298 }
299
300 var release Release
301 if err := json.NewDecoder(resp.Body).Decode(&release); err != nil {
302 return nil, err
303 }
304
305 return &release, nil
306}
307
308func StubFetchRelease(t *testing.T, reg *httpmock.Registry, owner, repoName, tagName, responseBody string) {
309 path := "repos/OWNER/REPO/releases/tags/v1.2.3"

Callers 3

FetchReleaseFunction · 0.85
FetchLatestReleaseFunction · 0.85
fetchDraftReleaseFunction · 0.85

Calls 5

HandleHTTPErrorFunction · 0.92
StringMethod · 0.65
DoMethod · 0.65
CloseMethod · 0.65
CopyMethod · 0.45

Tested by

no test coverage detected