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