Simplify run view annotation fetch error handling

This commit is contained in:
William Martin 2023-11-06 11:59:19 +01:00
parent ccf45cc7c6
commit 8364301017
2 changed files with 37 additions and 12 deletions

View file

@ -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)

View file

@ -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 {