Skip to content

Commit 00da7f9

Browse files
committed
handle 404 for annotations
1 parent ac0fe6b commit 00da7f9

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

pkg/cmd/run/shared/shared.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package shared
22

33
import (
44
"archive/zip"
5+
"errors"
56
"fmt"
67
"net/url"
78
"strings"
@@ -133,6 +134,11 @@ func GetAnnotations(client *api.Client, repo ghrepo.Interface, job Job) ([]Annot
133134

134135
err := client.REST(repo.RepoHost(), "GET", path, nil, &result)
135136
if err != nil {
137+
var notFound *api.NotFoundError
138+
if !errors.As(err, &notFound) {
139+
return []Annotation{}, nil
140+
}
141+
136142
return nil, err
137143
}
138144

pkg/cmd/run/shared/shared_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
package shared
22

33
import (
4+
"net/http"
45
"testing"
56
"time"
7+
8+
"github.com/cli/cli/api"
9+
"github.com/cli/cli/internal/ghrepo"
10+
"github.com/cli/cli/pkg/httpmock"
11+
"github.com/stretchr/testify/assert"
612
)
713

814
func TestPreciseAgo(t *testing.T) {
@@ -29,3 +35,20 @@ func TestPreciseAgo(t *testing.T) {
2935
}
3036
}
3137
}
38+
39+
func TestGetAnnotations404(t *testing.T) {
40+
reg := &httpmock.Registry{}
41+
defer reg.Verify(t)
42+
43+
reg.Register(
44+
httpmock.REST("GET", "repos/OWNER/REPO/check-runs/123456/annotations"),
45+
httpmock.StatusStringResponse(404, "not found"))
46+
47+
httpClient := &http.Client{Transport: reg}
48+
apiClient := api.NewClientFromHTTP(httpClient)
49+
repo := ghrepo.New("OWNER", "REPO")
50+
51+
result, err := GetAnnotations(apiClient, repo, Job{ID: 123456, Name: "a job"})
52+
assert.NoError(t, err)
53+
assert.Equal(t, result, []Annotation{})
54+
}

0 commit comments

Comments
 (0)