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