aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Lakin2020-10-04 21:42:03 +0000
committerGitHub2020-10-04 17:42:03 -0400
commitb05e1781382cd0a4163092ff46a99eb0be0a778c (patch)
treeca883527da591092aa8cb91d4cb7f36ab4f227f8
parent96918a442b4aad63bb28ceb767d49b29ba8c1b22 (diff)
Fix repository create/delete event webhooks (#13008) (#13027)
-rw-r--r--modules/notification/webhook/webhook.go32
-rw-r--r--services/repository/repository.go8
2 files changed, 17 insertions, 23 deletions
diff --git a/modules/notification/webhook/webhook.go b/modules/notification/webhook/webhook.go
index 625cf119a..c8b6bae72 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)
}
}
diff --git a/services/repository/repository.go b/services/repository/repository.go
index f50b98b64..4ebfae620 100644
--- a/services/repository/repository.go
+++ b/services/repository/repository.go
@@ -54,13 +54,11 @@ func DeleteRepository(doer *models.User, repo *models.Repository) error {
log.Error("CloseRepoBranchesPulls failed: %v", err)
}
- if err := models.DeleteRepository(doer, repo.OwnerID, repo.ID); err != nil {
- return err
- }
-
+ // If the repo itself has webhooks, we need to trigger them before deleting it...
notification.NotifyDeleteRepository(doer, repo)
- return nil
+ err := models.DeleteRepository(doer, repo.OwnerID, repo.ID)
+ return err
}
// PushCreateRepo creates a repository when a new repository is pushed to an appropriate namespace