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

Function fetchLatestRelease

pkg/cmd/extension/http.go:119–144  ·  view source on GitHub ↗

fetchLatestRelease finds the latest published release for a repository.

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

Source from the content-addressed store, hash-verified

117
118// fetchLatestRelease finds the latest published release for a repository.
119func fetchLatestRelease(httpClient *http.Client, baseRepo ghrepo.Interface) (*release, error) {
120 path, err := safeurl.JoinPath("repos", baseRepo.RepoOwner(), baseRepo.RepoName(), "releases", "latest")
121 if err != nil {
122 return nil, err
123 }
124
125 var data json.RawMessage
126 // TODO(api-client-rollout)
127 // This line of code is part of a mechanical roll out of the api client.
128 // As a follow up, consider whether the api client can be injected to this call site, rather than constructed
129 err = api.NewClientFromHTTP(httpClient).REST(baseRepo.RepoHost(), http.MethodGet, path.String(), nil, &data)
130 if err != nil {
131 var httpErr api.HTTPError
132 if errors.As(err, &httpErr) && httpErr.StatusCode == http.StatusNotFound {
133 return nil, releaseNotFoundErr
134 }
135 return nil, err
136 }
137
138 var r release
139 if err := json.Unmarshal(data, &r); err != nil {
140 return nil, err
141 }
142
143 return &r, nil
144}
145
146// fetchReleaseFromTag finds release by tag name for a repository
147func fetchReleaseFromTag(httpClient *http.Client, baseRepo ghrepo.Interface, tagName string) (*release, error) {

Callers 4

LatestVersionMethod · 0.85
installBinMethod · 0.85
isBinExtensionFunction · 0.85
TestFetchLatestReleaseFunction · 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

TestFetchLatestReleaseFunction · 0.68