Skip to content

Notification structure refactor #22266

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
fd9dcc7
Move notification implementations out of modules
lunny Dec 29, 2022
f4f09ee
Fix lint
lunny Dec 29, 2022
993e82f
Merge branch 'main' into lunny/move_notification_impl_services
lunny Dec 29, 2022
7f0221a
Fix lint
lunny Dec 29, 2022
f846d8a
merge main branch and merge notification
lunny Jan 1, 2023
b9e5fd6
improvement
lunny Jan 1, 2023
b7b0780
rename modules/notification -> services/notify
lunny Jan 1, 2023
172ed4b
Merge branch 'main' into lunny/move_notification_impl_services
lunny Jan 1, 2023
cf0d0c3
follow @delvh suggestion
lunny Jan 2, 2023
eab2f6e
Merge branch 'main' into lunny/move_notification_impl_services
lunny Jan 2, 2023
d76c735
Fix bugs
lunny Jan 2, 2023
79d82ee
Merge branch 'main' into lunny/move_notification_impl_services
lunny Jan 2, 2023
b6c0733
Merge branch 'lunny/move_notification_impl_services' of github.com:lu…
lunny Jan 2, 2023
acfac22
Fix test
lunny Jan 2, 2023
f9d43c8
Merge branch 'main' into lunny/move_notification_impl_services
lunny Jan 3, 2023
d55e1e8
Try to fix test
lunny Jan 3, 2023
7aab9e6
Merge branch 'main' into lunny/move_notification_impl_services
lunny Jan 3, 2023
5faece7
revert change of webhook
lunny Jan 7, 2023
8d3e234
Merge branch 'main' into lunny/move_notification_impl_services
lunny Jan 7, 2023
80f6493
Fix test
lunny Jan 7, 2023
b4c6045
merge main branch
lunny Jan 16, 2023
ba4c3c2
merge main branch
lunny Jan 29, 2023
58ce0e7
merge main branch
lunny Mar 27, 2023
73df316
merge main branch
lunny May 1, 2023
6cf06ff
register notify in Init
lunny May 1, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ import (
_ "code.gitea.io/gitea/modules/markup/markdown"
_ "code.gitea.io/gitea/modules/markup/orgmode"

_ "code.gitea.io/gitea/services/feed"
_ "code.gitea.io/gitea/services/indexer"
_ "code.gitea.io/gitea/services/notification"

"github.com/urfave/cli"
)

Expand Down
4 changes: 2 additions & 2 deletions routers/api/packages/conan/conan.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ import (
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/notification"
packages_module "code.gitea.io/gitea/modules/packages"
conan_module "code.gitea.io/gitea/modules/packages/conan"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/routers/api/packages/helper"
"code.gitea.io/gitea/services/notify"
packages_service "code.gitea.io/gitea/services/packages"
)

Expand Down Expand Up @@ -678,7 +678,7 @@ func deleteRecipeOrPackage(apictx *context.Context, rref *conan_module.RecipeRef
}

if versionDeleted {
notification.NotifyPackageDelete(apictx, apictx.Doer, pd)
notify.NotifyPackageDelete(apictx, apictx.Doer, pd)
}

return nil
Expand Down
6 changes: 3 additions & 3 deletions routers/api/v1/repo/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/context"
issue_indexer "code.gitea.io/gitea/modules/indexer/issues"
"code.gitea.io/gitea/modules/notification"
"code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/timeutil"
Expand All @@ -29,6 +28,7 @@ import (
"code.gitea.io/gitea/routers/api/v1/utils"
"code.gitea.io/gitea/services/convert"
issue_service "code.gitea.io/gitea/services/issue"
"code.gitea.io/gitea/services/notify"
)

// SearchIssues searches for issues across the repositories that the user has access to
Expand Down Expand Up @@ -822,11 +822,11 @@ func EditIssue(ctx *context.APIContext) {
}

if titleChanged {
notification.NotifyIssueChangeTitle(ctx, ctx.Doer, issue, oldTitle)
notify.NotifyIssueChangeTitle(ctx, ctx.Doer, issue, oldTitle)
}

if statusChangeComment != nil {
notification.NotifyIssueChangeStatus(ctx, ctx.Doer, issue, statusChangeComment, issue.IsClosed)
notify.NotifyIssueChangeStatus(ctx, ctx.Doer, issue, statusChangeComment, issue.IsClosed)
}

// Refetch from database to assign some automatic values
Expand Down
4 changes: 2 additions & 2 deletions routers/api/v1/repo/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"code.gitea.io/gitea/modules/lfs"
"code.gitea.io/gitea/modules/log"
base "code.gitea.io/gitea/modules/migration"
"code.gitea.io/gitea/modules/notification"
repo_module "code.gitea.io/gitea/modules/repository"
"code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs"
Expand All @@ -30,6 +29,7 @@ import (
"code.gitea.io/gitea/services/convert"
"code.gitea.io/gitea/services/forms"
"code.gitea.io/gitea/services/migrations"
"code.gitea.io/gitea/services/notify"
)

// Migrate migrate remote git repository to gitea
Expand Down Expand Up @@ -194,7 +194,7 @@ func Migrate(ctx *context.APIContext) {
}

if err == nil {
notification.NotifyMigrateRepository(ctx, ctx.Doer, repoOwner, repo)
notify.NotifyMigrateRepository(ctx, ctx.Doer, repoOwner, repo)
return
}

Expand Down
8 changes: 4 additions & 4 deletions routers/api/v1/repo/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/notification"
"code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/timeutil"
Expand All @@ -35,6 +34,7 @@ import (
"code.gitea.io/gitea/services/forms"
"code.gitea.io/gitea/services/gitdiff"
issue_service "code.gitea.io/gitea/services/issue"
"code.gitea.io/gitea/services/notify"
pull_service "code.gitea.io/gitea/services/pull"
repo_service "code.gitea.io/gitea/services/repository"
)
Expand Down Expand Up @@ -595,11 +595,11 @@ func EditPullRequest(ctx *context.APIContext) {
}

if titleChanged {
notification.NotifyIssueChangeTitle(ctx, ctx.Doer, issue, oldTitle)
notify.NotifyIssueChangeTitle(ctx, ctx.Doer, issue, oldTitle)
}

if statusChangeComment != nil {
notification.NotifyIssueChangeStatus(ctx, ctx.Doer, issue, statusChangeComment, issue.IsClosed)
notify.NotifyIssueChangeStatus(ctx, ctx.Doer, issue, statusChangeComment, issue.IsClosed)
}

// change pull target branch
Expand All @@ -623,7 +623,7 @@ func EditPullRequest(ctx *context.APIContext) {
}
return
}
notification.NotifyPullRequestChangeTargetBranch(ctx, ctx.Doer, pr, form.Base)
notify.NotifyPullRequestChangeTargetBranch(ctx, ctx.Doer, pr, form.Base)
}

// update allow edits
Expand Down
8 changes: 4 additions & 4 deletions routers/api/v1/repo/wiki.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import (
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/notification"
"code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/modules/web"
"code.gitea.io/gitea/services/convert"
"code.gitea.io/gitea/services/notify"
wiki_service "code.gitea.io/gitea/services/wiki"
)

Expand Down Expand Up @@ -85,7 +85,7 @@ func NewWikiPage(ctx *context.APIContext) {
wikiPage := getWikiPage(ctx, wikiName)

if !ctx.Written() {
notification.NotifyNewWikiPage(ctx, ctx.Doer, ctx.Repo.Repository, wikiName, form.Message)
notify.NotifyNewWikiPage(ctx, ctx.Doer, ctx.Repo.Repository, wikiName, form.Message)
ctx.JSON(http.StatusCreated, wikiPage)
}
}
Expand Down Expand Up @@ -153,7 +153,7 @@ func EditWikiPage(ctx *context.APIContext) {
wikiPage := getWikiPage(ctx, newWikiName)

if !ctx.Written() {
notification.NotifyEditWikiPage(ctx, ctx.Doer, ctx.Repo.Repository, newWikiName, form.Message)
notify.NotifyEditWikiPage(ctx, ctx.Doer, ctx.Repo.Repository, newWikiName, form.Message)
ctx.JSON(http.StatusOK, wikiPage)
}
}
Expand Down Expand Up @@ -244,7 +244,7 @@ func DeleteWikiPage(ctx *context.APIContext) {
return
}

notification.NotifyDeleteWikiPage(ctx, ctx.Doer, ctx.Repo.Repository, wikiName)
notify.NotifyDeleteWikiPage(ctx, ctx.Doer, ctx.Repo.Repository, wikiName)

ctx.Status(http.StatusNoContent)
}
Expand Down
2 changes: 0 additions & 2 deletions routers/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,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"
Expand Down Expand Up @@ -129,7 +128,6 @@ func GlobalInitInstalled(ctx context.Context) {

mailer.NewContext(ctx)
mustInit(cache.NewContext)
notification.NewContext()
mustInit(archiver.Init)

highlight.NewContext()
Expand Down
4 changes: 2 additions & 2 deletions routers/web/repo/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import (
"code.gitea.io/gitea/modules/git"
issue_template "code.gitea.io/gitea/modules/issue/template"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/notification"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/upload"
Expand All @@ -43,6 +42,7 @@ import (
"code.gitea.io/gitea/services/automerge"
"code.gitea.io/gitea/services/forms"
"code.gitea.io/gitea/services/gitdiff"
"code.gitea.io/gitea/services/notify"
pull_service "code.gitea.io/gitea/services/pull"
repo_service "code.gitea.io/gitea/services/repository"
)
Expand Down Expand Up @@ -1511,7 +1511,7 @@ func UpdatePullRequestTarget(ctx *context.Context) {
}
return
}
notification.NotifyPullRequestChangeTargetBranch(ctx, ctx.Doer, pr, targetBranch)
notify.NotifyPullRequestChangeTargetBranch(ctx, ctx.Doer, pr, targetBranch)

ctx.JSON(http.StatusOK, map[string]interface{}{
"base_branch": pr.BaseBranch,
Expand Down
8 changes: 4 additions & 4 deletions routers/web/repo/wiki.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ import (
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/markup"
"code.gitea.io/gitea/modules/markup/markdown"
"code.gitea.io/gitea/modules/notification"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/timeutil"
"code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/modules/web"
"code.gitea.io/gitea/routers/common"
"code.gitea.io/gitea/services/forms"
"code.gitea.io/gitea/services/notify"
wiki_service "code.gitea.io/gitea/services/wiki"
)

Expand Down Expand Up @@ -705,7 +705,7 @@ func NewWikiPost(ctx *context.Context) {
return
}

notification.NotifyNewWikiPage(ctx, ctx.Doer, ctx.Repo.Repository, wikiName, form.Message)
notify.NotifyNewWikiPage(ctx, ctx.Doer, ctx.Repo.Repository, wikiName, form.Message)

ctx.Redirect(ctx.Repo.RepoLink + "/wiki/" + wiki_service.NameToSubURL(wikiName))
}
Expand Down Expand Up @@ -749,7 +749,7 @@ func EditWikiPost(ctx *context.Context) {
return
}

notification.NotifyEditWikiPage(ctx, ctx.Doer, ctx.Repo.Repository, newWikiName, form.Message)
notify.NotifyEditWikiPage(ctx, ctx.Doer, ctx.Repo.Repository, newWikiName, form.Message)

ctx.Redirect(ctx.Repo.RepoLink + "/wiki/" + wiki_service.NameToSubURL(newWikiName))
}
Expand All @@ -766,7 +766,7 @@ func DeleteWikiPagePost(ctx *context.Context) {
return
}

notification.NotifyDeleteWikiPage(ctx, ctx.Doer, ctx.Repo.Repository, wikiName)
notify.NotifyDeleteWikiPage(ctx, ctx.Doer, ctx.Repo.Repository, wikiName)

ctx.JSON(http.StatusOK, map[string]interface{}{
"redirect": ctx.Repo.RepoLink + "/wiki/",
Expand Down
6 changes: 3 additions & 3 deletions services/agit/agit.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ 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"
"code.gitea.io/gitea/modules/private"
"code.gitea.io/gitea/services/notify"
pull_service "code.gitea.io/gitea/services/pull"
)

Expand Down Expand Up @@ -208,9 +208,9 @@ func ProcReceive(ctx context.Context, repo *repo_model.Repository, gitRepo *git.
}
comment, err := pull_service.CreatePushPullComment(ctx, pusher, pr, oldCommitID, opts.NewCommitIDs[i])
if err == nil && comment != nil {
notification.NotifyPullRequestPushCommits(ctx, pusher, pr, comment)
notify.NotifyPullRequestPushCommits(ctx, pusher, pr, comment)
}
notification.NotifyPullRequestSynchronized(ctx, pusher, pr)
notify.NotifyPullRequestSynchronized(ctx, pusher, pr)
isForcePush := comment != nil && comment.IsForcePush

results = append(results, private.HookProcReceiveRefResult{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2019 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT

package action
package feed

import (
"context"
Expand All @@ -15,22 +15,26 @@ import (
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/notification/base"
"code.gitea.io/gitea/modules/repository"
"code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/services/notify"
)

type actionNotifier struct {
base.NullNotifier
notify.NullNotifier
}

var _ base.Notifier = &actionNotifier{}
var _ notify.Notifier = &actionNotifier{}

// NewNotifier create a new actionNotifier notifier
func NewNotifier() base.Notifier {
func NewNotifier() notify.Notifier {
return &actionNotifier{}
}

func init() {
notify.RegisterNotifier(NewNotifier())
}

func (a *actionNotifier) NotifyNewIssue(ctx context.Context, issue *issues_model.Issue, mentions []*user_model.User) {
if err := issue.LoadPoster(ctx); err != nil {
log.Error("issue.LoadPoster: %v", err)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
// Copyright 2019 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT

package action
package feed

import (
"path/filepath"
"strings"
"testing"

Expand All @@ -17,12 +16,6 @@ import (
"github.com/stretchr/testify/assert"
)

func TestMain(m *testing.M) {
unittest.MainTest(m, &unittest.TestOptions{
GiteaRootPath: filepath.Join("..", "..", ".."),
})
}

func TestRenameRepoAction(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())

Expand Down
17 changes: 17 additions & 0 deletions services/feed/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright 2019 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT

package feed

import (
"path/filepath"
"testing"

"code.gitea.io/gitea/models/unittest"
)

func TestMain(m *testing.M) {
unittest.MainTest(m, &unittest.TestOptions{
GiteaRootPath: filepath.Join("..", ".."),
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,26 @@ import (
issue_indexer "code.gitea.io/gitea/modules/indexer/issues"
stats_indexer "code.gitea.io/gitea/modules/indexer/stats"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/notification/base"
"code.gitea.io/gitea/modules/repository"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/services/notify"
)

type indexerNotifier struct {
base.NullNotifier
notify.NullNotifier
}

var _ base.Notifier = &indexerNotifier{}
var _ notify.Notifier = &indexerNotifier{}

// NewNotifier create a new indexerNotifier notifier
func NewNotifier() base.Notifier {
func NewNotifier() notify.Notifier {
return &indexerNotifier{}
}

func init() {
notify.RegisterNotifier(NewNotifier())
}

func (r *indexerNotifier) NotifyCreateIssueComment(ctx context.Context, doer *user_model.User, repo *repo_model.Repository,
issue *issues_model.Issue, comment *issues_model.Comment, mentions []*user_model.User,
) {
Expand Down
Loading