GetAnnotations fetches annotations from the REST API. If the job has no annotations, an empty slice is returned. If the API returns a 403, a custom ErrMissingAnnotationsPermissions error is returned. When fine-grained PATs support checks:read permission, we can remove the need for this at the call
(client *api.Client, repo ghrepo.Interface, job Job)
| 280 | // |
| 281 | // When fine-grained PATs support checks:read permission, we can remove the need for this at the call sites. |
| 282 | func GetAnnotations(client *api.Client, repo ghrepo.Interface, job Job) ([]Annotation, error) { |
| 283 | var result []*Annotation |
| 284 | |
| 285 | path, err := safeurl.JoinPath("repos", repo.RepoOwner(), repo.RepoName(), "check-runs", strconv.FormatInt(job.ID, 10), "annotations") |
| 286 | if err != nil { |
| 287 | return nil, err |
| 288 | } |
| 289 | |
| 290 | err = client.REST(repo.RepoHost(), "GET", path.String(), nil, &result) |
| 291 | if err != nil { |
| 292 | var httpError api.HTTPError |
| 293 | if !errors.As(err, &httpError) { |
| 294 | return nil, err |
| 295 | } |
| 296 | |
| 297 | if httpError.StatusCode == http.StatusNotFound { |
| 298 | return []Annotation{}, nil |
| 299 | } |
| 300 | |
| 301 | if httpError.StatusCode == http.StatusForbidden { |
| 302 | return nil, ErrMissingAnnotationsPermissions |
| 303 | } |
| 304 | |
| 305 | return nil, err |
| 306 | } |
| 307 | |
| 308 | out := []Annotation{} |
| 309 | |
| 310 | for _, annotation := range result { |
| 311 | annotation.JobName = job.Name |
| 312 | out = append(out, *annotation) |
| 313 | } |
| 314 | |
| 315 | return out, nil |
| 316 | } |
| 317 | |
| 318 | func IsFailureState(c Conclusion) bool { |
| 319 | switch c { |