Skip to content

Commit

Permalink
feat: handle pull_request_review events
Browse files Browse the repository at this point in the history
  • Loading branch information
aeddi committed Dec 8, 2024
1 parent f491d95 commit 4f7b0b8
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 2 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/bot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ on:
- converted_to_draft
- ready_for_review

# Watch for changes on PR reviews
pull_request_review:
types: [submitted, edited, dismissed]

# Watch for changes on PR comment
issue_comment:
types: [created, edited, deleted]
Expand Down
2 changes: 1 addition & 1 deletion contribs/github-bot/internal/matrix/matrix.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func getPRListFromEvent(gh *client.GitHub, actionCtx *githubactions.GitHubContex

// Event triggered by an issue / PR comment being created / edited / deleted
// or any update on a PR.
case utils.EventIssueComment, utils.EventPullRequest, utils.EventPullRequestTarget:
case utils.EventIssueComment, utils.EventPullRequest, utils.EventPullRequestReview, utils.EventPullRequestTarget:
// For these events, retrieve the number of the associated PR from the context.
prNum, err := utils.GetPRNumFromActionsCtx(actionCtx)
if err != nil {
Expand Down
9 changes: 9 additions & 0 deletions contribs/github-bot/internal/matrix/matrix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ func TestProcessEvent(t *testing.T) {
prs,
utils.PRList{1},
false,
}, {
"valid pull_request_review event",
&githubactions.GitHubContext{
EventName: utils.EventPullRequestReview,
Event: map[string]any{"pull_request": map[string]any{"number": 1.}},
},
prs,
utils.PRList{1},
false,
}, {
"valid pull_request_target event",
&githubactions.GitHubContext{
Expand Down
2 changes: 1 addition & 1 deletion contribs/github-bot/internal/utils/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func GetPRNumFromActionsCtx(actionCtx *githubactions.GitHubContext) (int, error)
switch actionCtx.EventName {
case EventIssueComment:
firstKey = "issue"
case EventPullRequest, EventPullRequestTarget:
case EventPullRequest, EventPullRequestReview, EventPullRequestTarget:

Check warning on line 33 in contribs/github-bot/internal/utils/actions.go

View check run for this annotation

Codecov / codecov/patch

contribs/github-bot/internal/utils/actions.go#L33

Added line #L33 was not covered by tests
firstKey = "pull_request"
default:
return 0, fmt.Errorf("unsupported event: %s", actionCtx.EventName)
Expand Down
1 change: 1 addition & 0 deletions contribs/github-bot/internal/utils/github_const.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const (
// GitHub Actions Event Names.
EventIssueComment = "issue_comment"
EventPullRequest = "pull_request"
EventPullRequestReview = "pull_request_review"
EventPullRequestTarget = "pull_request_target"
EventWorkflowDispatch = "workflow_dispatch"

Expand Down

0 comments on commit 4f7b0b8

Please sign in to comment.