Skip to content

Commit

Permalink
Merge pull request #8301 from cli/wm/minor-annotation-fetch-error-sim…
Browse files Browse the repository at this point in the history
…plification

Simplify run view annotation fetch error handling
  • Loading branch information
williammartin committed Nov 6, 2023
2 parents ccf45cc + 8364301 commit 515b854
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 12 deletions.
15 changes: 3 additions & 12 deletions pkg/cmd/run/view/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
34 changes: 34 additions & 0 deletions pkg/cmd/run/view/view_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 515b854

Please sign in to comment.