Skip to content

Commit 1290d0e

Browse files
authored
ignore 404 on ListFiles call (#24)
1 parent 625a2e6 commit 1290d0e

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

pkg/checkmate/commenter.go

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

33
import (
44
"context"
5+
"errors"
6+
"net/http"
57
"sort"
68
"strings"
79

@@ -138,6 +140,9 @@ func updateComment(ctx context.Context, action *githubactions.Action, cfg Config
138140

139141
func listPullRequestFiles(ctx context.Context, pr pullrequest.Client) ([]string, error) {
140142
files, err := pr.ListFiles(ctx, nil)
143+
if isNotFoundError(err) {
144+
return nil, nil
145+
}
141146
if err != nil {
142147
return nil, err
143148
}
@@ -161,3 +166,13 @@ func sorted(ss []string) []string {
161166
func join(s ...string) string {
162167
return strings.Join(s[:len(s)-1], s[len(s)-1])
163168
}
169+
170+
func isNotFoundError(err error) bool {
171+
ghe := new(github.ErrorResponse)
172+
if errors.As(err, &ghe) {
173+
if ghe.Response.StatusCode == http.StatusNotFound {
174+
return true
175+
}
176+
}
177+
return false
178+
}

pkg/checkmate/commenter_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,22 @@ func Test_commenter(t *testing.T) {
6565
assert.NoError(t, err)
6666
})
6767

68+
t.Run("IssueCommentHasNoFiles", func(t *testing.T) {
69+
action, _ := setupAction("issue-comment.created")
70+
ghMockAPI := mock.NewMockedHTTPClient(
71+
mock.WithRequestMatchHandler(
72+
mock.GetReposPullsFilesByOwnerByRepoByPullNumber,
73+
http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
74+
mock.WriteError(w, http.StatusNotFound, "Not Found")
75+
}),
76+
))
77+
78+
pr, err := pullrequest.NewClient(action, github.NewClient(ghMockAPI))
79+
assert.NoError(t, err)
80+
_, err = commenter(ctx, cfg, action, pr)
81+
assert.NoError(t, err)
82+
})
83+
6884
t.Run("MatchingFilesNoExistingComment", func(t *testing.T) {
6985
action, _ := setupAction("pull-request.edited")
7086
ghMockAPI := mock.NewMockedHTTPClient(

0 commit comments

Comments
 (0)