summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZettat123 <zettat123@gmail.com>2023-04-18 01:49:47 +0800
committerGitHub <noreply@github.com>2023-04-17 13:49:47 -0400
commit5eb4c6386709259a9280c5aad6e0488f381144c5 (patch)
tree8c0b8f1200b6ee10c3d32ba8637daeec95d56fb6
parent4014200021a1997283c779a815fe9e5febf1fda1 (diff)
downloadgitea-5eb4c6386709259a9280c5aad6e0488f381144c5.tar.gz
gitea-5eb4c6386709259a9280c5aad6e0488f381144c5.zip
Support triggering workflows by wiki related events (#24119)
This PR is to support triggering workflows by wiki related events like creating, editing or deleting wiki pages. In GitHub, this event is called [gollum](https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#gollum)
-rw-r--r--modules/actions/github.go5
-rw-r--r--modules/actions/workflows.go2
-rw-r--r--modules/actions/workflows_test.go7
-rw-r--r--services/actions/notifier.go35
4 files changed, 47 insertions, 2 deletions
diff --git a/modules/actions/github.go b/modules/actions/github.go
index 1148554139..f3cb335da9 100644
--- a/modules/actions/github.go
+++ b/modules/actions/github.go
@@ -21,6 +21,7 @@ const (
githubEventIssueComment = "issue_comment"
githubEventRelease = "release"
githubEventPullRequestComment = "pull_request_comment"
+ githubEventGollum = "gollum"
)
// canGithubEventMatch check if the input Github event can match any Gitea event.
@@ -29,6 +30,10 @@ func canGithubEventMatch(eventName string, triggedEvent webhook_module.HookEvent
case githubEventRegistryPackage:
return triggedEvent == webhook_module.HookEventPackage
+ // See https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#gollum
+ case githubEventGollum:
+ return triggedEvent == webhook_module.HookEventWiki
+
case githubEventIssues:
switch triggedEvent {
case webhook_module.HookEventIssues,
diff --git a/modules/actions/workflows.go b/modules/actions/workflows.go
index d21dc1d809..f37f4f2878 100644
--- a/modules/actions/workflows.go
+++ b/modules/actions/workflows.go
@@ -119,8 +119,6 @@ func detectMatched(commit *git.Commit, triggedEvent webhook_module.HookEventType
webhook_module.HookEventCreate,
webhook_module.HookEventDelete,
webhook_module.HookEventFork,
- // FIXME: `wiki` event should match `gollum` event
- // See https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#gollum
webhook_module.HookEventWiki:
if len(evt.Acts()) != 0 {
log.Warn("Ignore unsupported %s event arguments %v", triggedEvent, evt.Acts())
diff --git a/modules/actions/workflows_test.go b/modules/actions/workflows_test.go
index 6724abafd8..6ef5d59942 100644
--- a/modules/actions/workflows_test.go
+++ b/modules/actions/workflows_test.go
@@ -92,6 +92,13 @@ func TestDetectMatched(t *testing.T) {
yamlOn: "on:\n registry_package:\n types: [updated]",
expected: false,
},
+ {
+ desc: "HookEventWiki(wiki) matches githubEventGollum(gollum)",
+ triggedEvent: webhook_module.HookEventWiki,
+ payload: nil,
+ yamlOn: "on: gollum",
+ expected: true,
+ },
}
for _, tc := range testCases {
diff --git a/services/actions/notifier.go b/services/actions/notifier.go
index 6956c25cee..4ac77276ff 100644
--- a/services/actions/notifier.go
+++ b/services/actions/notifier.go
@@ -526,3 +526,38 @@ func (n *actionsNotifier) NotifyPullRequestChangeTargetBranch(ctx context.Contex
WithPullRequest(pr).
Notify(ctx)
}
+
+func (n *actionsNotifier) NotifyNewWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, page, comment string) {
+ ctx = withMethod(ctx, "NotifyNewWikiPage")
+
+ newNotifyInput(repo, doer, webhook_module.HookEventWiki).WithPayload(&api.WikiPayload{
+ Action: api.HookWikiCreated,
+ Repository: convert.ToRepo(ctx, repo, perm_model.AccessModeOwner),
+ Sender: convert.ToUser(ctx, doer, nil),
+ Page: page,
+ Comment: comment,
+ }).Notify(ctx)
+}
+
+func (n *actionsNotifier) NotifyEditWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, page, comment string) {
+ ctx = withMethod(ctx, "NotifyEditWikiPage")
+
+ newNotifyInput(repo, doer, webhook_module.HookEventWiki).WithPayload(&api.WikiPayload{
+ Action: api.HookWikiEdited,
+ Repository: convert.ToRepo(ctx, repo, perm_model.AccessModeOwner),
+ Sender: convert.ToUser(ctx, doer, nil),
+ Page: page,
+ Comment: comment,
+ }).Notify(ctx)
+}
+
+func (n *actionsNotifier) NotifyDeleteWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, page string) {
+ ctx = withMethod(ctx, "NotifyDeleteWikiPage")
+
+ newNotifyInput(repo, doer, webhook_module.HookEventWiki).WithPayload(&api.WikiPayload{
+ Action: api.HookWikiDeleted,
+ Repository: convert.ToRepo(ctx, repo, perm_model.AccessModeOwner),
+ Sender: convert.ToUser(ctx, doer, nil),
+ Page: page,
+ }).Notify(ctx)
+}