MCPcopy
hub / github.com/cli/cli / fetchReleasePath

Function fetchReleasePath

pkg/cmd/release/shared/fetch.go:254–279  ·  view source on GitHub ↗
(ctx context.Context, httpClient *http.Client, host string, p string)

Source from the content-addressed store, hash-verified

252}
253
254func fetchReleasePath(ctx context.Context, httpClient *http.Client, host string, p string) (*Release, error) {
255 req, err := http.NewRequestWithContext(ctx, "GET", ghinstance.RESTPrefix(host)+p, nil)
256 if err != nil {
257 return nil, err
258 }
259
260 resp, err := httpClient.Do(req)
261 if err != nil {
262 return nil, err
263 }
264 defer resp.Body.Close()
265
266 if resp.StatusCode == http.StatusNotFound {
267 _, _ = io.Copy(io.Discard, resp.Body)
268 return nil, ErrReleaseNotFound
269 } else if resp.StatusCode > 299 {
270 return nil, api.HandleHTTPError(resp)
271 }
272
273 var release Release
274 if err := json.NewDecoder(resp.Body).Decode(&release); err != nil {
275 return nil, err
276 }
277
278 return &release, nil
279}
280
281func StubFetchRelease(t *testing.T, reg *httpmock.Registry, owner, repoName, tagName, responseBody string) {
282 path := "repos/OWNER/REPO/releases/tags/v1.2.3"

Callers 3

FetchReleaseFunction · 0.85
FetchLatestReleaseFunction · 0.85
fetchDraftReleaseFunction · 0.85

Calls 5

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

Tested by

no test coverage detected