mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
Use ctx
instead of db.DefaultContext
in some packages(routers/services/modules) (#19163)
* Remove `db.DefaultContext` usage in routers, use `ctx` directly * Use `ctx` directly if there is one, remove some `db.DefaultContext` in `services` * Use ctx instead of db.DefaultContext for `cmd` and some `modules` packages * fix incorrect context usage
This commit is contained in:
@@ -7,6 +7,7 @@ package mailer
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"mime"
|
||||
@@ -414,6 +415,7 @@ func SendIssueAssignedMail(issue *models.Issue, doer *user_model.User, content s
|
||||
|
||||
for lang, tos := range langMap {
|
||||
msgs, err := composeIssueCommentMessages(&mailCommentContext{
|
||||
Context: context.TODO(), // TODO: use a correct context
|
||||
Issue: issue,
|
||||
Doer: doer,
|
||||
ActionType: models.ActionType(0),
|
||||
|
@@ -9,7 +9,6 @@ import (
|
||||
"fmt"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
"code.gitea.io/gitea/models/unit"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
@@ -81,7 +80,7 @@ func mailIssueCommentToParticipants(ctx *mailCommentContext, mentions []*user_mo
|
||||
// =========== Repo watchers ===========
|
||||
// Make repo watchers last, since it's likely the list with the most users
|
||||
if !(ctx.Issue.IsPull && ctx.Issue.PullRequest.IsWorkInProgress() && ctx.ActionType != models.ActionCreatePullRequest) {
|
||||
ids, err = repo_model.GetRepoWatchersIDs(db.DefaultContext, ctx.Issue.RepoID)
|
||||
ids, err = repo_model.GetRepoWatchersIDs(ctx, ctx.Issue.RepoID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("GetRepoWatchersIDs(%d): %v", ctx.Issue.RepoID, err)
|
||||
}
|
||||
@@ -186,6 +185,7 @@ func MailParticipants(issue *models.Issue, doer *user_model.User, opType models.
|
||||
}
|
||||
if err := mailIssueCommentToParticipants(
|
||||
&mailCommentContext{
|
||||
Context: context.TODO(), // TODO: use a correct context
|
||||
Issue: issue,
|
||||
Doer: doer,
|
||||
ActionType: opType,
|
||||
|
@@ -9,7 +9,6 @@ import (
|
||||
"context"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/base"
|
||||
@@ -32,7 +31,7 @@ func MailNewRelease(ctx context.Context, rel *models.Release) {
|
||||
return
|
||||
}
|
||||
|
||||
watcherIDList, err := repo_model.GetRepoWatchersIDs(db.DefaultContext, rel.RepoID)
|
||||
watcherIDList, err := repo_model.GetRepoWatchersIDs(ctx, rel.RepoID)
|
||||
if err != nil {
|
||||
log.Error("GetRepoWatchersIDs(%d): %v", rel.RepoID, err)
|
||||
return
|
||||
|
@@ -6,6 +6,7 @@ package mailer
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"strings"
|
||||
@@ -70,7 +71,8 @@ func TestComposeIssueCommentMessage(t *testing.T) {
|
||||
|
||||
recipients := []*user_model.User{{Name: "Test", Email: "test@gitea.com"}, {Name: "Test2", Email: "test2@gitea.com"}}
|
||||
msgs, err := composeIssueCommentMessages(&mailCommentContext{
|
||||
Issue: issue, Doer: doer, ActionType: models.ActionCommentIssue,
|
||||
Context: context.TODO(), // TODO: use a correct context
|
||||
Issue: issue, Doer: doer, ActionType: models.ActionCommentIssue,
|
||||
Content: "test body", Comment: comment,
|
||||
}, "en-US", recipients, false, "issue comment")
|
||||
assert.NoError(t, err)
|
||||
@@ -99,7 +101,8 @@ func TestComposeIssueMessage(t *testing.T) {
|
||||
|
||||
recipients := []*user_model.User{{Name: "Test", Email: "test@gitea.com"}, {Name: "Test2", Email: "test2@gitea.com"}}
|
||||
msgs, err := composeIssueCommentMessages(&mailCommentContext{
|
||||
Issue: issue, Doer: doer, ActionType: models.ActionCreateIssue,
|
||||
Context: context.TODO(), // TODO: use a correct context
|
||||
Issue: issue, Doer: doer, ActionType: models.ActionCreateIssue,
|
||||
Content: "test body",
|
||||
}, "en-US", recipients, false, "issue create")
|
||||
assert.NoError(t, err)
|
||||
@@ -145,13 +148,15 @@ func TestTemplateSelection(t *testing.T) {
|
||||
}
|
||||
|
||||
msg := testComposeIssueCommentMessage(t, &mailCommentContext{
|
||||
Issue: issue, Doer: doer, ActionType: models.ActionCreateIssue,
|
||||
Context: context.TODO(), // TODO: use a correct context
|
||||
Issue: issue, Doer: doer, ActionType: models.ActionCreateIssue,
|
||||
Content: "test body",
|
||||
}, recipients, false, "TestTemplateSelection")
|
||||
expect(t, msg, "issue/new/subject", "issue/new/body")
|
||||
|
||||
msg = testComposeIssueCommentMessage(t, &mailCommentContext{
|
||||
Issue: issue, Doer: doer, ActionType: models.ActionCommentIssue,
|
||||
Context: context.TODO(), // TODO: use a correct context
|
||||
Issue: issue, Doer: doer, ActionType: models.ActionCommentIssue,
|
||||
Content: "test body", Comment: comment,
|
||||
}, recipients, false, "TestTemplateSelection")
|
||||
expect(t, msg, "issue/default/subject", "issue/default/body")
|
||||
@@ -159,13 +164,15 @@ func TestTemplateSelection(t *testing.T) {
|
||||
pull := unittest.AssertExistsAndLoadBean(t, &models.Issue{ID: 2, Repo: repo, Poster: doer}).(*models.Issue)
|
||||
comment = unittest.AssertExistsAndLoadBean(t, &models.Comment{ID: 4, Issue: pull}).(*models.Comment)
|
||||
msg = testComposeIssueCommentMessage(t, &mailCommentContext{
|
||||
Issue: pull, Doer: doer, ActionType: models.ActionCommentPull,
|
||||
Context: context.TODO(), // TODO: use a correct context
|
||||
Issue: pull, Doer: doer, ActionType: models.ActionCommentPull,
|
||||
Content: "test body", Comment: comment,
|
||||
}, recipients, false, "TestTemplateSelection")
|
||||
expect(t, msg, "pull/comment/subject", "pull/comment/body")
|
||||
|
||||
msg = testComposeIssueCommentMessage(t, &mailCommentContext{
|
||||
Issue: issue, Doer: doer, ActionType: models.ActionCloseIssue,
|
||||
Context: context.TODO(), // TODO: use a correct context
|
||||
Issue: issue, Doer: doer, ActionType: models.ActionCloseIssue,
|
||||
Content: "test body", Comment: comment,
|
||||
}, recipients, false, "TestTemplateSelection")
|
||||
expect(t, msg, "Re: [user2/repo1] issue1 (#1)", "issue/close/body")
|
||||
@@ -184,7 +191,8 @@ func TestTemplateServices(t *testing.T) {
|
||||
|
||||
recipients := []*user_model.User{{Name: "Test", Email: "test@gitea.com"}}
|
||||
msg := testComposeIssueCommentMessage(t, &mailCommentContext{
|
||||
Issue: issue, Doer: doer, ActionType: actionType,
|
||||
Context: context.TODO(), // TODO: use a correct context
|
||||
Issue: issue, Doer: doer, ActionType: actionType,
|
||||
Content: "test body", Comment: comment,
|
||||
}, recipients, fromMention, "TestTemplateServices")
|
||||
|
||||
@@ -226,7 +234,7 @@ func testComposeIssueCommentMessage(t *testing.T, ctx *mailCommentContext, recip
|
||||
func TestGenerateAdditionalHeaders(t *testing.T) {
|
||||
doer, _, issue, _ := prepareMailerTest(t)
|
||||
|
||||
ctx := &mailCommentContext{Issue: issue, Doer: doer}
|
||||
ctx := &mailCommentContext{Context: context.TODO() /* TODO: use a correct context */, Issue: issue, Doer: doer}
|
||||
recipient := &user_model.User{Name: "Test", Email: "test@gitea.com"}
|
||||
|
||||
headers := generateAdditionalHeaders(ctx, "dummy-reason", recipient)
|
||||
|
Reference in New Issue
Block a user