diff options
Diffstat (limited to 'modules')
-rw-r--r-- | modules/notification/base/notifier.go | 3 | ||||
-rw-r--r-- | modules/notification/base/null.go | 12 | ||||
-rw-r--r-- | modules/notification/notification.go | 21 | ||||
-rw-r--r-- | modules/notification/webhook/webhook.go | 38 | ||||
-rw-r--r-- | modules/structs/hook.go | 33 |
5 files changed, 107 insertions, 0 deletions
diff --git a/modules/notification/base/notifier.go b/modules/notification/base/notifier.go index 541731ddbf..d6cec92e19 100644 --- a/modules/notification/base/notifier.go +++ b/modules/notification/base/notifier.go @@ -45,6 +45,9 @@ type Notifier interface { issue *issues_model.Issue, comment *issues_model.Comment, mentions []*user_model.User) NotifyUpdateComment(*user_model.User, *issues_model.Comment, string) NotifyDeleteComment(*user_model.User, *issues_model.Comment) + NotifyNewWikiPage(doer *user_model.User, repo *repo_model.Repository, page, comment string) + NotifyEditWikiPage(doer *user_model.User, repo *repo_model.Repository, page, comment string) + NotifyDeleteWikiPage(doer *user_model.User, repo *repo_model.Repository, page string) NotifyNewRelease(rel *repo_model.Release) NotifyUpdateRelease(doer *user_model.User, rel *repo_model.Release) NotifyDeleteRelease(doer *user_model.User, rel *repo_model.Release) diff --git a/modules/notification/base/null.go b/modules/notification/base/null.go index 4f382b3d01..b113ae79e1 100644 --- a/modules/notification/base/null.go +++ b/modules/notification/base/null.go @@ -78,6 +78,18 @@ func (*NullNotifier) NotifyUpdateComment(doer *user_model.User, c *issues_model. func (*NullNotifier) NotifyDeleteComment(doer *user_model.User, c *issues_model.Comment) { } +// NotifyNewWikiPage places a place holder function +func (*NullNotifier) NotifyNewWikiPage(doer *user_model.User, repo *repo_model.Repository, page, comment string) { +} + +// NotifyEditWikiPage places a place holder function +func (*NullNotifier) NotifyEditWikiPage(doer *user_model.User, repo *repo_model.Repository, page, comment string) { +} + +// NotifyDeleteWikiPage places a place holder function +func (*NullNotifier) NotifyDeleteWikiPage(doer *user_model.User, repo *repo_model.Repository, page string) { +} + // NotifyNewRelease places a place holder function func (*NullNotifier) NotifyNewRelease(rel *repo_model.Release) { } diff --git a/modules/notification/notification.go b/modules/notification/notification.go index 713cc72aac..693c7f5c22 100644 --- a/modules/notification/notification.go +++ b/modules/notification/notification.go @@ -40,6 +40,27 @@ func NewContext() { RegisterNotifier(mirror.NewNotifier()) } +// NotifyNewWikiPage notifies creating new wiki pages to notifiers +func NotifyNewWikiPage(doer *user_model.User, repo *repo_model.Repository, page, comment string) { + for _, notifier := range notifiers { + notifier.NotifyNewWikiPage(doer, repo, page, comment) + } +} + +// NotifyEditWikiPage notifies editing or renaming wiki pages to notifiers +func NotifyEditWikiPage(doer *user_model.User, repo *repo_model.Repository, page, comment string) { + for _, notifier := range notifiers { + notifier.NotifyEditWikiPage(doer, repo, page, comment) + } +} + +// NotifyDeleteWikiPage notifies deleting wiki pages to notifiers +func NotifyDeleteWikiPage(doer *user_model.User, repo *repo_model.Repository, page string) { + for _, notifier := range notifiers { + notifier.NotifyDeleteWikiPage(doer, repo, page) + } +} + // NotifyCreateIssueComment notifies issue comment related message to notifiers func NotifyCreateIssueComment(doer *user_model.User, repo *repo_model.Repository, issue *issues_model.Issue, comment *issues_model.Comment, mentions []*user_model.User, diff --git a/modules/notification/webhook/webhook.go b/modules/notification/webhook/webhook.go index ed3b53e3e7..0eb2099a20 100644 --- a/modules/notification/webhook/webhook.go +++ b/modules/notification/webhook/webhook.go @@ -501,6 +501,44 @@ func (m *webhookNotifier) NotifyDeleteComment(doer *user_model.User, comment *is } } +func (m *webhookNotifier) NotifyNewWikiPage(doer *user_model.User, repo *repo_model.Repository, page, comment string) { + // Add to hook queue for created wiki page. + if err := webhook_services.PrepareWebhooks(repo, webhook.HookEventWiki, &api.WikiPayload{ + Action: api.HookWikiCreated, + Repository: convert.ToRepo(repo, perm.AccessModeOwner), + Sender: convert.ToUser(doer, nil), + Page: page, + Comment: comment, + }); err != nil { + log.Error("PrepareWebhooks [repo_id: %d]: %v", repo.ID, err) + } +} + +func (m *webhookNotifier) NotifyEditWikiPage(doer *user_model.User, repo *repo_model.Repository, page, comment string) { + // Add to hook queue for edit wiki page. + if err := webhook_services.PrepareWebhooks(repo, webhook.HookEventWiki, &api.WikiPayload{ + Action: api.HookWikiEdited, + Repository: convert.ToRepo(repo, perm.AccessModeOwner), + Sender: convert.ToUser(doer, nil), + Page: page, + Comment: comment, + }); err != nil { + log.Error("PrepareWebhooks [repo_id: %d]: %v", repo.ID, err) + } +} + +func (m *webhookNotifier) NotifyDeleteWikiPage(doer *user_model.User, repo *repo_model.Repository, page string) { + // Add to hook queue for edit wiki page. + if err := webhook_services.PrepareWebhooks(repo, webhook.HookEventWiki, &api.WikiPayload{ + Action: api.HookWikiDeleted, + Repository: convert.ToRepo(repo, perm.AccessModeOwner), + Sender: convert.ToUser(doer, nil), + Page: page, + }); err != nil { + log.Error("PrepareWebhooks [repo_id: %d]: %v", repo.ID, err) + } +} + func (m *webhookNotifier) NotifyIssueChangeLabels(doer *user_model.User, issue *issues_model.Issue, addedLabels, removedLabels []*issues_model.Label, ) { diff --git a/modules/structs/hook.go b/modules/structs/hook.go index 07d51915de..132b24b856 100644 --- a/modules/structs/hook.go +++ b/modules/structs/hook.go @@ -397,6 +397,39 @@ type ReviewPayload struct { Content string `json:"content"` } +// __ __.__ __ .__ +// / \ / \__| | _|__| +// \ \/\/ / | |/ / | +// \ /| | <| | +// \__/\ / |__|__|_ \__| +// \/ \/ + +// HookWikiAction an action that happens to a wiki page +type HookWikiAction string + +const ( + // HookWikiCreated created + HookWikiCreated HookWikiAction = "created" + // HookWikiEdited edited + HookWikiEdited HookWikiAction = "edited" + // HookWikiDeleted deleted + HookWikiDeleted HookWikiAction = "deleted" +) + +// WikiPayload payload for repository webhooks +type WikiPayload struct { + Action HookWikiAction `json:"action"` + Repository *Repository `json:"repository"` + Sender *User `json:"sender"` + Page string `json:"page"` + Comment string `json:"comment"` +} + +// JSONPayload JSON representation of the payload +func (p *WikiPayload) JSONPayload() ([]byte, error) { + return json.MarshalIndent(p, "", " ") +} + //__________ .__ __ //\______ \ ____ ______ ____ _____|__|/ |_ ___________ ___.__. // | _// __ \\____ \ / _ \/ ___/ \ __\/ _ \_ __ < | | |