fetchCommitSHA finds full commit SHA from a target ref in a repo
(httpClient *http.Client, baseRepo ghrepo.Interface, targetRef string)
| 193 | |
| 194 | // fetchCommitSHA finds full commit SHA from a target ref in a repo |
| 195 | func fetchCommitSHA(httpClient *http.Client, baseRepo ghrepo.Interface, targetRef string) (string, error) { |
| 196 | url, err := safeurl.JoinPathWithHostPrefix(ghinstance.RESTPrefix(baseRepo.RepoHost()), "repos", baseRepo.RepoOwner(), baseRepo.RepoName(), "commits", targetRef) |
| 197 | if err != nil { |
| 198 | return "", err |
| 199 | } |
| 200 | req, err := http.NewRequest("GET", url.String(), nil) |
| 201 | if err != nil { |
| 202 | return "", err |
| 203 | } |
| 204 | |
| 205 | req.Header.Set("Accept", "application/vnd.github.v3.sha") |
| 206 | resp, err := httpClient.Do(req) |
| 207 | if err != nil { |
| 208 | return "", err |
| 209 | } |
| 210 | |
| 211 | defer resp.Body.Close() |
| 212 | if resp.StatusCode == 422 { |
| 213 | return "", commitNotFoundErr |
| 214 | } |
| 215 | if resp.StatusCode > 299 { |
| 216 | return "", api.HandleHTTPError(resp) |
| 217 | } |
| 218 | |
| 219 | body, err := io.ReadAll(resp.Body) |
| 220 | if err != nil { |
| 221 | return "", err |
| 222 | } |
| 223 | |
| 224 | return string(body), nil |
| 225 | } |
no test coverage detected