mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
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>
This commit is contained in:
@@ -96,7 +96,7 @@ func ProcReceive(ctx context.Context, repo *repo_model.Repository, gitRepo *git.
|
||||
headBranch = curentTopicBranch
|
||||
}
|
||||
|
||||
pr, err := issues_model.GetUnmergedPullRequest(repo.ID, repo.ID, headBranch, baseBranchName, issues_model.PullRequestFlowAGit)
|
||||
pr, err := issues_model.GetUnmergedPullRequest(ctx, repo.ID, repo.ID, headBranch, baseBranchName, issues_model.PullRequestFlowAGit)
|
||||
if err != nil {
|
||||
if !issues_model.IsErrPullRequestNotExist(err) {
|
||||
return nil, fmt.Errorf("Failed to get unmerged agit flow pull request in repository: %s/%s Error: %w", ownerName, repoName, err)
|
||||
@@ -159,7 +159,7 @@ func ProcReceive(ctx context.Context, repo *repo_model.Repository, gitRepo *git.
|
||||
}
|
||||
|
||||
// update exist pull request
|
||||
if err := pr.LoadBaseRepoCtx(ctx); err != nil {
|
||||
if err := pr.LoadBaseRepo(ctx); err != nil {
|
||||
return nil, fmt.Errorf("Unable to load base repository for PR[%d] Error: %w", pr.ID, err)
|
||||
}
|
||||
|
||||
@@ -203,15 +203,15 @@ func ProcReceive(ctx context.Context, repo *repo_model.Repository, gitRepo *git.
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Failed to get user. Error: %w", err)
|
||||
}
|
||||
err = pr.LoadIssue()
|
||||
err = pr.LoadIssue(ctx)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Failed to load pull issue. Error: %w", err)
|
||||
}
|
||||
comment, err := issues_model.CreatePushPullComment(ctx, pusher, pr, oldCommitID, opts.NewCommitIDs[i])
|
||||
if err == nil && comment != nil {
|
||||
notification.NotifyPullRequestPushCommits(pusher, pr, comment)
|
||||
notification.NotifyPullRequestPushCommits(ctx, pusher, pr, comment)
|
||||
}
|
||||
notification.NotifyPullRequestSynchronized(pusher, pr)
|
||||
notification.NotifyPullRequestSynchronized(ctx, pusher, pr)
|
||||
isForcePush := comment != nil && comment.IsForcePush
|
||||
|
||||
results = append(results, private.HookProcReceiveRefResult{
|
||||
|
@@ -272,7 +272,7 @@ Loop:
|
||||
|
||||
// SignMerge determines if we should sign a PR merge commit to the base repository
|
||||
func SignMerge(ctx context.Context, pr *issues_model.PullRequest, u *user_model.User, tmpBasePath, baseCommit, headCommit string) (bool, string, *git.Signature, error) {
|
||||
if err := pr.LoadBaseRepoCtx(ctx); err != nil {
|
||||
if err := pr.LoadBaseRepo(ctx); err != nil {
|
||||
log.Error("Unable to get Base Repo for pull request")
|
||||
return false, "", nil, err
|
||||
}
|
||||
|
@@ -188,8 +188,8 @@ func handlePull(pullID int64, sha string) {
|
||||
// We get the latest sha commit hash again to handle the case where the check of a previous push
|
||||
// did not succeed or was not finished yet.
|
||||
|
||||
if err = pr.LoadHeadRepoCtx(ctx); err != nil {
|
||||
log.Error("pull[%d] LoadHeadRepoCtx: %v", pr.ID, err)
|
||||
if err = pr.LoadHeadRepo(ctx); err != nil {
|
||||
log.Error("pull[%d] LoadHeadRepo: %v", pr.ID, err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -244,8 +244,8 @@ func handlePull(pullID int64, sha string) {
|
||||
if pr.BaseRepoID == pr.HeadRepoID {
|
||||
baseGitRepo = headGitRepo
|
||||
} else {
|
||||
if err = pr.LoadBaseRepoCtx(ctx); err != nil {
|
||||
log.Error("LoadBaseRepoCtx: %v", err)
|
||||
if err = pr.LoadBaseRepo(ctx); err != nil {
|
||||
log.Error("LoadBaseRepo: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@@ -5,6 +5,8 @@
|
||||
package comments
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
issues_model "code.gitea.io/gitea/models/issues"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
@@ -14,7 +16,7 @@ import (
|
||||
)
|
||||
|
||||
// CreateIssueComment creates a plain issue comment.
|
||||
func CreateIssueComment(doer *user_model.User, repo *repo_model.Repository, issue *issues_model.Issue, content string, attachments []string) (*issues_model.Comment, error) {
|
||||
func CreateIssueComment(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, issue *issues_model.Issue, content string, attachments []string) (*issues_model.Comment, error) {
|
||||
comment, err := issues_model.CreateComment(&issues_model.CreateCommentOptions{
|
||||
Type: issues_model.CommentTypeComment,
|
||||
Doer: doer,
|
||||
@@ -27,27 +29,27 @@ func CreateIssueComment(doer *user_model.User, repo *repo_model.Repository, issu
|
||||
return nil, err
|
||||
}
|
||||
|
||||
mentions, err := issues_model.FindAndUpdateIssueMentions(db.DefaultContext, issue, doer, comment.Content)
|
||||
mentions, err := issues_model.FindAndUpdateIssueMentions(ctx, issue, doer, comment.Content)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
notification.NotifyCreateIssueComment(doer, repo, issue, comment, mentions)
|
||||
notification.NotifyCreateIssueComment(ctx, doer, repo, issue, comment, mentions)
|
||||
|
||||
return comment, nil
|
||||
}
|
||||
|
||||
// UpdateComment updates information of comment.
|
||||
func UpdateComment(c *issues_model.Comment, doer *user_model.User, oldContent string) error {
|
||||
func UpdateComment(ctx context.Context, c *issues_model.Comment, doer *user_model.User, oldContent string) error {
|
||||
needsContentHistory := c.Content != oldContent &&
|
||||
(c.Type == issues_model.CommentTypeComment || c.Type == issues_model.CommentTypeReview || c.Type == issues_model.CommentTypeCode)
|
||||
if needsContentHistory {
|
||||
hasContentHistory, err := issues_model.HasIssueContentHistory(db.DefaultContext, c.IssueID, c.ID)
|
||||
hasContentHistory, err := issues_model.HasIssueContentHistory(ctx, c.IssueID, c.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !hasContentHistory {
|
||||
if err = issues_model.SaveIssueContentHistory(db.DefaultContext, c.PosterID, c.IssueID, c.ID,
|
||||
if err = issues_model.SaveIssueContentHistory(ctx, c.PosterID, c.IssueID, c.ID,
|
||||
c.CreatedUnix, oldContent, true); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -59,33 +61,27 @@ func UpdateComment(c *issues_model.Comment, doer *user_model.User, oldContent st
|
||||
}
|
||||
|
||||
if needsContentHistory {
|
||||
err := issues_model.SaveIssueContentHistory(db.DefaultContext, doer.ID, c.IssueID, c.ID, timeutil.TimeStampNow(), c.Content, false)
|
||||
err := issues_model.SaveIssueContentHistory(ctx, doer.ID, c.IssueID, c.ID, timeutil.TimeStampNow(), c.Content, false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
notification.NotifyUpdateComment(doer, c, oldContent)
|
||||
notification.NotifyUpdateComment(ctx, doer, c, oldContent)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeleteComment deletes the comment
|
||||
func DeleteComment(doer *user_model.User, comment *issues_model.Comment) error {
|
||||
ctx, committer, err := db.TxContext(db.DefaultContext)
|
||||
func DeleteComment(ctx context.Context, doer *user_model.User, comment *issues_model.Comment) error {
|
||||
err := db.AutoTx(ctx, func(ctx context.Context) error {
|
||||
return issues_model.DeleteComment(ctx, comment)
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer committer.Close()
|
||||
|
||||
if err := issues_model.DeleteComment(ctx, comment); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := committer.Commit(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
notification.NotifyDeleteComment(doer, comment)
|
||||
notification.NotifyDeleteComment(ctx, doer, comment)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@@ -51,13 +51,13 @@ func ToggleAssignee(issue *issues_model.Issue, doer *user_model.User, assigneeID
|
||||
return
|
||||
}
|
||||
|
||||
assignee, err1 := user_model.GetUserByID(assigneeID)
|
||||
assignee, err1 := user_model.GetUserByIDCtx(db.DefaultContext, assigneeID)
|
||||
if err1 != nil {
|
||||
err = err1
|
||||
return
|
||||
}
|
||||
|
||||
notification.NotifyIssueChangeAssignee(doer, issue, assignee, removed, comment)
|
||||
notification.NotifyIssueChangeAssignee(db.DefaultContext, doer, issue, assignee, removed, comment)
|
||||
|
||||
return removed, comment, err
|
||||
}
|
||||
@@ -75,7 +75,7 @@ func ReviewRequest(issue *issues_model.Issue, doer, reviewer *user_model.User, i
|
||||
}
|
||||
|
||||
if comment != nil {
|
||||
notification.NotifyPullReviewRequest(doer, issue, reviewer, isAdd, comment)
|
||||
notification.NotifyPullReviewRequest(db.DefaultContext, doer, issue, reviewer, isAdd, comment)
|
||||
}
|
||||
|
||||
return comment, err
|
||||
@@ -246,7 +246,7 @@ func TeamReviewRequest(issue *issues_model.Issue, doer *user_model.User, reviewe
|
||||
}
|
||||
|
||||
// notify all user in this team
|
||||
if err = comment.LoadIssue(); err != nil {
|
||||
if err = comment.LoadIssue(db.DefaultContext); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -262,7 +262,7 @@ func TeamReviewRequest(issue *issues_model.Issue, doer *user_model.User, reviewe
|
||||
continue
|
||||
}
|
||||
comment.AssigneeID = member.ID
|
||||
notification.NotifyPullReviewRequest(doer, issue, member, isAdd, comment)
|
||||
notification.NotifyPullReviewRequest(db.DefaultContext, doer, issue, member, isAdd, comment)
|
||||
}
|
||||
|
||||
return comment, err
|
||||
|
@@ -5,6 +5,7 @@
|
||||
package issue
|
||||
|
||||
import (
|
||||
"code.gitea.io/gitea/models/db"
|
||||
issues_model "code.gitea.io/gitea/models/issues"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/notification"
|
||||
@@ -18,7 +19,7 @@ func ChangeContent(issue *issues_model.Issue, doer *user_model.User, content str
|
||||
return err
|
||||
}
|
||||
|
||||
notification.NotifyIssueChangeContent(doer, issue, oldContent)
|
||||
notification.NotifyIssueChangeContent(db.DefaultContext, doer, issue, oldContent)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@@ -38,12 +38,12 @@ func NewIssue(repo *repo_model.Repository, issue *issues_model.Issue, labelIDs [
|
||||
return err
|
||||
}
|
||||
|
||||
notification.NotifyNewIssue(issue, mentions)
|
||||
notification.NotifyNewIssue(db.DefaultContext, issue, mentions)
|
||||
if len(issue.Labels) > 0 {
|
||||
notification.NotifyIssueChangeLabels(issue.Poster, issue, issue.Labels, nil)
|
||||
notification.NotifyIssueChangeLabels(db.DefaultContext, issue.Poster, issue, issue.Labels, nil)
|
||||
}
|
||||
if issue.Milestone != nil {
|
||||
notification.NotifyIssueChangeMilestone(issue.Poster, issue, 0)
|
||||
notification.NotifyIssueChangeMilestone(db.DefaultContext, issue.Poster, issue, 0)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -58,7 +58,7 @@ func ChangeTitle(issue *issues_model.Issue, doer *user_model.User, title string)
|
||||
return
|
||||
}
|
||||
|
||||
notification.NotifyIssueChangeTitle(doer, issue, oldTitle)
|
||||
notification.NotifyIssueChangeTitle(db.DefaultContext, doer, issue, oldTitle)
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -72,7 +72,7 @@ func ChangeIssueRef(issue *issues_model.Issue, doer *user_model.User, ref string
|
||||
return err
|
||||
}
|
||||
|
||||
notification.NotifyIssueChangeRef(doer, issue, oldRef)
|
||||
notification.NotifyIssueChangeRef(db.DefaultContext, doer, issue, oldRef)
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -135,10 +135,10 @@ func UpdateAssignees(issue *issues_model.Issue, oneAssignee string, multipleAssi
|
||||
// DeleteIssue deletes an issue
|
||||
func DeleteIssue(doer *user_model.User, gitRepo *git.Repository, issue *issues_model.Issue) error {
|
||||
// load issue before deleting it
|
||||
if err := issue.LoadAttributes(db.DefaultContext); err != nil {
|
||||
if err := issue.LoadAttributes(gitRepo.Ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := issue.LoadPullRequest(); err != nil {
|
||||
if err := issue.LoadPullRequest(gitRepo.Ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -154,7 +154,7 @@ func DeleteIssue(doer *user_model.User, gitRepo *git.Repository, issue *issues_m
|
||||
}
|
||||
}
|
||||
|
||||
notification.NotifyDeleteIssue(doer, issue)
|
||||
notification.NotifyDeleteIssue(gitRepo.Ctx, doer, issue)
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -162,7 +162,7 @@ func DeleteIssue(doer *user_model.User, gitRepo *git.Repository, issue *issues_m
|
||||
// AddAssigneeIfNotAssigned adds an assignee only if he isn't already assigned to the issue.
|
||||
// Also checks for access of assigned user
|
||||
func AddAssigneeIfNotAssigned(issue *issues_model.Issue, doer *user_model.User, assigneeID int64) (err error) {
|
||||
assignee, err := user_model.GetUserByID(assigneeID)
|
||||
assignee, err := user_model.GetUserByIDCtx(db.DefaultContext, assigneeID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@@ -18,7 +18,7 @@ func ClearLabels(issue *issues_model.Issue, doer *user_model.User) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
notification.NotifyIssueClearLabels(doer, issue)
|
||||
notification.NotifyIssueClearLabels(db.DefaultContext, doer, issue)
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -29,7 +29,7 @@ func AddLabel(issue *issues_model.Issue, doer *user_model.User, label *issues_mo
|
||||
return err
|
||||
}
|
||||
|
||||
notification.NotifyIssueChangeLabels(doer, issue, []*issues_model.Label{label}, nil)
|
||||
notification.NotifyIssueChangeLabels(db.DefaultContext, doer, issue, []*issues_model.Label{label}, nil)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ func AddLabels(issue *issues_model.Issue, doer *user_model.User, labels []*issue
|
||||
return err
|
||||
}
|
||||
|
||||
notification.NotifyIssueChangeLabels(doer, issue, labels, nil)
|
||||
notification.NotifyIssueChangeLabels(db.DefaultContext, doer, issue, labels, nil)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ func RemoveLabel(issue *issues_model.Issue, doer *user_model.User, label *issues
|
||||
return err
|
||||
}
|
||||
|
||||
notification.NotifyIssueChangeLabels(doer, issue, nil, []*issues_model.Label{label})
|
||||
notification.NotifyIssueChangeLabels(db.DefaultContext, doer, issue, nil, []*issues_model.Label{label})
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -89,6 +89,6 @@ func ReplaceLabels(issue *issues_model.Issue, doer *user_model.User, labels []*i
|
||||
return err
|
||||
}
|
||||
|
||||
notification.NotifyIssueChangeLabels(doer, issue, labels, old)
|
||||
notification.NotifyIssueChangeLabels(db.DefaultContext, doer, issue, labels, old)
|
||||
return nil
|
||||
}
|
||||
|
@@ -79,7 +79,7 @@ func ChangeMilestoneAssign(issue *issues_model.Issue, doer *user_model.User, old
|
||||
return fmt.Errorf("Commit: %w", err)
|
||||
}
|
||||
|
||||
notification.NotifyIssueChangeMilestone(doer, issue, oldMilestoneID)
|
||||
notification.NotifyIssueChangeMilestone(db.DefaultContext, doer, issue, oldMilestoneID)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@@ -38,7 +38,7 @@ func changeStatusCtx(ctx context.Context, issue *issues_model.Issue, doer *user_
|
||||
}
|
||||
}
|
||||
|
||||
notification.NotifyIssueChangeStatus(doer, issue, comment, closed)
|
||||
notification.NotifyIssueChangeStatus(ctx, doer, issue, comment, closed)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@@ -57,7 +57,7 @@ func GetListLockHandler(ctx *context.Context) {
|
||||
})
|
||||
return
|
||||
}
|
||||
repository.MustOwner()
|
||||
repository.MustOwner(ctx)
|
||||
|
||||
authenticated := authenticate(ctx, repository, rv.Authorization, true, false)
|
||||
if !authenticated {
|
||||
@@ -144,7 +144,7 @@ func PostLockHandler(ctx *context.Context) {
|
||||
})
|
||||
return
|
||||
}
|
||||
repository.MustOwner()
|
||||
repository.MustOwner(ctx)
|
||||
|
||||
authenticated := authenticate(ctx, repository, authorization, true, true)
|
||||
if !authenticated {
|
||||
@@ -211,7 +211,7 @@ func VerifyLockHandler(ctx *context.Context) {
|
||||
})
|
||||
return
|
||||
}
|
||||
repository.MustOwner()
|
||||
repository.MustOwner(ctx)
|
||||
|
||||
authenticated := authenticate(ctx, repository, authorization, true, true)
|
||||
if !authenticated {
|
||||
@@ -277,7 +277,7 @@ func UnLockHandler(ctx *context.Context) {
|
||||
})
|
||||
return
|
||||
}
|
||||
repository.MustOwner()
|
||||
repository.MustOwner(ctx)
|
||||
|
||||
authenticated := authenticate(ctx, repository, authorization, true, true)
|
||||
if !authenticated {
|
||||
|
@@ -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),
|
||||
|
@@ -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,
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
}
|
||||
|
@@ -84,7 +84,7 @@ func TestGiteaUploadRepo(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, labels, 12)
|
||||
|
||||
releases, err := repo_model.GetReleasesByRepoID(repo.ID, repo_model.FindReleasesOptions{
|
||||
releases, err := repo_model.GetReleasesByRepoID(db.DefaultContext, repo.ID, repo_model.FindReleasesOptions{
|
||||
ListOptions: db.ListOptions{
|
||||
PageSize: 10,
|
||||
Page: 0,
|
||||
@@ -94,7 +94,7 @@ func TestGiteaUploadRepo(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, releases, 8)
|
||||
|
||||
releases, err = repo_model.GetReleasesByRepoID(repo.ID, repo_model.FindReleasesOptions{
|
||||
releases, err = repo_model.GetReleasesByRepoID(db.DefaultContext, repo.ID, repo_model.FindReleasesOptions{
|
||||
ListOptions: db.ListOptions{
|
||||
PageSize: 10,
|
||||
Page: 0,
|
||||
@@ -104,14 +104,14 @@ func TestGiteaUploadRepo(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, releases, 1)
|
||||
|
||||
issues, err := issues_model.Issues(&issues_model.IssuesOptions{
|
||||
issues, err := issues_model.Issues(db.DefaultContext, &issues_model.IssuesOptions{
|
||||
RepoID: repo.ID,
|
||||
IsPull: util.OptionalBoolFalse,
|
||||
SortType: "oldest",
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, issues, 15)
|
||||
assert.NoError(t, issues[0].LoadDiscussComments())
|
||||
assert.NoError(t, issues[0].LoadDiscussComments(db.DefaultContext))
|
||||
assert.Empty(t, issues[0].Comments)
|
||||
|
||||
pulls, _, err := issues_model.PullRequests(repo.ID, &issues_model.PullRequestsOptions{
|
||||
@@ -119,8 +119,8 @@ func TestGiteaUploadRepo(t *testing.T) {
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, pulls, 30)
|
||||
assert.NoError(t, pulls[0].LoadIssue())
|
||||
assert.NoError(t, pulls[0].Issue.LoadDiscussComments())
|
||||
assert.NoError(t, pulls[0].LoadIssue(db.DefaultContext))
|
||||
assert.NoError(t, pulls[0].Issue.LoadDiscussComments(db.DefaultContext))
|
||||
assert.Len(t, pulls[0].Issue.Comments, 2)
|
||||
}
|
||||
|
||||
|
@@ -459,18 +459,18 @@ func SyncPullMirror(ctx context.Context, repoID int64) bool {
|
||||
log.Error("SyncMirrors [repo: %-v]: unable to GetRefCommitID [ref_name: %s]: %v", m.Repo, result.refName, err)
|
||||
continue
|
||||
}
|
||||
notification.NotifySyncPushCommits(m.Repo.MustOwner(), m.Repo, &repo_module.PushUpdateOptions{
|
||||
notification.NotifySyncPushCommits(ctx, m.Repo.MustOwner(ctx), m.Repo, &repo_module.PushUpdateOptions{
|
||||
RefFullName: result.refName,
|
||||
OldCommitID: git.EmptySHA,
|
||||
NewCommitID: commitID,
|
||||
}, repo_module.NewPushCommits())
|
||||
notification.NotifySyncCreateRef(m.Repo.MustOwner(), m.Repo, tp, result.refName, commitID)
|
||||
notification.NotifySyncCreateRef(ctx, m.Repo.MustOwner(ctx), m.Repo, tp, result.refName, commitID)
|
||||
continue
|
||||
}
|
||||
|
||||
// Delete reference
|
||||
if result.newCommitID == gitShortEmptySha {
|
||||
notification.NotifySyncDeleteRef(m.Repo.MustOwner(), m.Repo, tp, result.refName)
|
||||
notification.NotifySyncDeleteRef(ctx, m.Repo.MustOwner(ctx), m.Repo, tp, result.refName)
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -498,7 +498,7 @@ func SyncPullMirror(ctx context.Context, repoID int64) bool {
|
||||
|
||||
theCommits.CompareURL = m.Repo.ComposeCompareURL(oldCommitID, newCommitID)
|
||||
|
||||
notification.NotifySyncPushCommits(m.Repo.MustOwner(), m.Repo, &repo_module.PushUpdateOptions{
|
||||
notification.NotifySyncPushCommits(ctx, m.Repo.MustOwner(ctx), m.Repo, &repo_module.PushUpdateOptions{
|
||||
RefFullName: result.refName,
|
||||
OldCommitID: oldCommitID,
|
||||
NewCommitID: newCommitID,
|
||||
|
@@ -108,12 +108,12 @@ func createPackageAndAddFile(pvci *PackageCreationInfo, pfci *PackageFileCreatio
|
||||
}
|
||||
|
||||
if created {
|
||||
pd, err := packages_model.GetPackageDescriptor(ctx, pv)
|
||||
pd, err := packages_model.GetPackageDescriptor(db.DefaultContext, pv)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
notification.NotifyPackageCreate(pvci.Creator, pd)
|
||||
notification.NotifyPackageCreate(db.DefaultContext, pvci.Creator, pd)
|
||||
}
|
||||
|
||||
return pv, pf, nil
|
||||
@@ -409,7 +409,7 @@ func RemovePackageVersion(doer *user_model.User, pv *packages_model.PackageVersi
|
||||
return err
|
||||
}
|
||||
|
||||
notification.NotifyPackageDelete(doer, pd)
|
||||
notification.NotifyPackageDelete(db.DefaultContext, doer, pd)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@@ -48,7 +48,7 @@ var (
|
||||
func AddToTaskQueue(pr *issues_model.PullRequest) {
|
||||
err := prPatchCheckerQueue.PushFunc(strconv.FormatInt(pr.ID, 10), func() error {
|
||||
pr.Status = issues_model.PullRequestStatusChecking
|
||||
err := pr.UpdateColsIfNotMerged("status")
|
||||
err := pr.UpdateColsIfNotMerged(db.DefaultContext, "status")
|
||||
if err != nil {
|
||||
log.Error("AddToTaskQueue.UpdateCols[%d].(add to queue): %v", pr.ID, err)
|
||||
} else {
|
||||
@@ -68,7 +68,7 @@ func CheckPullMergable(stdCtx context.Context, doer *user_model.User, perm *acce
|
||||
return ErrHasMerged
|
||||
}
|
||||
|
||||
if err := pr.LoadIssueCtx(ctx); err != nil {
|
||||
if err := pr.LoadIssue(ctx); err != nil {
|
||||
return err
|
||||
} else if pr.Issue.IsClosed {
|
||||
return ErrIsClosed
|
||||
@@ -142,7 +142,7 @@ func isSignedIfRequired(ctx context.Context, pr *issues_model.PullRequest, doer
|
||||
|
||||
// checkAndUpdateStatus checks if pull request is possible to leaving checking status,
|
||||
// and set to be either conflict or mergeable.
|
||||
func checkAndUpdateStatus(pr *issues_model.PullRequest) {
|
||||
func checkAndUpdateStatus(ctx context.Context, pr *issues_model.PullRequest) {
|
||||
// Status is not changed to conflict means mergeable.
|
||||
if pr.Status == issues_model.PullRequestStatusChecking {
|
||||
pr.Status = issues_model.PullRequestStatusMergeable
|
||||
@@ -155,7 +155,7 @@ func checkAndUpdateStatus(pr *issues_model.PullRequest) {
|
||||
}
|
||||
|
||||
if !has {
|
||||
if err := pr.UpdateColsIfNotMerged("merge_base", "status", "conflicted_files", "changed_protected_files"); err != nil {
|
||||
if err := pr.UpdateColsIfNotMerged(ctx, "merge_base", "status", "conflicted_files", "changed_protected_files"); err != nil {
|
||||
log.Error("Update[%d]: %v", pr.ID, err)
|
||||
}
|
||||
}
|
||||
@@ -232,7 +232,7 @@ func getMergeCommit(ctx context.Context, pr *issues_model.PullRequest) (*git.Com
|
||||
// manuallyMerged checks if a pull request got manually merged
|
||||
// When a pull request got manually merged mark the pull request as merged
|
||||
func manuallyMerged(ctx context.Context, pr *issues_model.PullRequest) bool {
|
||||
if err := pr.LoadBaseRepoCtx(ctx); err != nil {
|
||||
if err := pr.LoadBaseRepo(ctx); err != nil {
|
||||
log.Error("PullRequest[%d].LoadBaseRepo: %v", pr.ID, err)
|
||||
return false
|
||||
}
|
||||
@@ -278,7 +278,7 @@ func manuallyMerged(ctx context.Context, pr *issues_model.PullRequest) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
notification.NotifyMergePullRequest(pr, merger)
|
||||
notification.NotifyMergePullRequest(ctx, merger, pr)
|
||||
|
||||
log.Info("manuallyMerged[%d]: Marked as manually merged into %s/%s by commit id: %s", pr.ID, pr.BaseRepo.Name, pr.BaseBranch, commit.ID.String())
|
||||
return true
|
||||
@@ -346,7 +346,7 @@ func testPR(id int64) {
|
||||
}
|
||||
return
|
||||
}
|
||||
checkAndUpdateStatus(pr)
|
||||
checkAndUpdateStatus(ctx, pr)
|
||||
}
|
||||
|
||||
// CheckPrsForBaseBranch check all pulls with bseBrannch
|
||||
|
@@ -101,7 +101,7 @@ func IsPullCommitStatusPass(ctx context.Context, pr *issues_model.PullRequest) (
|
||||
// GetPullRequestCommitStatusState returns pull request merged commit status state
|
||||
func GetPullRequestCommitStatusState(ctx context.Context, pr *issues_model.PullRequest) (structs.CommitStatusState, error) {
|
||||
// Ensure HeadRepo is loaded
|
||||
if err := pr.LoadHeadRepoCtx(ctx); err != nil {
|
||||
if err := pr.LoadHeadRepo(ctx); err != nil {
|
||||
return "", errors.Wrap(err, "LoadHeadRepo")
|
||||
}
|
||||
|
||||
@@ -129,7 +129,7 @@ func GetPullRequestCommitStatusState(ctx context.Context, pr *issues_model.PullR
|
||||
return "", err
|
||||
}
|
||||
|
||||
if err := pr.LoadBaseRepoCtx(ctx); err != nil {
|
||||
if err := pr.LoadBaseRepo(ctx); err != nil {
|
||||
return "", errors.Wrap(err, "LoadBaseRepo")
|
||||
}
|
||||
|
||||
|
@@ -23,7 +23,7 @@ func SetAllowEdits(ctx context.Context, doer *user_model.User, pr *issues_model.
|
||||
return ErrUserHasNoPermissionForAction
|
||||
}
|
||||
|
||||
if err := pr.LoadHeadRepo(); err != nil {
|
||||
if err := pr.LoadHeadRepo(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
@@ -40,18 +40,18 @@ import (
|
||||
)
|
||||
|
||||
// GetDefaultMergeMessage returns default message used when merging pull request
|
||||
func GetDefaultMergeMessage(baseGitRepo *git.Repository, pr *issues_model.PullRequest, mergeStyle repo_model.MergeStyle) (string, error) {
|
||||
if err := pr.LoadHeadRepo(); err != nil {
|
||||
func GetDefaultMergeMessage(ctx context.Context, baseGitRepo *git.Repository, pr *issues_model.PullRequest, mergeStyle repo_model.MergeStyle) (string, error) {
|
||||
if err := pr.LoadHeadRepo(ctx); err != nil {
|
||||
return "", err
|
||||
}
|
||||
if err := pr.LoadBaseRepo(); err != nil {
|
||||
if err := pr.LoadBaseRepo(ctx); err != nil {
|
||||
return "", err
|
||||
}
|
||||
if pr.BaseRepo == nil {
|
||||
return "", repo_model.ErrRepoNotExist{ID: pr.BaseRepoID}
|
||||
}
|
||||
|
||||
if err := pr.LoadIssue(); err != nil {
|
||||
if err := pr.LoadIssue(ctx); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ func GetDefaultMergeMessage(baseGitRepo *git.Repository, pr *issues_model.PullRe
|
||||
vars["HeadRepoOwnerName"] = pr.HeadRepo.OwnerName
|
||||
vars["HeadRepoName"] = pr.HeadRepo.Name
|
||||
}
|
||||
refs, err := pr.ResolveCrossReferences(baseGitRepo.Ctx)
|
||||
refs, err := pr.ResolveCrossReferences(ctx)
|
||||
if err == nil {
|
||||
closeIssueIndexes := make([]string, 0, len(refs))
|
||||
closeWord := "close"
|
||||
@@ -134,10 +134,10 @@ func GetDefaultMergeMessage(baseGitRepo *git.Repository, pr *issues_model.PullRe
|
||||
// Merge merges pull request to base repository.
|
||||
// Caller should check PR is ready to be merged (review and status checks)
|
||||
func Merge(ctx context.Context, pr *issues_model.PullRequest, doer *user_model.User, baseGitRepo *git.Repository, mergeStyle repo_model.MergeStyle, expectedHeadCommitID, message string, wasAutoMerged bool) error {
|
||||
if err := pr.LoadHeadRepo(); err != nil {
|
||||
if err := pr.LoadHeadRepo(ctx); err != nil {
|
||||
log.Error("LoadHeadRepo: %v", err)
|
||||
return fmt.Errorf("LoadHeadRepo: %w", err)
|
||||
} else if err := pr.LoadBaseRepo(); err != nil {
|
||||
} else if err := pr.LoadBaseRepo(ctx); err != nil {
|
||||
log.Error("LoadBaseRepo: %v", err)
|
||||
return fmt.Errorf("LoadBaseRepo: %w", err)
|
||||
}
|
||||
@@ -179,24 +179,24 @@ func Merge(ctx context.Context, pr *issues_model.PullRequest, doer *user_model.U
|
||||
pr.MergerID = doer.ID
|
||||
|
||||
if _, err := pr.SetMerged(hammerCtx); err != nil {
|
||||
log.Error("setMerged [%d]: %v", pr.ID, err)
|
||||
log.Error("SetMerged [%d]: %v", pr.ID, err)
|
||||
}
|
||||
|
||||
if err := pr.LoadIssueCtx(hammerCtx); err != nil {
|
||||
log.Error("loadIssue [%d]: %v", pr.ID, err)
|
||||
if err := pr.LoadIssue(hammerCtx); err != nil {
|
||||
log.Error("LoadIssue [%d]: %v", pr.ID, err)
|
||||
}
|
||||
|
||||
if err := pr.Issue.LoadRepo(hammerCtx); err != nil {
|
||||
log.Error("loadRepo for issue [%d]: %v", pr.ID, err)
|
||||
log.Error("LoadRepo for issue [%d]: %v", pr.ID, err)
|
||||
}
|
||||
if err := pr.Issue.Repo.GetOwner(hammerCtx); err != nil {
|
||||
log.Error("GetOwner for issue repo [%d]: %v", pr.ID, err)
|
||||
log.Error("GetOwner for PR [%d]: %v", pr.ID, err)
|
||||
}
|
||||
|
||||
if wasAutoMerged {
|
||||
notification.NotifyAutoMergePullRequest(pr, doer)
|
||||
notification.NotifyAutoMergePullRequest(hammerCtx, doer, pr)
|
||||
} else {
|
||||
notification.NotifyMergePullRequest(pr, doer)
|
||||
notification.NotifyMergePullRequest(hammerCtx, doer, pr)
|
||||
}
|
||||
|
||||
// Reset cached commit count
|
||||
@@ -210,7 +210,7 @@ func Merge(ctx context.Context, pr *issues_model.PullRequest, doer *user_model.U
|
||||
}
|
||||
|
||||
for _, ref := range refs {
|
||||
if err = ref.LoadIssueCtx(hammerCtx); err != nil {
|
||||
if err = ref.LoadIssue(hammerCtx); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = ref.Issue.LoadRepo(hammerCtx); err != nil {
|
||||
@@ -511,7 +511,7 @@ func rawMerge(ctx context.Context, pr *issues_model.PullRequest, doer *user_mode
|
||||
return "", err
|
||||
}
|
||||
|
||||
if err = pr.Issue.LoadPoster(); err != nil {
|
||||
if err = pr.Issue.LoadPoster(ctx); err != nil {
|
||||
log.Error("LoadPoster: %v", err)
|
||||
return "", fmt.Errorf("LoadPoster: %w", err)
|
||||
}
|
||||
@@ -767,7 +767,7 @@ func IsUserAllowedToMerge(ctx context.Context, pr *issues_model.PullRequest, p a
|
||||
|
||||
// CheckPullBranchProtections checks whether the PR is ready to be merged (reviews and status checks)
|
||||
func CheckPullBranchProtections(ctx context.Context, pr *issues_model.PullRequest, skipProtectedFilesCheck bool) (err error) {
|
||||
if err = pr.LoadBaseRepoCtx(ctx); err != nil {
|
||||
if err = pr.LoadBaseRepo(ctx); err != nil {
|
||||
return fmt.Errorf("LoadBaseRepo: %w", err)
|
||||
}
|
||||
|
||||
@@ -878,7 +878,7 @@ func MergedManually(pr *issues_model.PullRequest, doer *user_model.User, baseGit
|
||||
return err
|
||||
}
|
||||
|
||||
notification.NotifyMergePullRequest(pr, doer)
|
||||
notification.NotifyMergePullRequest(baseGitRepo.Ctx, doer, pr)
|
||||
log.Info("manuallyMerged[%d]: Marked as manually merged into %s/%s by commit id: %s", pr.ID, pr.BaseRepo.Name, pr.BaseBranch, commitID)
|
||||
return nil
|
||||
}
|
||||
|
@@ -30,7 +30,7 @@ import (
|
||||
|
||||
// DownloadDiffOrPatch will write the patch for the pr to the writer
|
||||
func DownloadDiffOrPatch(ctx context.Context, pr *issues_model.PullRequest, w io.Writer, patch, binary bool) error {
|
||||
if err := pr.LoadBaseRepoCtx(ctx); err != nil {
|
||||
if err := pr.LoadBaseRepo(ctx); err != nil {
|
||||
log.Error("Unable to load base repository ID %d for pr #%d [%d]", pr.BaseRepoID, pr.Index, pr.ID)
|
||||
return err
|
||||
}
|
||||
|
@@ -82,12 +82,12 @@ func NewPullRequest(ctx context.Context, repo *repo_model.Repository, pull *issu
|
||||
return err
|
||||
}
|
||||
|
||||
notification.NotifyNewPullRequest(pr, mentions)
|
||||
notification.NotifyNewPullRequest(prCtx, pr, mentions)
|
||||
if len(pull.Labels) > 0 {
|
||||
notification.NotifyIssueChangeLabels(pull.Poster, pull, pull.Labels, nil)
|
||||
notification.NotifyIssueChangeLabels(prCtx, pull.Poster, pull, pull.Labels, nil)
|
||||
}
|
||||
if pull.Milestone != nil {
|
||||
notification.NotifyIssueChangeMilestone(pull.Poster, pull, 0)
|
||||
notification.NotifyIssueChangeMilestone(prCtx, pull.Poster, pull, 0)
|
||||
}
|
||||
|
||||
// add first push codes comment
|
||||
@@ -172,7 +172,7 @@ func ChangeTargetBranch(ctx context.Context, pr *issues_model.PullRequest, doer
|
||||
}
|
||||
|
||||
// Check if pull request for the new target branch already exists
|
||||
existingPr, err := issues_model.GetUnmergedPullRequest(pr.HeadRepoID, pr.BaseRepoID, pr.HeadBranch, targetBranch, issues_model.PullRequestFlowGithub)
|
||||
existingPr, err := issues_model.GetUnmergedPullRequest(ctx, pr.HeadRepoID, pr.BaseRepoID, pr.HeadBranch, targetBranch, issues_model.PullRequestFlowGithub)
|
||||
if existingPr != nil {
|
||||
return issues_model.ErrPullRequestAlreadyExists{
|
||||
ID: existingPr.ID,
|
||||
@@ -210,7 +210,7 @@ func ChangeTargetBranch(ctx context.Context, pr *issues_model.PullRequest, doer
|
||||
pr.CommitsAhead = divergence.Ahead
|
||||
pr.CommitsBehind = divergence.Behind
|
||||
|
||||
if err := pr.UpdateColsIfNotMerged("merge_base", "status", "conflicted_files", "changed_protected_files", "base_branch", "commits_ahead", "commits_behind"); err != nil {
|
||||
if err := pr.UpdateColsIfNotMerged(ctx, "merge_base", "status", "conflicted_files", "changed_protected_files", "base_branch", "commits_ahead", "commits_behind"); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -231,9 +231,9 @@ func ChangeTargetBranch(ctx context.Context, pr *issues_model.PullRequest, doer
|
||||
}
|
||||
|
||||
func checkForInvalidation(ctx context.Context, requests issues_model.PullRequestList, repoID int64, doer *user_model.User, branch string) error {
|
||||
repo, err := repo_model.GetRepositoryByID(repoID)
|
||||
repo, err := repo_model.GetRepositoryByIDCtx(ctx, repoID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("GetRepositoryByID: %w", err)
|
||||
return fmt.Errorf("GetRepositoryByIDCtx: %w", err)
|
||||
}
|
||||
gitRepo, err := git.OpenRepository(ctx, repo.RepoPath())
|
||||
if err != nil {
|
||||
@@ -301,7 +301,7 @@ func AddTestPullRequestTask(doer *user_model.User, repoID int64, branch string,
|
||||
}
|
||||
|
||||
pr.Issue.PullRequest = pr
|
||||
notification.NotifyPullRequestSynchronized(doer, pr)
|
||||
notification.NotifyPullRequestSynchronized(ctx, doer, pr)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -320,7 +320,7 @@ func AddTestPullRequestTask(doer *user_model.User, repoID int64, branch string,
|
||||
AddToTaskQueue(pr)
|
||||
comment, err := issues_model.CreatePushPullComment(ctx, doer, pr, oldCommitID, newCommitID)
|
||||
if err == nil && comment != nil {
|
||||
notification.NotifyPullRequestPushCommits(doer, pr, comment)
|
||||
notification.NotifyPullRequestPushCommits(ctx, doer, pr, comment)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -352,14 +352,14 @@ func AddTestPullRequestTask(doer *user_model.User, repoID int64, branch string,
|
||||
// checkIfPRContentChanged checks if diff to target branch has changed by push
|
||||
// A commit can be considered to leave the PR untouched if the patch/diff with its merge base is unchanged
|
||||
func checkIfPRContentChanged(ctx context.Context, pr *issues_model.PullRequest, oldCommitID, newCommitID string) (hasChanged bool, err error) {
|
||||
if err = pr.LoadHeadRepoCtx(ctx); err != nil {
|
||||
if err = pr.LoadHeadRepo(ctx); err != nil {
|
||||
return false, fmt.Errorf("LoadHeadRepo: %w", err)
|
||||
} else if pr.HeadRepo == nil {
|
||||
// corrupt data assumed changed
|
||||
return true, nil
|
||||
}
|
||||
|
||||
if err = pr.LoadBaseRepoCtx(ctx); err != nil {
|
||||
if err = pr.LoadBaseRepo(ctx); err != nil {
|
||||
return false, fmt.Errorf("LoadBaseRepo: %w", err)
|
||||
}
|
||||
|
||||
@@ -430,22 +430,22 @@ func PushToBaseRepo(ctx context.Context, pr *issues_model.PullRequest) (err erro
|
||||
func pushToBaseRepoHelper(ctx context.Context, pr *issues_model.PullRequest, prefixHeadBranch string) (err error) {
|
||||
log.Trace("PushToBaseRepo[%d]: pushing commits to base repo '%s'", pr.BaseRepoID, pr.GetGitRefName())
|
||||
|
||||
if err := pr.LoadHeadRepoCtx(ctx); err != nil {
|
||||
if err := pr.LoadHeadRepo(ctx); err != nil {
|
||||
log.Error("Unable to load head repository for PR[%d] Error: %v", pr.ID, err)
|
||||
return err
|
||||
}
|
||||
headRepoPath := pr.HeadRepo.RepoPath()
|
||||
|
||||
if err := pr.LoadBaseRepoCtx(ctx); err != nil {
|
||||
if err := pr.LoadBaseRepo(ctx); err != nil {
|
||||
log.Error("Unable to load base repository for PR[%d] Error: %v", pr.ID, err)
|
||||
return err
|
||||
}
|
||||
baseRepoPath := pr.BaseRepo.RepoPath()
|
||||
|
||||
if err = pr.LoadIssue(); err != nil {
|
||||
if err = pr.LoadIssue(ctx); err != nil {
|
||||
return fmt.Errorf("unable to load issue %d for pr %d: %w", pr.IssueID, pr.ID, err)
|
||||
}
|
||||
if err = pr.Issue.LoadPoster(); err != nil {
|
||||
if err = pr.Issue.LoadPoster(ctx); err != nil {
|
||||
return fmt.Errorf("unable to load poster %d for pr %d: %w", pr.Issue.PosterID, pr.ID, err)
|
||||
}
|
||||
|
||||
@@ -485,7 +485,7 @@ func pushToBaseRepoHelper(ctx context.Context, pr *issues_model.PullRequest, pre
|
||||
// UpdateRef update refs/pull/id/head directly for agit flow pull request
|
||||
func UpdateRef(ctx context.Context, pr *issues_model.PullRequest) (err error) {
|
||||
log.Trace("UpdateRef[%d]: upgate pull request ref in base repo '%s'", pr.ID, pr.GetGitRefName())
|
||||
if err := pr.LoadBaseRepoCtx(ctx); err != nil {
|
||||
if err := pr.LoadBaseRepo(ctx); err != nil {
|
||||
log.Error("Unable to load base repository for PR[%d] Error: %v", pr.ID, err)
|
||||
return err
|
||||
}
|
||||
@@ -583,21 +583,21 @@ var commitMessageTrailersPattern = regexp.MustCompile(`(?:^|\n\n)(?:[\w-]+[ \t]*
|
||||
|
||||
// GetSquashMergeCommitMessages returns the commit messages between head and merge base (if there is one)
|
||||
func GetSquashMergeCommitMessages(ctx context.Context, pr *issues_model.PullRequest) string {
|
||||
if err := pr.LoadIssue(); err != nil {
|
||||
if err := pr.LoadIssue(ctx); err != nil {
|
||||
log.Error("Cannot load issue %d for PR id %d: Error: %v", pr.IssueID, pr.ID, err)
|
||||
return ""
|
||||
}
|
||||
|
||||
if err := pr.Issue.LoadPoster(); err != nil {
|
||||
if err := pr.Issue.LoadPoster(ctx); err != nil {
|
||||
log.Error("Cannot load poster %d for pr id %d, index %d Error: %v", pr.Issue.PosterID, pr.ID, pr.Index, err)
|
||||
return ""
|
||||
}
|
||||
|
||||
if pr.HeadRepo == nil {
|
||||
var err error
|
||||
pr.HeadRepo, err = repo_model.GetRepositoryByID(pr.HeadRepoID)
|
||||
pr.HeadRepo, err = repo_model.GetRepositoryByIDCtx(ctx, pr.HeadRepoID)
|
||||
if err != nil {
|
||||
log.Error("GetRepositoryById[%d]: %v", pr.HeadRepoID, err)
|
||||
log.Error("GetRepositoryByIdCtx[%d]: %v", pr.HeadRepoID, err)
|
||||
return ""
|
||||
}
|
||||
}
|
||||
@@ -743,10 +743,10 @@ func GetIssuesLastCommitStatus(ctx context.Context, issues issues_model.IssueLis
|
||||
|
||||
// GetIssuesAllCommitStatus returns a map of issue ID to a list of all statuses for the most recent commit as well as a map of issue ID to only the commit's latest status
|
||||
func GetIssuesAllCommitStatus(ctx context.Context, issues issues_model.IssueList) (map[int64][]*git_model.CommitStatus, map[int64]*git_model.CommitStatus, error) {
|
||||
if err := issues.LoadPullRequests(); err != nil {
|
||||
if err := issues.LoadPullRequests(ctx); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
if _, err := issues.LoadRepositories(); err != nil {
|
||||
if _, err := issues.LoadRepositories(ctx); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
@@ -802,7 +802,7 @@ func getAllCommitStatus(gitRepo *git.Repository, pr *issues_model.PullRequest) (
|
||||
// IsHeadEqualWithBranch returns if the commits of branchName are available in pull request head
|
||||
func IsHeadEqualWithBranch(ctx context.Context, pr *issues_model.PullRequest, branchName string) (bool, error) {
|
||||
var err error
|
||||
if err = pr.LoadBaseRepoCtx(ctx); err != nil {
|
||||
if err = pr.LoadBaseRepo(ctx); err != nil {
|
||||
return false, err
|
||||
}
|
||||
baseGitRepo, closer, err := git.RepositoryFromContextOrOpen(ctx, pr.BaseRepo.RepoPath())
|
||||
@@ -816,7 +816,7 @@ func IsHeadEqualWithBranch(ctx context.Context, pr *issues_model.PullRequest, br
|
||||
return false, err
|
||||
}
|
||||
|
||||
if err = pr.LoadHeadRepoCtx(ctx); err != nil {
|
||||
if err = pr.LoadHeadRepo(ctx); err != nil {
|
||||
return false, err
|
||||
}
|
||||
var headGitRepo *git.Repository
|
||||
|
@@ -8,6 +8,7 @@ package pull
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
issues_model "code.gitea.io/gitea/models/issues"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
"code.gitea.io/gitea/models/unit"
|
||||
@@ -40,18 +41,18 @@ func TestPullRequest_GetDefaultMergeMessage_InternalTracker(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
pr := unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: 2})
|
||||
|
||||
assert.NoError(t, pr.LoadBaseRepo())
|
||||
assert.NoError(t, pr.LoadBaseRepo(db.DefaultContext))
|
||||
gitRepo, err := git.OpenRepository(git.DefaultContext, pr.BaseRepo.RepoPath())
|
||||
assert.NoError(t, err)
|
||||
defer gitRepo.Close()
|
||||
|
||||
mergeMessage, err := GetDefaultMergeMessage(gitRepo, pr, "")
|
||||
mergeMessage, err := GetDefaultMergeMessage(db.DefaultContext, gitRepo, pr, "")
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "Merge pull request 'issue3' (#3) from branch2 into master", mergeMessage)
|
||||
|
||||
pr.BaseRepoID = 1
|
||||
pr.HeadRepoID = 2
|
||||
mergeMessage, err = GetDefaultMergeMessage(gitRepo, pr, "")
|
||||
mergeMessage, err = GetDefaultMergeMessage(db.DefaultContext, gitRepo, pr, "")
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "Merge pull request 'issue3' (#3) from user2/repo1:branch2 into master", mergeMessage)
|
||||
}
|
||||
@@ -70,12 +71,12 @@ func TestPullRequest_GetDefaultMergeMessage_ExternalTracker(t *testing.T) {
|
||||
|
||||
pr := unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: 2, BaseRepo: baseRepo})
|
||||
|
||||
assert.NoError(t, pr.LoadBaseRepo())
|
||||
assert.NoError(t, pr.LoadBaseRepo(db.DefaultContext))
|
||||
gitRepo, err := git.OpenRepository(git.DefaultContext, pr.BaseRepo.RepoPath())
|
||||
assert.NoError(t, err)
|
||||
defer gitRepo.Close()
|
||||
|
||||
mergeMessage, err := GetDefaultMergeMessage(gitRepo, pr, "")
|
||||
mergeMessage, err := GetDefaultMergeMessage(db.DefaultContext, gitRepo, pr, "")
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "Merge pull request 'issue3' (!3) from branch2 into master", mergeMessage)
|
||||
@@ -84,7 +85,7 @@ func TestPullRequest_GetDefaultMergeMessage_ExternalTracker(t *testing.T) {
|
||||
pr.HeadRepoID = 2
|
||||
pr.BaseRepo = nil
|
||||
pr.HeadRepo = nil
|
||||
mergeMessage, err = GetDefaultMergeMessage(gitRepo, pr, "")
|
||||
mergeMessage, err = GetDefaultMergeMessage(db.DefaultContext, gitRepo, pr, "")
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "Merge pull request 'issue3' (#3) from user2/repo2:branch2 into master", mergeMessage)
|
||||
|
@@ -67,7 +67,7 @@ func CreateCodeComment(ctx context.Context, doer *user_model.User, gitRepo *git.
|
||||
return nil, err
|
||||
}
|
||||
|
||||
notification.NotifyCreateIssueComment(doer, issue.Repo, issue, comment, mentions)
|
||||
notification.NotifyCreateIssueComment(ctx, doer, issue.Repo, issue, comment, mentions)
|
||||
|
||||
return comment, nil
|
||||
}
|
||||
@@ -119,12 +119,12 @@ var notEnoughLines = regexp.MustCompile(`exit status 128 - fatal: file .* has on
|
||||
// createCodeComment creates a plain code comment at the specified line / path
|
||||
func createCodeComment(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, issue *issues_model.Issue, content, treePath string, line, reviewID int64) (*issues_model.Comment, error) {
|
||||
var commitID, patch string
|
||||
if err := issue.LoadPullRequest(); err != nil {
|
||||
return nil, fmt.Errorf("GetPullRequestByIssueID: %w", err)
|
||||
if err := issue.LoadPullRequest(ctx); err != nil {
|
||||
return nil, fmt.Errorf("LoadPullRequest: %w", err)
|
||||
}
|
||||
pr := issue.PullRequest
|
||||
if err := pr.LoadBaseRepoCtx(ctx); err != nil {
|
||||
return nil, fmt.Errorf("LoadHeadRepo: %w", err)
|
||||
if err := pr.LoadBaseRepo(ctx); err != nil {
|
||||
return nil, fmt.Errorf("LoadBaseRepo: %w", err)
|
||||
}
|
||||
gitRepo, closer, err := git.RepositoryFromContextOrOpen(ctx, pr.BaseRepo.RepoPath())
|
||||
if err != nil {
|
||||
@@ -254,7 +254,7 @@ func SubmitReview(ctx context.Context, doer *user_model.User, gitRepo *git.Repos
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
notification.NotifyPullRequestReview(pr, review, comm, mentions)
|
||||
notification.NotifyPullRequestReview(ctx, pr, review, comm, mentions)
|
||||
|
||||
for _, lines := range review.CodeComments {
|
||||
for _, comments := range lines {
|
||||
@@ -263,7 +263,7 @@ func SubmitReview(ctx context.Context, doer *user_model.User, gitRepo *git.Repos
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
notification.NotifyPullRequestCodeComment(pr, codeComment, mentions)
|
||||
notification.NotifyPullRequestCodeComment(ctx, pr, codeComment, mentions)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -316,7 +316,7 @@ func DismissReview(ctx context.Context, reviewID, repoID int64, message string,
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
if err = review.Issue.LoadPullRequest(); err != nil {
|
||||
if err = review.Issue.LoadPullRequest(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
if err = review.Issue.LoadAttributes(ctx); err != nil {
|
||||
@@ -339,7 +339,7 @@ func DismissReview(ctx context.Context, reviewID, repoID int64, message string,
|
||||
comment.Poster = doer
|
||||
comment.Issue = review.Issue
|
||||
|
||||
notification.NotifyPullRevieweDismiss(doer, review, comment)
|
||||
notification.NotifyPullReviewDismiss(ctx, doer, review, comment)
|
||||
|
||||
return comment, err
|
||||
}
|
||||
|
@@ -23,7 +23,7 @@ import (
|
||||
// createTemporaryRepo creates a temporary repo with "base" for pr.BaseBranch and "tracking" for pr.HeadBranch
|
||||
// it also create a second base branch called "original_base"
|
||||
func createTemporaryRepo(ctx context.Context, pr *issues_model.PullRequest) (string, error) {
|
||||
if err := pr.LoadHeadRepoCtx(ctx); err != nil {
|
||||
if err := pr.LoadHeadRepo(ctx); err != nil {
|
||||
log.Error("LoadHeadRepo: %v", err)
|
||||
return "", fmt.Errorf("LoadHeadRepo: %w", err)
|
||||
} else if pr.HeadRepo == nil {
|
||||
@@ -31,7 +31,7 @@ func createTemporaryRepo(ctx context.Context, pr *issues_model.PullRequest) (str
|
||||
return "", &repo_model.ErrRepoNotExist{
|
||||
ID: pr.HeadRepoID,
|
||||
}
|
||||
} else if err := pr.LoadBaseRepoCtx(ctx); err != nil {
|
||||
} else if err := pr.LoadBaseRepo(ctx); err != nil {
|
||||
log.Error("LoadBaseRepo: %v", err)
|
||||
return "", fmt.Errorf("LoadBaseRepo: %w", err)
|
||||
} else if pr.BaseRepo == nil {
|
||||
|
@@ -48,10 +48,10 @@ func Update(ctx context.Context, pull *issues_model.PullRequest, doer *user_mode
|
||||
return fmt.Errorf("Not support update agit flow pull request's head branch")
|
||||
}
|
||||
|
||||
if err := pr.LoadHeadRepoCtx(ctx); err != nil {
|
||||
if err := pr.LoadHeadRepo(ctx); err != nil {
|
||||
log.Error("LoadHeadRepo: %v", err)
|
||||
return fmt.Errorf("LoadHeadRepo: %w", err)
|
||||
} else if err = pr.LoadBaseRepoCtx(ctx); err != nil {
|
||||
} else if err = pr.LoadBaseRepo(ctx); err != nil {
|
||||
log.Error("LoadBaseRepo: %v", err)
|
||||
return fmt.Errorf("LoadBaseRepo: %w", err)
|
||||
}
|
||||
@@ -145,10 +145,10 @@ func IsUserAllowedToUpdate(ctx context.Context, pull *issues_model.PullRequest,
|
||||
// GetDiverging determines how many commits a PR is ahead or behind the PR base branch
|
||||
func GetDiverging(ctx context.Context, pr *issues_model.PullRequest) (*git.DivergeObject, error) {
|
||||
log.Trace("GetDiverging[%d]: compare commits", pr.ID)
|
||||
if err := pr.LoadBaseRepoCtx(ctx); err != nil {
|
||||
if err := pr.LoadBaseRepo(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := pr.LoadHeadRepoCtx(ctx); err != nil {
|
||||
if err := pr.LoadHeadRepo(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
@@ -24,24 +24,24 @@ import (
|
||||
"code.gitea.io/gitea/modules/timeutil"
|
||||
)
|
||||
|
||||
func createTag(gitRepo *git.Repository, rel *repo_model.Release, msg string) (bool, error) {
|
||||
func createTag(ctx context.Context, gitRepo *git.Repository, rel *repo_model.Release, msg string) (bool, error) {
|
||||
var created bool
|
||||
// Only actual create when publish.
|
||||
if !rel.IsDraft {
|
||||
if !gitRepo.IsTagExist(rel.TagName) {
|
||||
if err := rel.LoadAttributes(); err != nil {
|
||||
if err := rel.LoadAttributes(ctx); err != nil {
|
||||
log.Error("LoadAttributes: %v", err)
|
||||
return false, err
|
||||
}
|
||||
|
||||
protectedTags, err := git_model.GetProtectedTags(rel.Repo.ID)
|
||||
protectedTags, err := git_model.GetProtectedTags(ctx, rel.Repo.ID)
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("GetProtectedTags: %w", err)
|
||||
}
|
||||
|
||||
// Trim '--' prefix to prevent command line argument vulnerability.
|
||||
rel.TagName = strings.TrimPrefix(rel.TagName, "--")
|
||||
isAllowed, err := git_model.IsUserAllowedToControlTag(protectedTags, rel.TagName, rel.PublisherID)
|
||||
isAllowed, err := git_model.IsUserAllowedToControlTag(ctx, protectedTags, rel.TagName, rel.PublisherID)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
@@ -81,13 +81,13 @@ func createTag(gitRepo *git.Repository, rel *repo_model.Release, msg string) (bo
|
||||
commits.CompareURL = rel.Repo.ComposeCompareURL(git.EmptySHA, commit.ID.String())
|
||||
|
||||
notification.NotifyPushCommits(
|
||||
rel.Publisher, rel.Repo,
|
||||
ctx, rel.Publisher, rel.Repo,
|
||||
&repository.PushUpdateOptions{
|
||||
RefFullName: git.TagPrefix + rel.TagName,
|
||||
OldCommitID: git.EmptySHA,
|
||||
NewCommitID: commit.ID.String(),
|
||||
}, commits)
|
||||
notification.NotifyCreateRef(rel.Publisher, rel.Repo, "tag", git.TagPrefix+rel.TagName, commit.ID.String())
|
||||
notification.NotifyCreateRef(ctx, rel.Publisher, rel.Repo, "tag", git.TagPrefix+rel.TagName, commit.ID.String())
|
||||
rel.CreatedUnix = timeutil.TimeStampNow()
|
||||
}
|
||||
commit, err := gitRepo.GetTagCommit(rel.TagName)
|
||||
@@ -102,7 +102,7 @@ func createTag(gitRepo *git.Repository, rel *repo_model.Release, msg string) (bo
|
||||
}
|
||||
|
||||
if rel.PublisherID <= 0 {
|
||||
u, err := user_model.GetUserByEmail(commit.Author.Email)
|
||||
u, err := user_model.GetUserByEmailContext(ctx, commit.Author.Email)
|
||||
if err == nil {
|
||||
rel.PublisherID = u.ID
|
||||
}
|
||||
@@ -124,7 +124,7 @@ func CreateRelease(gitRepo *git.Repository, rel *repo_model.Release, attachmentU
|
||||
}
|
||||
}
|
||||
|
||||
if _, err = createTag(gitRepo, rel, msg); err != nil {
|
||||
if _, err = createTag(gitRepo.Ctx, gitRepo, rel, msg); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -138,7 +138,7 @@ func CreateRelease(gitRepo *git.Repository, rel *repo_model.Release, attachmentU
|
||||
}
|
||||
|
||||
if !rel.IsDraft {
|
||||
notification.NotifyNewRelease(rel)
|
||||
notification.NotifyNewRelease(gitRepo.Ctx, rel)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -173,7 +173,7 @@ func CreateNewTag(ctx context.Context, doer *user_model.User, repo *repo_model.R
|
||||
IsTag: true,
|
||||
}
|
||||
|
||||
if _, err = createTag(gitRepo, rel, msg); err != nil {
|
||||
if _, err = createTag(ctx, gitRepo, rel, msg); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -190,7 +190,7 @@ func UpdateRelease(doer *user_model.User, gitRepo *git.Repository, rel *repo_mod
|
||||
if rel.ID == 0 {
|
||||
return errors.New("UpdateRelease only accepts an exist release")
|
||||
}
|
||||
isCreated, err := createTag(gitRepo, rel, "")
|
||||
isCreated, err := createTag(gitRepo.Ctx, gitRepo, rel, "")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -272,12 +272,12 @@ func UpdateRelease(doer *user_model.User, gitRepo *git.Repository, rel *repo_mod
|
||||
}
|
||||
|
||||
if !isCreated {
|
||||
notification.NotifyUpdateRelease(doer, rel)
|
||||
notification.NotifyUpdateRelease(gitRepo.Ctx, doer, rel)
|
||||
return
|
||||
}
|
||||
|
||||
if !rel.IsDraft {
|
||||
notification.NotifyNewRelease(rel)
|
||||
notification.NotifyNewRelease(gitRepo.Ctx, rel)
|
||||
}
|
||||
|
||||
return err
|
||||
@@ -296,11 +296,11 @@ func DeleteReleaseByID(ctx context.Context, id int64, doer *user_model.User, del
|
||||
}
|
||||
|
||||
if delTag {
|
||||
protectedTags, err := git_model.GetProtectedTags(rel.RepoID)
|
||||
protectedTags, err := git_model.GetProtectedTags(ctx, rel.RepoID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("GetProtectedTags: %w", err)
|
||||
}
|
||||
isAllowed, err := git_model.IsUserAllowedToControlTag(protectedTags, rel.TagName, rel.PublisherID)
|
||||
isAllowed, err := git_model.IsUserAllowedToControlTag(ctx, protectedTags, rel.TagName, rel.PublisherID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -318,15 +318,15 @@ func DeleteReleaseByID(ctx context.Context, id int64, doer *user_model.User, del
|
||||
}
|
||||
|
||||
notification.NotifyPushCommits(
|
||||
doer, repo,
|
||||
ctx, doer, repo,
|
||||
&repository.PushUpdateOptions{
|
||||
RefFullName: git.TagPrefix + rel.TagName,
|
||||
OldCommitID: rel.Sha1,
|
||||
NewCommitID: git.EmptySHA,
|
||||
}, repository.NewPushCommits())
|
||||
notification.NotifyDeleteRef(doer, repo, "tag", git.TagPrefix+rel.TagName)
|
||||
notification.NotifyDeleteRef(ctx, doer, repo, "tag", git.TagPrefix+rel.TagName)
|
||||
|
||||
if err := repo_model.DeleteReleaseByID(id); err != nil {
|
||||
if err := repo_model.DeleteReleaseByID(ctx, id); err != nil {
|
||||
return fmt.Errorf("DeleteReleaseByID: %w", err)
|
||||
}
|
||||
} else {
|
||||
@@ -338,11 +338,11 @@ func DeleteReleaseByID(ctx context.Context, id int64, doer *user_model.User, del
|
||||
}
|
||||
|
||||
rel.Repo = repo
|
||||
if err = rel.LoadAttributes(); err != nil {
|
||||
if err = rel.LoadAttributes(ctx); err != nil {
|
||||
return fmt.Errorf("LoadAttributes: %w", err)
|
||||
}
|
||||
|
||||
if err := repo_model.DeleteAttachmentsByRelease(rel.ID); err != nil {
|
||||
if err := repo_model.DeleteAttachmentsByRelease(ctx, rel.ID); err != nil {
|
||||
return fmt.Errorf("DeleteAttachments: %w", err)
|
||||
}
|
||||
|
||||
@@ -353,7 +353,7 @@ func DeleteReleaseByID(ctx context.Context, id int64, doer *user_model.User, del
|
||||
}
|
||||
}
|
||||
|
||||
notification.NotifyDeleteRelease(doer, rel)
|
||||
notification.NotifyDeleteRelease(ctx, doer, rel)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@@ -297,13 +297,13 @@ func TestRelease_createTag(t *testing.T) {
|
||||
IsPrerelease: false,
|
||||
IsTag: false,
|
||||
}
|
||||
_, err = createTag(gitRepo, release, "")
|
||||
_, err = createTag(db.DefaultContext, gitRepo, release, "")
|
||||
assert.NoError(t, err)
|
||||
assert.NotEmpty(t, release.CreatedUnix)
|
||||
releaseCreatedUnix := release.CreatedUnix
|
||||
time.Sleep(2 * time.Second) // sleep 2 seconds to ensure a different timestamp
|
||||
release.Note = "Changed note"
|
||||
_, err = createTag(gitRepo, release, "")
|
||||
_, err = createTag(db.DefaultContext, gitRepo, release, "")
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, int64(releaseCreatedUnix), int64(release.CreatedUnix))
|
||||
|
||||
@@ -321,12 +321,12 @@ func TestRelease_createTag(t *testing.T) {
|
||||
IsPrerelease: false,
|
||||
IsTag: false,
|
||||
}
|
||||
_, err = createTag(gitRepo, release, "")
|
||||
_, err = createTag(db.DefaultContext, gitRepo, release, "")
|
||||
assert.NoError(t, err)
|
||||
releaseCreatedUnix = release.CreatedUnix
|
||||
time.Sleep(2 * time.Second) // sleep 2 seconds to ensure a different timestamp
|
||||
release.Title = "Changed title"
|
||||
_, err = createTag(gitRepo, release, "")
|
||||
_, err = createTag(db.DefaultContext, gitRepo, release, "")
|
||||
assert.NoError(t, err)
|
||||
assert.Less(t, int64(releaseCreatedUnix), int64(release.CreatedUnix))
|
||||
|
||||
@@ -344,13 +344,13 @@ func TestRelease_createTag(t *testing.T) {
|
||||
IsPrerelease: true,
|
||||
IsTag: false,
|
||||
}
|
||||
_, err = createTag(gitRepo, release, "")
|
||||
_, err = createTag(db.DefaultContext, gitRepo, release, "")
|
||||
assert.NoError(t, err)
|
||||
releaseCreatedUnix = release.CreatedUnix
|
||||
time.Sleep(2 * time.Second) // sleep 2 seconds to ensure a different timestamp
|
||||
release.Title = "Changed title"
|
||||
release.Note = "Changed note"
|
||||
_, err = createTag(gitRepo, release, "")
|
||||
_, err = createTag(db.DefaultContext, gitRepo, release, "")
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, int64(releaseCreatedUnix), int64(release.CreatedUnix))
|
||||
}
|
||||
|
@@ -96,7 +96,7 @@ func AdoptRepository(doer, u *user_model.User, opts repo_module.CreateRepoOption
|
||||
return nil, err
|
||||
}
|
||||
|
||||
notification.NotifyCreateRepository(doer, u, repo)
|
||||
notification.NotifyCreateRepository(db.DefaultContext, doer, u, repo)
|
||||
|
||||
return repo, nil
|
||||
}
|
||||
|
@@ -11,6 +11,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
git_model "code.gitea.io/gitea/models/git"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
@@ -141,8 +142,8 @@ func RenameBranch(repo *repo_model.Repository, doer *user_model.User, gitRepo *g
|
||||
return "", err
|
||||
}
|
||||
|
||||
notification.NotifyDeleteRef(doer, repo, "branch", git.BranchPrefix+from)
|
||||
notification.NotifyCreateRef(doer, repo, "branch", git.BranchPrefix+to, refID)
|
||||
notification.NotifyDeleteRef(db.DefaultContext, doer, repo, "branch", git.BranchPrefix+from)
|
||||
notification.NotifyCreateRef(db.DefaultContext, doer, repo, "branch", git.BranchPrefix+to, refID)
|
||||
|
||||
return "", nil
|
||||
}
|
||||
|
@@ -177,7 +177,7 @@ func ForkRepository(ctx context.Context, doer, owner *user_model.User, opts Fork
|
||||
}
|
||||
}
|
||||
|
||||
notification.NotifyForkRepository(doer, opts.BaseRepo, repo)
|
||||
notification.NotifyForkRepository(ctx, doer, opts.BaseRepo, repo)
|
||||
|
||||
return repo, nil
|
||||
}
|
||||
|
@@ -117,7 +117,7 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error {
|
||||
tagName := opts.TagName()
|
||||
if opts.IsDelRef() {
|
||||
notification.NotifyPushCommits(
|
||||
pusher, repo,
|
||||
db.DefaultContext, pusher, repo,
|
||||
&repo_module.PushUpdateOptions{
|
||||
RefFullName: git.TagPrefix + tagName,
|
||||
OldCommitID: opts.OldCommitID,
|
||||
@@ -125,7 +125,7 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error {
|
||||
}, repo_module.NewPushCommits())
|
||||
|
||||
delTags = append(delTags, tagName)
|
||||
notification.NotifyDeleteRef(pusher, repo, "tag", opts.RefFullName)
|
||||
notification.NotifyDeleteRef(db.DefaultContext, pusher, repo, "tag", opts.RefFullName)
|
||||
} else { // is new tag
|
||||
newCommit, err := gitRepo.GetCommit(opts.NewCommitID)
|
||||
if err != nil {
|
||||
@@ -137,7 +137,7 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error {
|
||||
commits.CompareURL = repo.ComposeCompareURL(git.EmptySHA, opts.NewCommitID)
|
||||
|
||||
notification.NotifyPushCommits(
|
||||
pusher, repo,
|
||||
db.DefaultContext, pusher, repo,
|
||||
&repo_module.PushUpdateOptions{
|
||||
RefFullName: git.TagPrefix + tagName,
|
||||
OldCommitID: git.EmptySHA,
|
||||
@@ -145,7 +145,7 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error {
|
||||
}, commits)
|
||||
|
||||
addTags = append(addTags, tagName)
|
||||
notification.NotifyCreateRef(pusher, repo, "tag", opts.RefFullName, opts.NewCommitID)
|
||||
notification.NotifyCreateRef(db.DefaultContext, pusher, repo, "tag", opts.RefFullName, opts.NewCommitID)
|
||||
}
|
||||
} else if opts.IsBranch() { // If is branch reference
|
||||
if pusher == nil || pusher.ID != opts.PusherID {
|
||||
@@ -190,7 +190,7 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error {
|
||||
if err != nil {
|
||||
return fmt.Errorf("newCommit.CommitsBeforeLimit: %w", err)
|
||||
}
|
||||
notification.NotifyCreateRef(pusher, repo, "branch", opts.RefFullName, opts.NewCommitID)
|
||||
notification.NotifyCreateRef(db.DefaultContext, pusher, repo, "branch", opts.RefFullName, opts.NewCommitID)
|
||||
} else {
|
||||
l, err = newCommit.CommitsBeforeUntil(opts.OldCommitID)
|
||||
if err != nil {
|
||||
@@ -250,7 +250,7 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error {
|
||||
commits.Commits = commits.Commits[:setting.UI.FeedMaxCommitNum]
|
||||
}
|
||||
|
||||
notification.NotifyPushCommits(pusher, repo, opts, commits)
|
||||
notification.NotifyPushCommits(db.DefaultContext, pusher, repo, opts, commits)
|
||||
|
||||
if err = git_model.RemoveDeletedBranchByName(repo.ID, branch); err != nil {
|
||||
log.Error("models.RemoveDeletedBranch %s/%s failed: %v", repo.ID, branch, err)
|
||||
@@ -261,7 +261,7 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error {
|
||||
log.Error("repo_module.CacheRef %s/%s failed: %v", repo.ID, branch, err)
|
||||
}
|
||||
} else {
|
||||
notification.NotifyDeleteRef(pusher, repo, "branch", opts.RefFullName)
|
||||
notification.NotifyDeleteRef(db.DefaultContext, pusher, repo, "branch", opts.RefFullName)
|
||||
if err = pull_service.CloseBranchPulls(pusher, repo.ID, branch); err != nil {
|
||||
// close all related pulls
|
||||
log.Error("close related pull request failed: %v", err)
|
||||
|
@@ -32,7 +32,7 @@ func CreateRepository(doer, owner *user_model.User, opts repo_module.CreateRepoO
|
||||
return nil, err
|
||||
}
|
||||
|
||||
notification.NotifyCreateRepository(doer, owner, repo)
|
||||
notification.NotifyCreateRepository(db.DefaultContext, doer, owner, repo)
|
||||
|
||||
return repo, nil
|
||||
}
|
||||
@@ -45,7 +45,7 @@ func DeleteRepository(ctx context.Context, doer *user_model.User, repo *repo_mod
|
||||
|
||||
if notify {
|
||||
// If the repo itself has webhooks, we need to trigger them before deleting it...
|
||||
notification.NotifyDeleteRepository(doer, repo)
|
||||
notification.NotifyDeleteRepository(ctx, doer, repo)
|
||||
}
|
||||
|
||||
if err := models.DeleteRepository(doer, repo.OwnerID, repo.ID); err != nil {
|
||||
|
@@ -101,7 +101,7 @@ func GenerateRepository(doer, owner *user_model.User, templateRepo *repo_model.R
|
||||
return nil, err
|
||||
}
|
||||
|
||||
notification.NotifyCreateRepository(doer, owner, generateRepo)
|
||||
notification.NotifyCreateRepository(db.DefaultContext, doer, owner, generateRepo)
|
||||
|
||||
return generateRepo, nil
|
||||
}
|
||||
|
@@ -55,7 +55,7 @@ func TransferOwnership(doer, newOwner *user_model.User, repo *repo_model.Reposit
|
||||
}
|
||||
}
|
||||
|
||||
notification.NotifyTransferRepository(doer, repo, oldOwner.Name)
|
||||
notification.NotifyTransferRepository(db.DefaultContext, doer, repo, oldOwner.Name)
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -78,7 +78,7 @@ func ChangeRepositoryName(doer *user_model.User, repo *repo_model.Repository, ne
|
||||
repoWorkingPool.CheckOut(fmt.Sprint(repo.ID))
|
||||
|
||||
repo.Name = newRepoName
|
||||
notification.NotifyRenameRepository(doer, repo, oldRepoName)
|
||||
notification.NotifyRenameRepository(db.DefaultContext, doer, repo, oldRepoName)
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -127,7 +127,7 @@ func StartRepositoryTransfer(doer, newOwner *user_model.User, repo *repo_model.R
|
||||
}
|
||||
|
||||
// notify users who are able to accept / reject transfer
|
||||
notification.NotifyRepoPendingTransfer(doer, newOwner, repo)
|
||||
notification.NotifyRepoPendingTransfer(db.DefaultContext, doer, newOwner, repo)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@@ -51,7 +51,7 @@ func runMigrateTask(t *admin_model.Task) (err error) {
|
||||
if err == nil {
|
||||
err = admin_model.FinishMigrateTask(t)
|
||||
if err == nil {
|
||||
notification.NotifyMigrateRepository(t.Doer, t.Owner, t.Repo)
|
||||
notification.NotifyMigrateRepository(db.DefaultContext, t.Doer, t.Owner, t.Repo)
|
||||
return
|
||||
}
|
||||
|
||||
|
@@ -78,7 +78,7 @@ func DeleteUser(ctx context.Context, u *user_model.User, purge bool) error {
|
||||
Actor: u,
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("SearchRepositoryByName: %w", err)
|
||||
return fmt.Errorf("GetUserRepositories: %w", err)
|
||||
}
|
||||
if len(repos) == 0 {
|
||||
break
|
||||
|
@@ -224,7 +224,7 @@ func PrepareWebhooks(ctx context.Context, source EventSource, event webhook_mode
|
||||
}
|
||||
ws = append(ws, repoHooks...)
|
||||
|
||||
owner = source.Repository.MustOwner()
|
||||
owner = source.Repository.MustOwner(ctx)
|
||||
}
|
||||
|
||||
// check if owner is an org and append additional webhooks
|
||||
|
Reference in New Issue
Block a user