fetchLatestRelease finds the latest published release for a repository.
(httpClient *http.Client, baseRepo ghrepo.Interface)
| 117 | |
| 118 | // fetchLatestRelease finds the latest published release for a repository. |
| 119 | func fetchLatestRelease(httpClient *http.Client, baseRepo ghrepo.Interface) (*release, error) { |
| 120 | path, err := safeurl.JoinPath("repos", baseRepo.RepoOwner(), baseRepo.RepoName(), "releases", "latest") |
| 121 | if err != nil { |
| 122 | return nil, err |
| 123 | } |
| 124 | |
| 125 | var data json.RawMessage |
| 126 | // TODO(api-client-rollout) |
| 127 | // This line of code is part of a mechanical roll out of the api client. |
| 128 | // As a follow up, consider whether the api client can be injected to this call site, rather than constructed |
| 129 | err = api.NewClientFromHTTP(httpClient).REST(baseRepo.RepoHost(), http.MethodGet, path.String(), nil, &data) |
| 130 | if err != nil { |
| 131 | var httpErr api.HTTPError |
| 132 | if errors.As(err, &httpErr) && httpErr.StatusCode == http.StatusNotFound { |
| 133 | return nil, releaseNotFoundErr |
| 134 | } |
| 135 | return nil, err |
| 136 | } |
| 137 | |
| 138 | var r release |
| 139 | if err := json.Unmarshal(data, &r); err != nil { |
| 140 | return nil, err |
| 141 | } |
| 142 | |
| 143 | return &r, nil |
| 144 | } |
| 145 | |
| 146 | // fetchReleaseFromTag finds release by tag name for a repository |
| 147 | func fetchReleaseFromTag(httpClient *http.Client, baseRepo ghrepo.Interface, tagName string) (*release, error) { |