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

Function fetchReleaseFromTag

pkg/cmd/extension/http.go:147–172  ·  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

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