Skip to content

Commit 5eb4c63

Browse files
authored
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)
1 parent 4014200 commit 5eb4c63

File tree

4 files changed

+47
-2
lines changed

4 files changed

+47
-2
lines changed

modules/actions/github.go

+5
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const (
2121
githubEventIssueComment = "issue_comment"
2222
githubEventRelease = "release"
2323
githubEventPullRequestComment = "pull_request_comment"
24+
githubEventGollum = "gollum"
2425
)
2526

2627
// canGithubEventMatch check if the input Github event can match any Gitea event.
@@ -29,6 +30,10 @@ func canGithubEventMatch(eventName string, triggedEvent webhook_module.HookEvent
2930
case githubEventRegistryPackage:
3031
return triggedEvent == webhook_module.HookEventPackage
3132

33+
// See https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#gollum
34+
case githubEventGollum:
35+
return triggedEvent == webhook_module.HookEventWiki
36+
3237
case githubEventIssues:
3338
switch triggedEvent {
3439
case webhook_module.HookEventIssues,

modules/actions/workflows.go

-2
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,6 @@ func detectMatched(commit *git.Commit, triggedEvent webhook_module.HookEventType
119119
webhook_module.HookEventCreate,
120120
webhook_module.HookEventDelete,
121121
webhook_module.HookEventFork,
122-
// FIXME: `wiki` event should match `gollum` event
123-
// See https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#gollum
124122
webhook_module.HookEventWiki:
125123
if len(evt.Acts()) != 0 {
126124
log.Warn("Ignore unsupported %s event arguments %v", triggedEvent, evt.Acts())

modules/actions/workflows_test.go

+7
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,13 @@ func TestDetectMatched(t *testing.T) {
9292
yamlOn: "on:\n registry_package:\n types: [updated]",
9393
expected: false,
9494
},
95+
{
96+
desc: "HookEventWiki(wiki) matches githubEventGollum(gollum)",
97+
triggedEvent: webhook_module.HookEventWiki,
98+
payload: nil,
99+
yamlOn: "on: gollum",
100+
expected: true,
101+
},
95102
}
96103

97104
for _, tc := range testCases {

services/actions/notifier.go

+35
Original file line numberDiff line numberDiff line change
@@ -526,3 +526,38 @@ func (n *actionsNotifier) NotifyPullRequestChangeTargetBranch(ctx context.Contex
526526
WithPullRequest(pr).
527527
Notify(ctx)
528528
}
529+
530+
func (n *actionsNotifier) NotifyNewWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, page, comment string) {
531+
ctx = withMethod(ctx, "NotifyNewWikiPage")
532+
533+
newNotifyInput(repo, doer, webhook_module.HookEventWiki).WithPayload(&api.WikiPayload{
534+
Action: api.HookWikiCreated,
535+
Repository: convert.ToRepo(ctx, repo, perm_model.AccessModeOwner),
536+
Sender: convert.ToUser(ctx, doer, nil),
537+
Page: page,
538+
Comment: comment,
539+
}).Notify(ctx)
540+
}
541+
542+
func (n *actionsNotifier) NotifyEditWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, page, comment string) {
543+
ctx = withMethod(ctx, "NotifyEditWikiPage")
544+
545+
newNotifyInput(repo, doer, webhook_module.HookEventWiki).WithPayload(&api.WikiPayload{
546+
Action: api.HookWikiEdited,
547+
Repository: convert.ToRepo(ctx, repo, perm_model.AccessModeOwner),
548+
Sender: convert.ToUser(ctx, doer, nil),
549+
Page: page,
550+
Comment: comment,
551+
}).Notify(ctx)
552+
}
553+
554+
func (n *actionsNotifier) NotifyDeleteWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, page string) {
555+
ctx = withMethod(ctx, "NotifyDeleteWikiPage")
556+
557+
newNotifyInput(repo, doer, webhook_module.HookEventWiki).WithPayload(&api.WikiPayload{
558+
Action: api.HookWikiDeleted,
559+
Repository: convert.ToRepo(ctx, repo, perm_model.AccessModeOwner),
560+
Sender: convert.ToUser(ctx, doer, nil),
561+
Page: page,
562+
}).Notify(ctx)
563+
}

0 commit comments

Comments
 (0)