MCPcopy
hub / github.com/cli/cli / GetAnnotations

Function GetAnnotations

pkg/cmd/run/shared/shared.go:280–311  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

278//
279// When fine-grained PATs support checks:read permission, we can remove the need for this at the call sites.
280func 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
313func IsFailureState(c Conclusion) bool {
314 switch c {

Callers 3

runViewFunction · 0.92
renderRunFunction · 0.92
TestGetAnnotations404Function · 0.85

Calls 3

FullNameFunction · 0.92
RESTMethod · 0.65
RepoHostMethod · 0.65

Tested by 1

TestGetAnnotations404Function · 0.68