handle 404 for annotations
This commit is contained in:
parent
ac0fe6bf71
commit
00da7f9fc1
2 changed files with 29 additions and 0 deletions
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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{})
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue