diff options
author | zeripath <art27@cantab.net> | 2022-01-19 23:26:57 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-19 23:26:57 +0000 |
commit | 5cb0c9aa0d7eed087055b1efca79628957207d36 (patch) | |
tree | d117a514e1f17e5f6bfcda1be273f6a971112663 /services/mailer | |
parent | 4563148a61ba892e8f2bb66342f00a950bcd5315 (diff) | |
download | gitea-5cb0c9aa0d7eed087055b1efca79628957207d36.tar.gz gitea-5cb0c9aa0d7eed087055b1efca79628957207d36.zip |
Propagate context and ensure git commands run in request context (#17868)
This PR continues the work in #17125 by progressively ensuring that git
commands run within the request context.
This now means that the if there is a git repo already open in the context it will be used instead of reopening it.
Signed-off-by: Andrew Thornton <art27@cantab.net>
Diffstat (limited to 'services/mailer')
-rw-r--r-- | services/mailer/mail.go | 1 | ||||
-rw-r--r-- | services/mailer/mail_comment.go | 8 | ||||
-rw-r--r-- | services/mailer/mail_issue.go | 2 | ||||
-rw-r--r-- | services/mailer/mail_release.go | 8 |
4 files changed, 14 insertions, 5 deletions
diff --git a/services/mailer/mail.go b/services/mailer/mail.go index 20552be584..5244cd0433 100644 --- a/services/mailer/mail.go +++ b/services/mailer/mail.go @@ -231,6 +231,7 @@ func composeIssueCommentMessages(ctx *mailCommentContext, lang string, recipient // This is the body of the new issue or comment, not the mail body body, err := markdown.RenderString(&markup.RenderContext{ + Ctx: ctx, URLPrefix: ctx.Issue.Repo.HTMLURL(), Metas: ctx.Issue.Repo.ComposeMetas(), }, ctx.Content) diff --git a/services/mailer/mail_comment.go b/services/mailer/mail_comment.go index 3662164092..a42458b2c2 100644 --- a/services/mailer/mail_comment.go +++ b/services/mailer/mail_comment.go @@ -5,6 +5,8 @@ package mailer import ( + "context" + "code.gitea.io/gitea/models" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/log" @@ -12,7 +14,7 @@ import ( ) // MailParticipantsComment sends new comment emails to repository watchers and mentioned people. -func MailParticipantsComment(c *models.Comment, opType models.ActionType, issue *models.Issue, mentions []*user_model.User) error { +func MailParticipantsComment(ctx context.Context, c *models.Comment, opType models.ActionType, issue *models.Issue, mentions []*user_model.User) error { if setting.MailService == nil { // No mail service configured return nil @@ -24,6 +26,7 @@ func MailParticipantsComment(c *models.Comment, opType models.ActionType, issue } if err := mailIssueCommentToParticipants( &mailCommentContext{ + Context: ctx, Issue: issue, Doer: c.Poster, ActionType: opType, @@ -36,7 +39,7 @@ func MailParticipantsComment(c *models.Comment, opType models.ActionType, issue } // MailMentionsComment sends email to users mentioned in a code comment -func MailMentionsComment(pr *models.PullRequest, c *models.Comment, mentions []*user_model.User) (err error) { +func MailMentionsComment(ctx context.Context, pr *models.PullRequest, c *models.Comment, mentions []*user_model.User) (err error) { if setting.MailService == nil { // No mail service configured return nil @@ -46,6 +49,7 @@ func MailMentionsComment(pr *models.PullRequest, c *models.Comment, mentions []* visited[c.Poster.ID] = true if err = mailIssueCommentBatch( &mailCommentContext{ + Context: ctx, Issue: pr.Issue, Doer: c.Poster, ActionType: models.ActionCommentPull, diff --git a/services/mailer/mail_issue.go b/services/mailer/mail_issue.go index c9cc2e015a..1df8332116 100644 --- a/services/mailer/mail_issue.go +++ b/services/mailer/mail_issue.go @@ -5,6 +5,7 @@ package mailer import ( + "context" "fmt" "code.gitea.io/gitea/models" @@ -21,6 +22,7 @@ func fallbackMailSubject(issue *models.Issue) string { } type mailCommentContext struct { + context.Context Issue *models.Issue Doer *user_model.User ActionType models.ActionType diff --git a/services/mailer/mail_release.go b/services/mailer/mail_release.go index ee4c6f3a59..1ca9ad02d7 100644 --- a/services/mailer/mail_release.go +++ b/services/mailer/mail_release.go @@ -6,6 +6,7 @@ package mailer import ( "bytes" + "context" "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/db" @@ -25,7 +26,7 @@ const ( ) // MailNewRelease send new release notify to all all repo watchers. -func MailNewRelease(rel *models.Release) { +func MailNewRelease(ctx context.Context, rel *models.Release) { if setting.MailService == nil { // No mail service configured return @@ -51,15 +52,16 @@ func MailNewRelease(rel *models.Release) { } for lang, tos := range langMap { - mailNewRelease(lang, tos, rel) + mailNewRelease(ctx, lang, tos, rel) } } -func mailNewRelease(lang string, tos []string, rel *models.Release) { +func mailNewRelease(ctx context.Context, lang string, tos []string, rel *models.Release) { locale := translation.NewLocale(lang) var err error rel.RenderedNote, err = markdown.RenderString(&markup.RenderContext{ + Ctx: ctx, URLPrefix: rel.Repo.Link(), Metas: rel.Repo.ComposeMetas(), }, rel.Note) |