aboutsummaryrefslogtreecommitdiffstats
path: root/modules/notification
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2019-10-26 14:54:11 +0800
committerGitHub <noreply@github.com>2019-10-26 14:54:11 +0800
commit9e85358777ea4bd345f832d08b19915a72cc128b (patch)
tree56116e7a6acbfd91a29cade7f753802f9ea561ea /modules/notification
parentd2d5910894cfe513f8aa331b30c991db6fbe8e6d (diff)
downloadgitea-9e85358777ea4bd345f832d08b19915a72cc128b.tar.gz
gitea-9e85358777ea4bd345f832d08b19915a72cc128b.zip
Move some repositories' operations to a standalone service package (#8557)
* Move some repositories' operations to a standalone service package * improve code * remove unused codes * add rollback when fork failed * add repo when return
Diffstat (limited to 'modules/notification')
-rw-r--r--modules/notification/indexer/indexer.go1
-rw-r--r--modules/notification/webhook/webhook.go64
2 files changed, 65 insertions, 0 deletions
diff --git a/modules/notification/indexer/indexer.go b/modules/notification/indexer/indexer.go
index 66614b2c20..453eb0c295 100644
--- a/modules/notification/indexer/indexer.go
+++ b/modules/notification/indexer/indexer.go
@@ -98,6 +98,7 @@ func (r *indexerNotifier) NotifyDeleteComment(doer *models.User, comment *models
func (r *indexerNotifier) NotifyDeleteRepository(doer *models.User, repo *models.Repository) {
issue_indexer.DeleteRepoIssueIndexer(repo)
+ models.DeleteRepoFromIndexer(repo)
}
func (r *indexerNotifier) NotifyIssueChangeContent(doer *models.User, issue *models.Issue, oldContent string) {
diff --git a/modules/notification/webhook/webhook.go b/modules/notification/webhook/webhook.go
index 33adfaa739..13f2f4486a 100644
--- a/modules/notification/webhook/webhook.go
+++ b/modules/notification/webhook/webhook.go
@@ -65,3 +65,67 @@ func (m *webhookNotifier) NotifyIssueClearLabels(doer *models.User, issue *model
go models.HookQueue.Add(issue.RepoID)
}
}
+
+func (m *webhookNotifier) NotifyForkRepository(doer *models.User, oldRepo, repo *models.Repository) {
+ oldMode, _ := models.AccessLevel(doer, oldRepo)
+ mode, _ := models.AccessLevel(doer, repo)
+
+ // forked webhook
+ if err := models.PrepareWebhooks(oldRepo, models.HookEventFork, &api.ForkPayload{
+ Forkee: oldRepo.APIFormat(oldMode),
+ Repo: repo.APIFormat(mode),
+ Sender: doer.APIFormat(),
+ }); err != nil {
+ log.Error("PrepareWebhooks [repo_id: %d]: %v", oldRepo.ID, err)
+ } else {
+ go models.HookQueue.Add(oldRepo.ID)
+ }
+
+ u := repo.MustOwner()
+
+ // Add to hook queue for created repo after session commit.
+ if u.IsOrganization() {
+ if err := models.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)
+ } else {
+ go models.HookQueue.Add(repo.ID)
+ }
+ }
+}
+
+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 := models.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)
+ } else {
+ go models.HookQueue.Add(repo.ID)
+ }
+ }
+}
+
+func (m *webhookNotifier) NotifyDeleteRepository(doer *models.User, repo *models.Repository) {
+ u := repo.MustOwner()
+
+ if u.IsOrganization() {
+ if err := models.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)
+ }
+ go models.HookQueue.Add(repo.ID)
+ }
+}