summaryrefslogtreecommitdiffstats
path: root/services/mailer
diff options
context:
space:
mode:
authorKN4CK3R <admin@oldschoolhack.me>2022-11-19 09:12:33 +0100
committerGitHub <noreply@github.com>2022-11-19 16:12:33 +0800
commit044c754ea53f5b81f451451df53aea366f6f700a (patch)
tree45688c28a84f87f71ec3f99eb0e8456eb7d19c42 /services/mailer
parentfefdb7ffd11bbfbff66dae8e88681ec840dedfde (diff)
downloadgitea-044c754ea53f5b81f451451df53aea366f6f700a.tar.gz
gitea-044c754ea53f5b81f451451df53aea366f6f700a.zip
Add `context.Context` to more methods (#21546)
This PR adds a context parameter to a bunch of methods. Some helper `xxxCtx()` methods got replaced with the normal name now. Co-authored-by: delvh <dev.lh@web.de> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Diffstat (limited to 'services/mailer')
-rw-r--r--services/mailer/mail.go9
-rw-r--r--services/mailer/mail_issue.go20
-rw-r--r--services/mailer/mail_release.go2
-rw-r--r--services/mailer/mail_repo.go6
4 files changed, 18 insertions, 19 deletions
diff --git a/services/mailer/mail.go b/services/mailer/mail.go
index 85a7d107e5..a9e36e10f8 100644
--- a/services/mailer/mail.go
+++ b/services/mailer/mail.go
@@ -18,7 +18,6 @@ import (
"time"
activities_model "code.gitea.io/gitea/models/activities"
- "code.gitea.io/gitea/models/db"
issues_model "code.gitea.io/gitea/models/issues"
repo_model "code.gitea.io/gitea/models/repo"
user_model "code.gitea.io/gitea/models/user"
@@ -265,7 +264,7 @@ func composeIssueCommentMessages(ctx *mailCommentContext, lang string, recipient
"Issue": ctx.Issue,
"Comment": ctx.Comment,
"IsPull": ctx.Issue.IsPull,
- "User": ctx.Issue.Repo.MustOwner(),
+ "User": ctx.Issue.Repo.MustOwner(ctx),
"Repo": ctx.Issue.Repo.FullName(),
"Doer": ctx.Doer,
"IsMention": fromMention,
@@ -395,13 +394,13 @@ func sanitizeSubject(subject string) string {
}
// SendIssueAssignedMail composes and sends issue assigned email
-func SendIssueAssignedMail(issue *issues_model.Issue, doer *user_model.User, content string, comment *issues_model.Comment, recipients []*user_model.User) error {
+func SendIssueAssignedMail(ctx context.Context, issue *issues_model.Issue, doer *user_model.User, content string, comment *issues_model.Comment, recipients []*user_model.User) error {
if setting.MailService == nil {
// No mail service configured
return nil
}
- if err := issue.LoadRepo(db.DefaultContext); err != nil {
+ if err := issue.LoadRepo(ctx); err != nil {
log.Error("Unable to load repo [%d] for issue #%d [%d]. Error: %v", issue.RepoID, issue.Index, issue.ID, err)
return err
}
@@ -417,7 +416,7 @@ func SendIssueAssignedMail(issue *issues_model.Issue, doer *user_model.User, con
for lang, tos := range langMap {
msgs, err := composeIssueCommentMessages(&mailCommentContext{
- Context: context.TODO(), // TODO: use a correct context
+ Context: ctx,
Issue: issue,
Doer: doer,
ActionType: activities_model.ActionType(0),
diff --git a/services/mailer/mail_issue.go b/services/mailer/mail_issue.go
index 61e276805d..e7ff1d59d6 100644
--- a/services/mailer/mail_issue.go
+++ b/services/mailer/mail_issue.go
@@ -45,13 +45,13 @@ const (
func mailIssueCommentToParticipants(ctx *mailCommentContext, mentions []*user_model.User) error {
// Required by the mail composer; make sure to load these before calling the async function
if err := ctx.Issue.LoadRepo(ctx); err != nil {
- return fmt.Errorf("LoadRepo(): %w", err)
+ return fmt.Errorf("LoadRepo: %w", err)
}
- if err := ctx.Issue.LoadPoster(); err != nil {
- return fmt.Errorf("LoadPoster(): %w", err)
+ if err := ctx.Issue.LoadPoster(ctx); err != nil {
+ return fmt.Errorf("LoadPoster: %w", err)
}
- if err := ctx.Issue.LoadPullRequest(); err != nil {
- return fmt.Errorf("LoadPullRequest(): %w", err)
+ if err := ctx.Issue.LoadPullRequest(ctx); err != nil {
+ return fmt.Errorf("LoadPullRequest: %w", err)
}
// Enough room to avoid reallocations
@@ -61,14 +61,14 @@ func mailIssueCommentToParticipants(ctx *mailCommentContext, mentions []*user_mo
unfiltered[0] = ctx.Issue.PosterID
// =========== Assignees ===========
- ids, err := issues_model.GetAssigneeIDsByIssue(ctx.Issue.ID)
+ ids, err := issues_model.GetAssigneeIDsByIssue(ctx, ctx.Issue.ID)
if err != nil {
return fmt.Errorf("GetAssigneeIDsByIssue(%d): %w", ctx.Issue.ID, err)
}
unfiltered = append(unfiltered, ids...)
// =========== Participants (i.e. commenters, reviewers) ===========
- ids, err = issues_model.GetParticipantsIDsByIssueID(ctx.Issue.ID)
+ ids, err = issues_model.GetParticipantsIDsByIssueID(ctx, ctx.Issue.ID)
if err != nil {
return fmt.Errorf("GetParticipantsIDsByIssueID(%d): %w", ctx.Issue.ID, err)
}
@@ -110,7 +110,7 @@ func mailIssueCommentToParticipants(ctx *mailCommentContext, mentions []*user_mo
}
visited.AddMultiple(ids...)
- unfilteredUsers, err := user_model.GetMaileableUsersByIDs(unfiltered, false)
+ unfilteredUsers, err := user_model.GetMaileableUsersByIDs(ctx, unfiltered, false)
if err != nil {
return err
}
@@ -173,7 +173,7 @@ func mailIssueCommentBatch(ctx *mailCommentContext, users []*user_model.User, vi
// MailParticipants sends new issue thread created emails to repository watchers
// and mentioned people.
-func MailParticipants(issue *issues_model.Issue, doer *user_model.User, opType activities_model.ActionType, mentions []*user_model.User) error {
+func MailParticipants(ctx context.Context, issue *issues_model.Issue, doer *user_model.User, opType activities_model.ActionType, mentions []*user_model.User) error {
if setting.MailService == nil {
// No mail service configured
return nil
@@ -188,7 +188,7 @@ func MailParticipants(issue *issues_model.Issue, doer *user_model.User, opType a
forceDoerNotification := opType == activities_model.ActionAutoMergePullRequest
if err := mailIssueCommentToParticipants(
&mailCommentContext{
- Context: context.TODO(), // TODO: use a correct context
+ Context: ctx,
Issue: issue,
Doer: doer,
ActionType: opType,
diff --git a/services/mailer/mail_release.go b/services/mailer/mail_release.go
index 6df3fbbf1d..b15fc05ce9 100644
--- a/services/mailer/mail_release.go
+++ b/services/mailer/mail_release.go
@@ -36,7 +36,7 @@ func MailNewRelease(ctx context.Context, rel *repo_model.Release) {
return
}
- recipients, err := user_model.GetMaileableUsersByIDs(watcherIDList, false)
+ recipients, err := user_model.GetMaileableUsersByIDs(ctx, watcherIDList, false)
if err != nil {
log.Error("user_model.GetMaileableUsersByIDs: %v", err)
return
diff --git a/services/mailer/mail_repo.go b/services/mailer/mail_repo.go
index 6fe9df0926..d3f5120929 100644
--- a/services/mailer/mail_repo.go
+++ b/services/mailer/mail_repo.go
@@ -6,9 +6,9 @@ package mailer
import (
"bytes"
+ "context"
"fmt"
- "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/models/organization"
repo_model "code.gitea.io/gitea/models/repo"
user_model "code.gitea.io/gitea/models/user"
@@ -18,14 +18,14 @@ import (
)
// SendRepoTransferNotifyMail triggers a notification e-mail when a pending repository transfer was created
-func SendRepoTransferNotifyMail(doer, newOwner *user_model.User, repo *repo_model.Repository) error {
+func SendRepoTransferNotifyMail(ctx context.Context, doer, newOwner *user_model.User, repo *repo_model.Repository) error {
if setting.MailService == nil {
// No mail service configured
return nil
}
if newOwner.IsOrganization() {
- users, err := organization.GetUsersWhoCanCreateOrgRepo(db.DefaultContext, newOwner.ID)
+ users, err := organization.GetUsersWhoCanCreateOrgRepo(ctx, newOwner.ID)
if err != nil {
return err
}