summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorJames Lakin <jamesorlakin@users.noreply.github.com>2020-10-02 09:37:46 +0000
committerGitHub <noreply@github.com>2020-10-02 10:37:46 +0100
commit6fc129fe62d12cf702397ae9bc55778ac3abd997 (patch)
tree19ab8ba03422bdb1a9ca635b875a6fb7cdee112b /modules
parent77f3dbed6d97ed34ab85865b4fbc8365ae19f535 (diff)
downloadgitea-6fc129fe62d12cf702397ae9bc55778ac3abd997.tar.gz
gitea-6fc129fe62d12cf702397ae9bc55778ac3abd997.zip
Fix repository create/delete event webhooks (#13008)
This small PR changes the webhook trigger behaviour to be more in line with what's expected. (When 'repository' events are enabled, of course) In other words: For system-wide or default webhooks, repository events will now trigger said webhook. Previously it had to be under an organization for create events to be visible - a tad unexpected! Deleting a repository will now fire its own defined webhooks, not just organisational and system ones. In order to enable the latter the webhook has to now be triggered before the actual repo undergoes deletion. I'm willing to tweak this to try and 'grab' the webhook model beforehand and trigger the webhook notifier directly afterwards, but this may make the code more complex for little benefit. Closes #11766, #9180.
Diffstat (limited to 'modules')
-rw-r--r--modules/notification/webhook/webhook.go32
1 files changed, 14 insertions, 18 deletions
diff --git a/modules/notification/webhook/webhook.go b/modules/notification/webhook/webhook.go
index 625cf119a9..c8b6bae724 100644
--- a/modules/notification/webhook/webhook.go
+++ b/modules/notification/webhook/webhook.go
@@ -99,30 +99,26 @@ func (m *webhookNotifier) NotifyForkRepository(doer *models.User, oldRepo, repo
func (m *webhookNotifier) NotifyCreateRepository(doer *models.User, u *models.User, repo *models.Repository) {
// Add to hook queue for created repo after session commit.
- if u.IsOrganization() {
- if err := webhook_module.PrepareWebhooks(repo, models.HookEventRepository, &api.RepositoryPayload{
- Action: api.HookRepoCreated,
- Repository: repo.APIFormat(models.AccessModeOwner),
- Organization: u.APIFormat(),
- Sender: doer.APIFormat(),
- }); err != nil {
- log.Error("PrepareWebhooks [repo_id: %d]: %v", repo.ID, err)
- }
+ if err := webhook_module.PrepareWebhooks(repo, models.HookEventRepository, &api.RepositoryPayload{
+ Action: api.HookRepoCreated,
+ Repository: repo.APIFormat(models.AccessModeOwner),
+ Organization: u.APIFormat(),
+ Sender: doer.APIFormat(),
+ }); err != nil {
+ log.Error("PrepareWebhooks [repo_id: %d]: %v", repo.ID, err)
}
}
func (m *webhookNotifier) NotifyDeleteRepository(doer *models.User, repo *models.Repository) {
u := repo.MustOwner()
- if u.IsOrganization() {
- if err := webhook_module.PrepareWebhooks(repo, models.HookEventRepository, &api.RepositoryPayload{
- Action: api.HookRepoDeleted,
- Repository: repo.APIFormat(models.AccessModeOwner),
- Organization: u.APIFormat(),
- Sender: doer.APIFormat(),
- }); err != nil {
- log.Error("PrepareWebhooks [repo_id: %d]: %v", repo.ID, err)
- }
+ if err := webhook_module.PrepareWebhooks(repo, models.HookEventRepository, &api.RepositoryPayload{
+ Action: api.HookRepoDeleted,
+ Repository: repo.APIFormat(models.AccessModeOwner),
+ Organization: u.APIFormat(),
+ Sender: doer.APIFormat(),
+ }); err != nil {
+ log.Error("PrepareWebhooks [repo_id: %d]: %v", repo.ID, err)
}
}