From f064d716c3972f38249533602b41f8a68dcffc27 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Tue, 5 Sep 2023 21:00:52 +0800 Subject: [PATCH] Move feed notification service layer (#26908) Extract from #22266 --- modules/notification/notification.go | 6 ------ routers/init.go | 4 ++-- {modules/notification/action => services/feed}/action.go | 9 ++++++++- .../notification/action => services/feed}/action_test.go | 4 ++-- services/repository/transfer_test.go | 4 ++-- 5 files changed, 14 insertions(+), 13 deletions(-) rename {modules/notification/action => services/feed}/action.go (99%) rename {modules/notification/action => services/feed}/action_test.go (95%) diff --git a/modules/notification/notification.go b/modules/notification/notification.go index c265388a1..3c29dd925 100644 --- a/modules/notification/notification.go +++ b/modules/notification/notification.go @@ -12,7 +12,6 @@ import ( user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" - "code.gitea.io/gitea/modules/notification/action" "code.gitea.io/gitea/modules/notification/base" "code.gitea.io/gitea/modules/repository" ) @@ -25,11 +24,6 @@ func RegisterNotifier(notifier base.Notifier) { notifiers = append(notifiers, notifier) } -// NewContext registers notification handlers -func NewContext() { - RegisterNotifier(action.NewNotifier()) -} - // NotifyNewWikiPage notifies creating new wiki pages to notifiers func NotifyNewWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, page, comment string) { for _, notifier := range notifiers { diff --git a/routers/init.go b/routers/init.go index f311b4f95..6369a3975 100644 --- a/routers/init.go +++ b/routers/init.go @@ -18,7 +18,6 @@ import ( "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/markup" "code.gitea.io/gitea/modules/markup/external" - "code.gitea.io/gitea/modules/notification" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/ssh" "code.gitea.io/gitea/modules/storage" @@ -38,6 +37,7 @@ import ( "code.gitea.io/gitea/services/auth/source/oauth2" "code.gitea.io/gitea/services/automerge" "code.gitea.io/gitea/services/cron" + feed_service "code.gitea.io/gitea/services/feed" indexer_service "code.gitea.io/gitea/services/indexer" "code.gitea.io/gitea/services/mailer" mailer_incoming "code.gitea.io/gitea/services/mailer/incoming" @@ -119,7 +119,7 @@ func InitWebInstalled(ctx context.Context) { mailer.NewContext(ctx) mustInit(cache.NewContext) - notification.NewContext() + mustInit(feed_service.Init) mustInit(uinotification.Init) mustInit(archiver.Init) diff --git a/modules/notification/action/action.go b/services/feed/action.go similarity index 99% rename from modules/notification/action/action.go rename to services/feed/action.go index 1d759e492..3516e79fe 100644 --- a/modules/notification/action/action.go +++ b/services/feed/action.go @@ -1,7 +1,7 @@ // Copyright 2019 The Gitea Authors. All rights reserved. // SPDX-License-Identifier: MIT -package action +package feed import ( "context" @@ -16,6 +16,7 @@ import ( "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/json" "code.gitea.io/gitea/modules/log" + "code.gitea.io/gitea/modules/notification" "code.gitea.io/gitea/modules/notification/base" "code.gitea.io/gitea/modules/repository" "code.gitea.io/gitea/modules/util" @@ -27,6 +28,12 @@ type actionNotifier struct { var _ base.Notifier = &actionNotifier{} +func Init() error { + notification.RegisterNotifier(NewNotifier()) + + return nil +} + // NewNotifier create a new actionNotifier notifier func NewNotifier() base.Notifier { return &actionNotifier{} diff --git a/modules/notification/action/action_test.go b/services/feed/action_test.go similarity index 95% rename from modules/notification/action/action_test.go rename to services/feed/action_test.go index 05ce70f38..1037ba768 100644 --- a/modules/notification/action/action_test.go +++ b/services/feed/action_test.go @@ -1,7 +1,7 @@ // Copyright 2019 The Gitea Authors. All rights reserved. // SPDX-License-Identifier: MIT -package action +package feed import ( "path/filepath" @@ -19,7 +19,7 @@ import ( func TestMain(m *testing.M) { unittest.MainTest(m, &unittest.TestOptions{ - GiteaRootPath: filepath.Join("..", "..", ".."), + GiteaRootPath: filepath.Join("..", ".."), }) } diff --git a/services/repository/transfer_test.go b/services/repository/transfer_test.go index 1299e66be..53ba3c244 100644 --- a/services/repository/transfer_test.go +++ b/services/repository/transfer_test.go @@ -15,8 +15,8 @@ import ( "code.gitea.io/gitea/models/unittest" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/notification" - "code.gitea.io/gitea/modules/notification/action" "code.gitea.io/gitea/modules/util" + "code.gitea.io/gitea/services/feed" "github.com/stretchr/testify/assert" ) @@ -25,7 +25,7 @@ var notifySync sync.Once func registerNotifier() { notifySync.Do(func() { - notification.RegisterNotifier(action.NewNotifier()) + notification.RegisterNotifier(feed.NewNotifier()) }) }