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

Function fetchLatestRelease

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

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