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

Function fetchLatestRelease

pkg/cmd/extension/http.go:119–154  ·  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 url, err := safeurl.JoinPathWithHostPrefix(ghinstance.RESTPrefix(baseRepo.RepoHost()), "repos", baseRepo.RepoOwner(), baseRepo.RepoName(), "releases", "latest")
121 if err != nil {
122 return nil, err
123 }
124 req, err := http.NewRequest("GET", url.String(), nil)
125 if err != nil {
126 return nil, err
127 }
128
129 resp, err := httpClient.Do(req)
130 if err != nil {
131 return nil, err
132 }
133 defer resp.Body.Close()
134
135 if resp.StatusCode == 404 {
136 return nil, releaseNotFoundErr
137 }
138 if resp.StatusCode > 299 {
139 return nil, api.HandleHTTPError(resp)
140 }
141
142 b, err := io.ReadAll(resp.Body)
143 if err != nil {
144 return nil, err
145 }
146
147 var r release
148 err = json.Unmarshal(b, &r)
149 if err != nil {
150 return nil, err
151 }
152
153 return &r, nil
154}
155
156// fetchReleaseFromTag finds release by tag name for a repository
157func fetchReleaseFromTag(httpClient *http.Client, baseRepo ghrepo.Interface, tagName string) (*release, error) {

Callers 3

LatestVersionMethod · 0.85
installBinMethod · 0.85
isBinExtensionFunction · 0.85

Calls 9

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

Tested by

no test coverage detected