Skip to content

Commit 70e6366

Browse files
authored
handle non pr issue comments (#16)
1 parent e414bdf commit 70e6366

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

pkg/checkmate/action.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,12 @@ func inspect(checklists []Checklist, action *githubactions.Action) error {
7272
}
7373

7474
func getPullRequestBody(ghctx *githubactions.GitHubContext) (string, error) {
75-
body, ok := ghctx.Event["pull_request"].(map[string]any)["body"]
75+
pullRequest, ok := ghctx.Event["pull_request"]
76+
if !ok {
77+
return "", nil
78+
}
79+
80+
body, ok := pullRequest.(map[string]any)["body"]
7681
if !ok || body == nil {
7782
return "", nil
7883
}

pkg/checkmate/action_test.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,34 @@ import (
1313

1414
func TestRun(t *testing.T) {
1515
t.Run("CheckedSuccess", func(t *testing.T) {
16-
action, _ := setupAction("edited-checked")
16+
action, _ := setupAction("pull-request.edited-checked")
1717
err := Run(context.Background(), new(Config), action, nil)
1818
assert.NoError(t, err)
1919
})
2020

2121
t.Run("UncheckedFailure", func(t *testing.T) {
22-
action, _ := setupAction("edited")
22+
action, _ := setupAction("pull-request.edited")
2323
err := Run(context.Background(), new(Config), action, nil)
2424
require.Error(t, err)
2525
assert.Equal(t, "not all checklists are completed", err.Error())
2626
})
2727

2828
t.Run("OpenedWithNullBody", func(t *testing.T) {
29-
action, _ := setupAction("opened.with-null-body")
29+
action, _ := setupAction("pull-request.opened.with-null-body")
30+
err := Run(context.Background(), new(Config), action, nil)
31+
assert.NoError(t, err)
32+
})
33+
34+
t.Run("IssueComment", func(t *testing.T) {
35+
action, _ := setupAction("issue-comment.created")
3036
err := Run(context.Background(), new(Config), action, nil)
3137
assert.NoError(t, err)
3238
})
3339
}
3440

3541
func setupAction(input string) (*githubactions.Action, *bytes.Buffer) {
3642
envMap := map[string]string{
37-
"GITHUB_EVENT_PATH": fmt.Sprintf("../../test/events/pull-request.%s.json", input),
43+
"GITHUB_EVENT_PATH": fmt.Sprintf("../../test/events/%s.json", input),
3844
"GITHUB_STEP_SUMMARY": "/dev/null",
3945
"GITHUB_REPOSITORY": "RoryQ/checkmate",
4046
}

pkg/checkmate/commenter_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func Test_commenter(t *testing.T) {
4949
assetsChecklist := cfg.PathsChecklists[assetsGlob].ToChecklistItemsMD(assetsGlob)
5050

5151
t.Run("NoMatchingFiles", func(t *testing.T) {
52-
action, _ := setupAction("edited")
52+
action, _ := setupAction("pull-request.edited")
5353
ghMockAPI := mock.NewMockedHTTPClient(
5454
mock.WithRequestMatch(
5555
mock.GetReposPullsFilesByOwnerByRepoByPullNumber,
@@ -66,7 +66,7 @@ func Test_commenter(t *testing.T) {
6666
})
6767

6868
t.Run("MatchingFilesNoExistingComment", func(t *testing.T) {
69-
action, _ := setupAction("edited")
69+
action, _ := setupAction("pull-request.edited")
7070
ghMockAPI := mock.NewMockedHTTPClient(
7171
mock.WithRequestMatch(
7272
mock.GetReposPullsFilesByOwnerByRepoByPullNumber,
@@ -103,7 +103,7 @@ func Test_commenter(t *testing.T) {
103103
})
104104

105105
t.Run("MatchingFilesForSelectList", func(t *testing.T) {
106-
action, _ := setupAction("edited")
106+
action, _ := setupAction("pull-request.edited")
107107
ghMockAPI := mock.NewMockedHTTPClient(
108108
mock.WithRequestMatch(
109109
mock.GetReposPullsFilesByOwnerByRepoByPullNumber,
@@ -141,7 +141,7 @@ func Test_commenter(t *testing.T) {
141141
})
142142

143143
t.Run("MatchingFilesWithExistingComment", func(t *testing.T) {
144-
action, _ := setupAction("edited")
144+
action, _ := setupAction("pull-request.edited")
145145
ghMockAPI := mock.NewMockedHTTPClient(
146146
mock.WithRequestMatch(
147147
mock.GetReposPullsFilesByOwnerByRepoByPullNumber,
@@ -168,7 +168,7 @@ func Test_commenter(t *testing.T) {
168168
})
169169

170170
t.Run("MatchingFilesWithExistingCommentAndChangedFiles", func(t *testing.T) {
171-
action, _ := setupAction("edited")
171+
action, _ := setupAction("pull-request.edited")
172172
schemaChecked := strings.ReplaceAll(schemaMigrationsChecklist, "[ ]", "[x]")
173173
ghMockAPI := mock.NewMockedHTTPClient(
174174
mock.WithRequestMatch(

0 commit comments

Comments
 (0)