MCPcopy
hub / github.com/cli/cli / fetchLatestRelease

Function fetchLatestRelease

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

113
114// fetchLatestRelease finds the latest published release for a repository.
115func fetchLatestRelease(httpClient *http.Client, baseRepo ghrepo.Interface) (*release, error) {
116 path := fmt.Sprintf("repos/%s/%s/releases/latest", baseRepo.RepoOwner(), baseRepo.RepoName())
117 url := ghinstance.RESTPrefix(baseRepo.RepoHost()) + path
118 req, err := http.NewRequest("GET", url, nil)
119 if err != nil {
120 return nil, err
121 }
122
123 resp, err := httpClient.Do(req)
124 if err != nil {
125 return nil, err
126 }
127 defer resp.Body.Close()
128
129 if resp.StatusCode == 404 {
130 return nil, releaseNotFoundErr
131 }
132 if resp.StatusCode > 299 {
133 return nil, api.HandleHTTPError(resp)
134 }
135
136 b, err := io.ReadAll(resp.Body)
137 if err != nil {
138 return nil, err
139 }
140
141 var r release
142 err = json.Unmarshal(b, &r)
143 if err != nil {
144 return nil, err
145 }
146
147 return &r, nil
148}
149
150// fetchReleaseFromTag finds release by tag name for a repository
151func fetchReleaseFromTag(httpClient *http.Client, baseRepo ghrepo.Interface, tagName string) (*release, error) {

Callers 3

LatestVersionMethod · 0.85
installBinMethod · 0.85
isBinExtensionFunction · 0.85

Calls 7

RESTPrefixFunction · 0.92
HandleHTTPErrorFunction · 0.92
RepoOwnerMethod · 0.65
RepoNameMethod · 0.65
RepoHostMethod · 0.65
DoMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected