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

Function FetchRelease

pkg/cmd/release/shared/fetch.go:187–213  ·  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 res := <-results
205 if errors.Is(res.error, ErrReleaseNotFound) {
206 res = <-results
207 cancel() // satisfy the linter even though no goroutines are running anymore
208 } else {
209 cancel()
210 <-results // drain the channel
211 }
212 return res.release, res.error
213}
214
215// FetchLatestRelease finds the latest published release for a repository.
216func 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