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)
| 278 | // |
| 279 | // When fine-grained PATs support checks:read permission, we can remove the need for this at the call sites. |
| 280 | func GetAnnotations(client *api.Client, repo ghrepo.Interface, job Job) ([]Annotation, error) { |
| 281 | var result []*Annotation |
| 282 | |
| 283 | path := fmt.Sprintf("repos/%s/check-runs/%d/annotations", ghrepo.FullName(repo), job.ID) |
| 284 | |
| 285 | err := client.REST(repo.RepoHost(), "GET", path, nil, &result) |
| 286 | if err != nil { |
| 287 | var httpError api.HTTPError |
| 288 | if !errors.As(err, &httpError) { |
| 289 | return nil, err |
| 290 | } |
| 291 | |
| 292 | if httpError.StatusCode == http.StatusNotFound { |
| 293 | return []Annotation{}, nil |
| 294 | } |
| 295 | |
| 296 | if httpError.StatusCode == http.StatusForbidden { |
| 297 | return nil, ErrMissingAnnotationsPermissions |
| 298 | } |
| 299 | |
| 300 | return nil, err |
| 301 | } |
| 302 | |
| 303 | out := []Annotation{} |
| 304 | |
| 305 | for _, annotation := range result { |
| 306 | annotation.JobName = job.Name |
| 307 | out = append(out, *annotation) |
| 308 | } |
| 309 | |
| 310 | return out, nil |
| 311 | } |
| 312 | |
| 313 | func IsFailureState(c Conclusion) bool { |
| 314 | switch c { |