From f66c3c48f9fba5be1a635dee67d0008146dc0100 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Sat, 17 Feb 2024 16:04:48 +0800 Subject: [PATCH] Fix issue_comment actions not triggered for pull request --- modules/actions/github.go | 5 +++++ modules/actions/github_test.go | 6 ++++++ services/actions/notifier_helper.go | 3 ++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/modules/actions/github.go b/modules/actions/github.go index fafea4e11a805..2107178ad8d8a 100644 --- a/modules/actions/github.go +++ b/modules/actions/github.go @@ -73,6 +73,11 @@ func canGithubEventMatch(eventName string, triggedEvent webhook_module.HookEvent case GithubEventSchedule: return triggedEvent == webhook_module.HookEventSchedule + case GithubEventIssueComment: + // https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request_comment-use-issue_comment + return triggedEvent == webhook_module.HookEventIssueComment || + triggedEvent == webhook_module.HookEventPullRequestComment + default: return eventName == string(triggedEvent) } diff --git a/modules/actions/github_test.go b/modules/actions/github_test.go index 4bf55ae03fccd..6652ff6eac22e 100644 --- a/modules/actions/github_test.go +++ b/modules/actions/github_test.go @@ -103,6 +103,12 @@ func TestCanGithubEventMatch(t *testing.T) { webhook_module.HookEventCreate, true, }, + { + "create pull request comment", + GithubEventIssueComment, + webhook_module.HookEventPullRequestComment, + true, + }, } for _, tc := range testCases { diff --git a/services/actions/notifier_helper.go b/services/actions/notifier_helper.go index 8852f23c5f713..8a3a381161c3f 100644 --- a/services/actions/notifier_helper.go +++ b/services/actions/notifier_helper.go @@ -201,7 +201,8 @@ func notify(ctx context.Context, input *notifyInput) error { log.Trace("repo %s with commit %s couldn't find pull_request_target workflows", input.Repo.RepoPath(), baseCommit.ID) } else { for _, wf := range baseWorkflows { - if wf.TriggerEvent.Name == actions_module.GithubEventPullRequestTarget { + if wf.TriggerEvent.Name == actions_module.GithubEventPullRequestTarget || + wf.TriggerEvent.Name == actions_module.GithubEventIssueComment { detectedWorkflows = append(detectedWorkflows, wf) } }