diff --git a/pkg/cmd/run/view/view.go b/pkg/cmd/run/view/view.go index bc40b66ee..e77def23a 100644 --- a/pkg/cmd/run/view/view.go +++ b/pkg/cmd/run/view/view.go @@ -305,23 +305,14 @@ func runView(opts *ViewOptions) error { } var annotations []shared.Annotation - - var annotationErr error - var as []shared.Annotation for _, job := range jobs { - as, annotationErr = shared.GetAnnotations(client, repo, job) - if annotationErr != nil { - break + as, err := shared.GetAnnotations(client, repo, job) + if err != nil { + return fmt.Errorf("failed to get annotations: %w", err) } annotations = append(annotations, as...) } - opts.IO.StopProgressIndicator() - - if annotationErr != nil { - return fmt.Errorf("failed to get annotations: %w", annotationErr) - } - out := opts.IO.Out fmt.Fprintln(out) diff --git a/pkg/cmd/run/view/view_test.go b/pkg/cmd/run/view/view_test.go index 86aab619b..ac318b0c9 100644 --- a/pkg/cmd/run/view/view_test.go +++ b/pkg/cmd/run/view/view_test.go @@ -1279,6 +1279,40 @@ func TestViewRun(t *testing.T) { }, wantOut: "fetched 5 jobs\n", }, + { + name: "Returns error when failing to get annotations", + opts: &ViewOptions{ + RunID: "1234", + ExitStatus: true, + }, + httpStubs: func(reg *httpmock.Registry) { + reg.Register( + httpmock.REST("GET", "repos/OWNER/REPO/actions/runs/1234"), + httpmock.JSONResponse(shared.FailedRun)) + reg.Register( + httpmock.REST("GET", "repos/OWNER/REPO/actions/workflows/123"), + httpmock.JSONResponse(shared.TestWorkflow)) + reg.Register( + httpmock.REST("GET", "repos/OWNER/REPO/actions/runs/1234/artifacts"), + httpmock.StringResponse(`{}`)) + reg.Register( + httpmock.GraphQL(`query PullRequestForRun`), + httpmock.StringResponse(``)) + reg.Register( + httpmock.REST("GET", "runs/1234/jobs"), + httpmock.JSONResponse(shared.JobsPayload{ + Jobs: []shared.Job{ + shared.FailedJob, + }, + })) + reg.Register( + httpmock.REST("GET", "repos/OWNER/REPO/check-runs/20/annotations"), + httpmock.StatusStringResponse(500, "internal server error"), + ) + }, + errMsg: "failed to get annotations: HTTP 500 (https://api.github.com/repos/OWNER/REPO/check-runs/20/annotations)", + wantErr: true, + }, } for _, tt := range tests {