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)
| 185 | |
| 186 | // FetchRelease finds a published repository release by its tagName, or a draft release by its pending tag name. |
| 187 | func 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. |
| 216 | func FetchLatestRelease(ctx context.Context, httpClient *http.Client, repo ghrepo.Interface) (*Release, error) { |
no test coverage detected