summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorAaron F <mail@aaron-fischer.net>2022-09-04 21:54:23 +0200
committerGitHub <noreply@github.com>2022-09-04 20:54:23 +0100
commit3963625b6ef6f4d4f16959466c077593a1f908db (patch)
treef509433e0ca198759452c54a65b943c28bd6e2c3 /models
parent8b0aaa5f86e40a4699f278d09d116add63f8e4a0 (diff)
downloadgitea-3963625b6ef6f4d4f16959466c077593a1f908db.tar.gz
gitea-3963625b6ef6f4d4f16959466c077593a1f908db.zip
Webhook for Wiki changes (#20219)
Add support for triggering webhook notifications on wiki changes. This PR contains frontend and backend for webhook notifications on wiki actions (create a new page, rename a page, edit a page and delete a page). The frontend got a new checkbox under the Custom Event -> Repository Events section. There is only one checkbox for create/edit/rename/delete actions, because it makes no sense to separate it and others like releases or packages follow the same schema. ![image](https://user-images.githubusercontent.com/121972/177018803-26851196-831f-4fde-9a4c-9e639b0e0d6b.png) The actions itself are separated, so that different notifications will be executed (with the "action" field). All the webhook receivers implement the new interface method (Wiki) and the corresponding tests. When implementing this, I encounter a little bug on editing a wiki page. Creating and editing a wiki page is technically the same action and will be handled by the ```updateWikiPage``` function. But the function need to know if it is a new wiki page or just a change. This distinction is done by the ```action``` parameter, but this will not be sent by the frontend (on form submit). This PR will fix this by adding the ```action``` parameter with the values ```_new``` or ```_edit```, which will be used by the ```updateWikiPage``` function. I've done integration tests with matrix and gitea (http). ![image](https://user-images.githubusercontent.com/121972/177018795-eb5cdc01-9ba3-483e-a6b7-ed0e313a71fb.png) Fix #16457 Signed-off-by: Aaron Fischer <mail@aaron-fischer.net>
Diffstat (limited to 'models')
-rw-r--r--models/webhook/hooktask.go3
-rw-r--r--models/webhook/webhook.go8
-rw-r--r--models/webhook/webhook_test.go2
3 files changed, 12 insertions, 1 deletions
diff --git a/models/webhook/hooktask.go b/models/webhook/hooktask.go
index 4415518cf0..2adfcaa60d 100644
--- a/models/webhook/hooktask.go
+++ b/models/webhook/hooktask.go
@@ -47,6 +47,7 @@ const (
HookEventPullRequestReviewRejected HookEventType = "pull_request_review_rejected"
HookEventPullRequestReviewComment HookEventType = "pull_request_review_comment"
HookEventPullRequestSync HookEventType = "pull_request_sync"
+ HookEventWiki HookEventType = "wiki"
HookEventRepository HookEventType = "repository"
HookEventRelease HookEventType = "release"
HookEventPackage HookEventType = "package"
@@ -76,6 +77,8 @@ func (h HookEventType) Event() string {
return "pull_request_rejected"
case HookEventPullRequestReviewComment:
return "pull_request_comment"
+ case HookEventWiki:
+ return "wiki"
case HookEventRepository:
return "repository"
case HookEventRelease:
diff --git a/models/webhook/webhook.go b/models/webhook/webhook.go
index 478a6a29ff..ac09220630 100644
--- a/models/webhook/webhook.go
+++ b/models/webhook/webhook.go
@@ -132,6 +132,7 @@ type HookEvents struct {
PullRequestComment bool `json:"pull_request_comment"`
PullRequestReview bool `json:"pull_request_review"`
PullRequestSync bool `json:"pull_request_sync"`
+ Wiki bool `json:"wiki"`
Repository bool `json:"repository"`
Release bool `json:"release"`
Package bool `json:"package"`
@@ -328,6 +329,12 @@ func (w *Webhook) HasPullRequestSyncEvent() bool {
(w.ChooseEvents && w.HookEvents.PullRequestSync)
}
+// HasWikiEvent returns true if hook enabled wiki event.
+func (w *Webhook) HasWikiEvent() bool {
+ return w.SendEverything ||
+ (w.ChooseEvents && w.HookEvent.Wiki)
+}
+
// HasReleaseEvent returns if hook enabled release event.
func (w *Webhook) HasReleaseEvent() bool {
return w.SendEverything ||
@@ -373,6 +380,7 @@ func (w *Webhook) EventCheckers() []struct {
{w.HasPullRequestRejectedEvent, HookEventPullRequestReviewRejected},
{w.HasPullRequestCommentEvent, HookEventPullRequestReviewComment},
{w.HasPullRequestSyncEvent, HookEventPullRequestSync},
+ {w.HasWikiEvent, HookEventWiki},
{w.HasRepositoryEvent, HookEventRepository},
{w.HasReleaseEvent, HookEventRelease},
{w.HasPackageEvent, HookEventPackage},
diff --git a/models/webhook/webhook_test.go b/models/webhook/webhook_test.go
index 1d77ee2a41..7ec7edc0b7 100644
--- a/models/webhook/webhook_test.go
+++ b/models/webhook/webhook_test.go
@@ -71,7 +71,7 @@ func TestWebhook_EventsArray(t *testing.T) {
"issues", "issue_assign", "issue_label", "issue_milestone", "issue_comment",
"pull_request", "pull_request_assign", "pull_request_label", "pull_request_milestone",
"pull_request_comment", "pull_request_review_approved", "pull_request_review_rejected",
- "pull_request_review_comment", "pull_request_sync", "repository", "release",
+ "pull_request_review_comment", "pull_request_sync", "wiki", "repository", "release",
"package",
},
(&Webhook{