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

Function FetchRelease

pkg/cmd/release/shared/fetch.go:192–234  ·  view source on GitHub ↗

FetchRelease finds a published repository release by its tagName, or a draft release by its pending tag name.

(ctx context.Context, httpClient *http.Client, repo ghrepo.Interface, tagName string)

Source from the content-addressed store, hash-verified

190
191// FetchRelease finds a published repository release by its tagName, or a draft release by its pending tag name.
192func FetchRelease(ctx context.Context, httpClient *http.Client, repo ghrepo.Interface, tagName string) (*Release, error) {
193 publishedURL, err := safeurl.JoinPathWithHostPrefix(ghinstance.RESTPrefix(repo.RepoHost()), "repos", repo.RepoOwner(), repo.RepoName(), "releases", "tags", tagName)
194 if err != nil {
195 return nil, err
196 }
197
198 cc, cancel := context.WithCancel(ctx)
199 results := make(chan fetchResult, 2)
200
201 // published release lookup
202 go func() {
203 release, err := fetchReleasePath(cc, httpClient, publishedURL)
204 results <- fetchResult{release: release, error: err}
205 }()
206
207 // draft release lookup
208 go func() {
209 release, err := fetchDraftRelease(cc, httpClient, repo, tagName)
210 results <- fetchResult{release: release, error: err}
211 }()
212
213 // Prefer a release found by either lookup. A single failed lookup, such as
214 // the draft lookup when unauthenticated, must not mask a release found by
215 // the other; only report an error when both lookups fail.
216 first := <-results
217 if first.error == nil {
218 cancel()
219 <-results // drain the channel
220 return first.release, nil
221 }
222
223 second := <-results
224 cancel() // satisfy the linter even though no goroutines are running anymore
225 if second.error == nil {
226 return second.release, nil
227 }
228
229 // Both lookups failed; prefer reporting the release as not found.
230 if errors.Is(second.error, ErrReleaseNotFound) {
231 return nil, second.error
232 }
233 return nil, first.error
234}
235
236// FetchLatestRelease finds the latest published release for a repository.
237func FetchLatestRelease(ctx context.Context, httpClient *http.Client, repo ghrepo.Interface) (*Release, error) {

Callers 6

deleteAssetRunFunction · 0.92
deleteRunFunction · 0.92
viewRunFunction · 0.92
uploadRunFunction · 0.92
downloadRunFunction · 0.92
editRunFunction · 0.92

Calls 7

JoinPathWithHostPrefixFunction · 0.92
RESTPrefixFunction · 0.92
fetchReleasePathFunction · 0.85
fetchDraftReleaseFunction · 0.85
RepoHostMethod · 0.65
RepoOwnerMethod · 0.65
RepoNameMethod · 0.65

Tested by

no test coverage detected