MCPcopy Create free account
hub / github.com/cli/cli / GetAnnotations

Function GetAnnotations

pkg/cmd/run/shared/shared.go:282–316  ·  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

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

Callers 3

runViewFunction · 0.92
renderRunFunction · 0.92
TestGetAnnotations404Function · 0.85

Calls 6

JoinPathFunction · 0.92
RepoOwnerMethod · 0.65
RepoNameMethod · 0.65
RESTMethod · 0.65
RepoHostMethod · 0.65
StringMethod · 0.65

Tested by 1

TestGetAnnotations404Function · 0.68