Skip to content

Commit

Permalink
watch - handle annotation errors gracefully
Browse files Browse the repository at this point in the history
fixes cli#8842
  • Loading branch information
wingleung committed May 22, 2024
1 parent 105bafd commit 08ffb06
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/cmd/run/watch/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ func renderRun(out io.Writer, opts WatchOptions, client *api.Client, repo ghrepo
}

if annotationErr != nil {
return nil, fmt.Errorf("failed to get annotations: %w", annotationErr)
fmt.Printf("%s failed to get annotations: %s", cs.WarningIcon(), annotationErr)
}

fmt.Fprintln(out, shared.RenderRunHeader(cs, *run, text.FuzzyAgo(opts.Now(), run.StartedTime()), prNumber, 0))
Expand Down
34 changes: 34 additions & 0 deletions pkg/cmd/run/watch/watch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,40 @@ func TestWatchRun(t *testing.T) {
wantErr: true,
errMsg: "failed to get run: HTTP 404: run 1234 not found (https://api.github.com/repos/OWNER/REPO/actions/runs/1234?exclude_pull_requests=true)",
},
{
name: "annotation endpoint forbidden (fine grained tokens)",
tty: true,
opts: &WatchOptions{
RunID: "2",
},
httpStubs: func(reg *httpmock.Registry) {
inProgressRun := shared.TestRunWithCommit(2, shared.InProgress, "", "commit2")
completedRun := shared.TestRun(2, shared.Completed, shared.Success)
reg.Register(
httpmock.REST("GET", "repos/OWNER/REPO/actions/runs/2"),
httpmock.JSONResponse(inProgressRun))
reg.Register(
httpmock.REST("GET", "runs/2/jobs"),
httpmock.JSONResponse(shared.JobsPayload{
Jobs: []shared.Job{
shared.SuccessfulJob,
},
}))
reg.Register(
httpmock.REST("GET", "repos/OWNER/REPO/check-runs/10/annotations"),
httpmock.StatusStringResponse(403, "Forbidden"))
reg.Register(
httpmock.REST("GET", "repos/OWNER/REPO/actions/runs/2"),
httpmock.JSONResponse(completedRun))
reg.Register(
httpmock.REST("GET", "repos/OWNER/REPO/actions/workflows/123"),
httpmock.JSONResponse(shared.TestWorkflow))
reg.Register(
httpmock.REST("GET", "repos/OWNER/REPO/actions/workflows/123"),
httpmock.JSONResponse(shared.TestWorkflow))
},
wantOut: "\x1b[?1049h\x1b[?1049l✓ trunk CI · 2\nTriggered via push about 59 minutes ago\n\nJOBS\n✓ cool job in 4m34s (ID 10)\n ✓ fob the barz\n ✓ barz the fob\n\n✓ Run CI (2) completed with 'success'\n",
},
}

for _, tt := range tests {
Expand Down

0 comments on commit 08ffb06

Please sign in to comment.