1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-22 18:28:37 +00:00

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>
This commit is contained in:
zeripath
2022-01-19 23:26:57 +00:00
committed by GitHub
parent 4563148a61
commit 5cb0c9aa0d
193 changed files with 1264 additions and 1154 deletions

View File

@@ -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)

View File

@@ -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,

View File

@@ -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

View File

@@ -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)