Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify run view annotation fetch error handling #8301

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 3 additions & 12 deletions pkg/cmd/run/view/view.go
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
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