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

Function fetchReleaseFromTag

pkg/cmd/extension/http.go:141–166  ·  view source on GitHub ↗

fetchReleaseFromTag finds release by tag name for a repository

(httpClient *http.Client, baseRepo ghrepo.Interface, tagName string)

Source from the content-addressed store, hash-verified

139
140// fetchReleaseFromTag finds release by tag name for a repository
141func fetchReleaseFromTag(httpClient *http.Client, baseRepo ghrepo.Interface, tagName string) (*release, error) {
142 path, err := safeurl.JoinPath("repos", baseRepo.RepoOwner(), baseRepo.RepoName(), "releases", "tags", tagName)
143 if err != nil {
144 return nil, err
145 }
146
147 var data json.RawMessage
148 // TODO(api-client-rollout)
149 // This line of code is part of a mechanical roll out of the api client.
150 // As a follow up, consider whether the api client can be injected to this call site, rather than constructed
151 err = api.NewClientFromHTTP(httpClient).REST(baseRepo.RepoHost(), http.MethodGet, path.String(), nil, &data)
152 if err != nil {
153 var httpErr api.HTTPError
154 if errors.As(err, &httpErr) && httpErr.StatusCode == http.StatusNotFound {
155 return nil, releaseNotFoundErr
156 }
157 return nil, err
158 }
159
160 var r release
161 if err := json.Unmarshal(data, &r); err != nil {
162 return nil, err
163 }
164
165 return &r, nil
166}
167
168// fetchCommitSHA finds full commit SHA from a target ref in a repo
169func fetchCommitSHA(httpClient *http.Client, baseRepo ghrepo.Interface, targetRef string) (string, error) {

Callers 2

installBinMethod · 0.85
TestFetchReleaseFromTagFunction · 0.85

Calls 7

JoinPathFunction · 0.92
NewClientFromHTTPFunction · 0.92
RepoOwnerMethod · 0.65
RepoNameMethod · 0.65
RESTMethod · 0.65
RepoHostMethod · 0.65
StringMethod · 0.65

Tested by 1

TestFetchReleaseFromTagFunction · 0.68