MCPcopy
hub / github.com/cli/cli / FetchRelease

Function FetchRelease

pkg/cmd/release/shared/fetch.go:187–225  ·  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

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

fetchReleasePathFunction · 0.85
fetchDraftReleaseFunction · 0.85
RepoOwnerMethod · 0.65
RepoNameMethod · 0.65
RepoHostMethod · 0.65

Tested by

no test coverage detected