From 00da7f9fc1244dcdac71e613d703fbe412e3e861 Mon Sep 17 00:00:00 2001 From: vilmibm Date: Mon, 26 Apr 2021 16:55:08 -0500 Subject: [PATCH] handle 404 for annotations --- pkg/cmd/run/shared/shared.go | 6 ++++++ pkg/cmd/run/shared/shared_test.go | 23 +++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/pkg/cmd/run/shared/shared.go b/pkg/cmd/run/shared/shared.go index d0e2c131d..afd926114 100644 --- a/pkg/cmd/run/shared/shared.go +++ b/pkg/cmd/run/shared/shared.go @@ -2,6 +2,7 @@ package shared import ( "archive/zip" + "errors" "fmt" "net/url" "strings" @@ -133,6 +134,11 @@ func GetAnnotations(client *api.Client, repo ghrepo.Interface, job Job) ([]Annot err := client.REST(repo.RepoHost(), "GET", path, nil, &result) if err != nil { + var notFound *api.NotFoundError + if !errors.As(err, ¬Found) { + return []Annotation{}, nil + } + return nil, err } diff --git a/pkg/cmd/run/shared/shared_test.go b/pkg/cmd/run/shared/shared_test.go index bd6e73962..0b7cf8db1 100644 --- a/pkg/cmd/run/shared/shared_test.go +++ b/pkg/cmd/run/shared/shared_test.go @@ -1,8 +1,14 @@ package shared import ( + "net/http" "testing" "time" + + "github.com/cli/cli/api" + "github.com/cli/cli/internal/ghrepo" + "github.com/cli/cli/pkg/httpmock" + "github.com/stretchr/testify/assert" ) func TestPreciseAgo(t *testing.T) { @@ -29,3 +35,20 @@ func TestPreciseAgo(t *testing.T) { } } } + +func TestGetAnnotations404(t *testing.T) { + reg := &httpmock.Registry{} + defer reg.Verify(t) + + reg.Register( + httpmock.REST("GET", "repos/OWNER/REPO/check-runs/123456/annotations"), + httpmock.StatusStringResponse(404, "not found")) + + httpClient := &http.Client{Transport: reg} + apiClient := api.NewClientFromHTTP(httpClient) + repo := ghrepo.New("OWNER", "REPO") + + result, err := GetAnnotations(apiClient, repo, Job{ID: 123456, Name: "a job"}) + assert.NoError(t, err) + assert.Equal(t, result, []Annotation{}) +}