(client *api.Client, host, owner, repo string)
| 339 | func (e *noReleasesError) Error() string { return e.reason } |
| 340 | |
| 341 | func resolveLatestRelease(client *api.Client, host, owner, repo string) (*ResolvedRef, error) { |
| 342 | apiPath, err := safeurl.JoinPath("repos", owner, repo, "releases", "latest") |
| 343 | if err != nil { |
| 344 | return nil, err |
| 345 | } |
| 346 | var resp struct { |
| 347 | TagName string `json:"tag_name"` |
| 348 | } |
| 349 | if err := client.REST(host, "GET", apiPath.String(), nil, &resp); err != nil { |
| 350 | // A 404 means the repository has no releases. This is the |
| 351 | // only case where falling back to the default branch is safe. |
| 352 | // Any other HTTP error (403, 500, …) or network failure is |
| 353 | // returned as-is so ResolveRef surfaces it rather than |
| 354 | // silently falling back. |
| 355 | if isNotFound(err) { |
| 356 | return nil, &noReleasesError{reason: fmt.Sprintf("no releases found for %s/%s", owner, repo)} |
| 357 | } |
| 358 | return nil, fmt.Errorf("could not fetch latest release: %w", err) |
| 359 | } |
| 360 | if resp.TagName == "" { |
| 361 | return nil, &noReleasesError{reason: "latest release has no tag"} |
| 362 | } |
| 363 | return resolveTagRef(client, host, owner, repo, resp.TagName) |
| 364 | } |
| 365 | |
| 366 | func resolveDefaultBranch(client *api.Client, host, owner, repo string) (*ResolvedRef, error) { |
| 367 | apiPath, err := safeurl.JoinPath("repos", owner, repo) |
no test coverage detected