aboutsummaryrefslogtreecommitdiffstats
path: root/services
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
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')
-rw-r--r--services/agit/agit.go10
-rw-r--r--services/asymkey/sign.go2
-rw-r--r--services/automerge/automerge.go8
-rw-r--r--services/comments/comments.go34
-rw-r--r--services/issue/assignee.go10
-rw-r--r--services/issue/content.go3
-rw-r--r--services/issue/issue.go18
-rw-r--r--services/issue/label.go10
-rw-r--r--services/issue/milestone.go2
-rw-r--r--services/issue/status.go2
-rw-r--r--services/lfs/locks.go8
-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
-rw-r--r--services/migrations/gitea_uploader_test.go12
-rw-r--r--services/mirror/mirror_pull.go8
-rw-r--r--services/packages/packages.go6
-rw-r--r--services/pull/check.go14
-rw-r--r--services/pull/commit_status.go4
-rw-r--r--services/pull/edits.go2
-rw-r--r--services/pull/merge.go36
-rw-r--r--services/pull/patch.go2
-rw-r--r--services/pull/pull.go48
-rw-r--r--services/pull/pull_test.go13
-rw-r--r--services/pull/review.go18
-rw-r--r--services/pull/temp_repo.go4
-rw-r--r--services/pull/update.go8
-rw-r--r--services/release/release.go42
-rw-r--r--services/release/release_test.go12
-rw-r--r--services/repository/adopt.go2
-rw-r--r--services/repository/branch.go5
-rw-r--r--services/repository/fork.go2
-rw-r--r--services/repository/push.go14
-rw-r--r--services/repository/repository.go4
-rw-r--r--services/repository/template.go2
-rw-r--r--services/repository/transfer.go6
-rw-r--r--services/task/migrate.go2
-rw-r--r--services/user/user.go2
-rw-r--r--services/webhook/webhook.go2
40 files changed, 206 insertions, 208 deletions
diff --git a/services/agit/agit.go b/services/agit/agit.go
index a7e701d6c4..803ff696b0 100644
--- a/services/agit/agit.go
+++ b/services/agit/agit.go
@@ -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{
diff --git a/services/asymkey/sign.go b/services/asymkey/sign.go
index edfd0f6cad..a9d1e179ae 100644
--- a/services/asymkey/sign.go
+++ b/services/asymkey/sign.go
@@ -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
}
diff --git a/services/automerge/automerge.go b/services/automerge/automerge.go
index 5c38367e3b..3291ed31f0 100644
--- a/services/automerge/automerge.go
+++ b/services/automerge/automerge.go
@@ -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
}
diff --git a/services/comments/comments.go b/services/comments/comments.go
index 7167219c20..190b8a6725 100644
--- a/services/comments/comments.go
+++ b/services/comments/comments.go
@@ -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
}
diff --git a/services/issue/assignee.go b/services/issue/assignee.go
index e24f8500c9..291fc31637 100644
--- a/services/issue/assignee.go
+++ b/services/issue/assignee.go
@@ -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
diff --git a/services/issue/content.go b/services/issue/content.go
index 6f493892f4..851d986de3 100644
--- a/services/issue/content.go
+++ b/services/issue/content.go
@@ -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
}
diff --git a/services/issue/issue.go b/services/issue/issue.go
index 8342d7f5d2..ba9b17a0c8 100644
--- a/services/issue/issue.go
+++ b/services/issue/issue.go
@@ -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
}
diff --git a/services/issue/label.go b/services/issue/label.go
index a9a0c20b01..cd29fcebae 100644
--- a/services/issue/label.go
+++ b/services/issue/label.go
@@ -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
}
diff --git a/services/issue/milestone.go b/services/issue/milestone.go
index 965b07556d..2be4a9e70a 100644
--- a/services/issue/milestone.go
+++ b/services/issue/milestone.go
@@ -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
}
diff --git a/services/issue/status.go b/services/issue/status.go
index 0da5c88762..2d4622324c 100644
--- a/services/issue/status.go
+++ b/services/issue/status.go
@@ -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
}
diff --git a/services/lfs/locks.go b/services/lfs/locks.go
index e87589d124..45ba8faacd 100644
--- a/services/lfs/locks.go
+++ b/services/lfs/locks.go
@@ -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 {
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
}
diff --git a/services/migrations/gitea_uploader_test.go b/services/migrations/gitea_uploader_test.go
index 68a7182b07..362492631f 100644
--- a/services/migrations/gitea_uploader_test.go
+++ b/services/migrations/gitea_uploader_test.go
@@ -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)
}
diff --git a/services/mirror/mirror_pull.go b/services/mirror/mirror_pull.go
index 6002e6b8ed..4a77569d86 100644
--- a/services/mirror/mirror_pull.go
+++ b/services/mirror/mirror_pull.go
@@ -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,
diff --git a/services/packages/packages.go b/services/packages/packages.go
index 4513215ae1..76fdd02bf2 100644
--- a/services/packages/packages.go
+++ b/services/packages/packages.go
@@ -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
}
diff --git a/services/pull/check.go b/services/pull/check.go
index 6e91c22f3e..faf3459f16 100644
--- a/services/pull/check.go
+++ b/services/pull/check.go
@@ -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
diff --git a/services/pull/commit_status.go b/services/pull/commit_status.go
index 5d846129f6..10692221a4 100644
--- a/services/pull/commit_status.go
+++ b/services/pull/commit_status.go
@@ -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")
}
diff --git a/services/pull/edits.go b/services/pull/edits.go
index 2938f2b108..84f7c80da7 100644
--- a/services/pull/edits.go
+++ b/services/pull/edits.go
@@ -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
}
diff --git a/services/pull/merge.go b/services/pull/merge.go
index 6f37a887db..b29c9bc859 100644
--- a/services/pull/merge.go
+++ b/services/pull/merge.go
@@ -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
}
diff --git a/services/pull/patch.go b/services/pull/patch.go
index 9b87ac22e2..1046095ff1 100644
--- a/services/pull/patch.go
+++ b/services/pull/patch.go
@@ -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
}
diff --git a/services/pull/pull.go b/services/pull/pull.go
index 5f8bd6b671..e0dcefe141 100644
--- a/services/pull/pull.go
+++ b/services/pull/pull.go
@@ -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
diff --git a/services/pull/pull_test.go b/services/pull/pull_test.go
index 769e3c72e9..22eefd1624 100644
--- a/services/pull/pull_test.go
+++ b/services/pull/pull_test.go
@@ -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)
diff --git a/services/pull/review.go b/services/pull/review.go
index 16c9e108ee..2555e1b3b3 100644
--- a/services/pull/review.go
+++ b/services/pull/review.go
@@ -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
}
diff --git a/services/pull/temp_repo.go b/services/pull/temp_repo.go
index 15e776c4b9..9c04aa1c92 100644
--- a/services/pull/temp_repo.go
+++ b/services/pull/temp_repo.go
@@ -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 {
diff --git a/services/pull/update.go b/services/pull/update.go
index bd4880a2fc..36e66bb7a9 100644
--- a/services/pull/update.go
+++ b/services/pull/update.go
@@ -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
}
diff --git a/services/release/release.go b/services/release/release.go
index cf398debbb..eb989381f0 100644
--- a/services/release/release.go
+++ b/services/release/release.go
@@ -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
}
diff --git a/services/release/release_test.go b/services/release/release_test.go
index c0cafb5fcc..1ade9bed37 100644
--- a/services/release/release_test.go
+++ b/services/release/release_test.go
@@ -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))
}
diff --git a/services/repository/adopt.go b/services/repository/adopt.go
index 57a21f500c..3895c54c7b 100644
--- a/services/repository/adopt.go
+++ b/services/repository/adopt.go
@@ -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
}
diff --git a/services/repository/branch.go b/services/repository/branch.go
index 1328422582..e1f26b89af 100644
--- a/services/repository/branch.go
+++ b/services/repository/branch.go
@@ -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
}
diff --git a/services/repository/fork.go b/services/repository/fork.go
index e597bfa449..a9a2b33ed8 100644
--- a/services/repository/fork.go
+++ b/services/repository/fork.go
@@ -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
}
diff --git a/services/repository/push.go b/services/repository/push.go
index 6776ff9f74..e2db18e1f7 100644
--- a/services/repository/push.go
+++ b/services/repository/push.go
@@ -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)
diff --git a/services/repository/repository.go b/services/repository/repository.go
index 2f2c27ff20..c369b98aae 100644
--- a/services/repository/repository.go
+++ b/services/repository/repository.go
@@ -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 {
diff --git a/services/repository/template.go b/services/repository/template.go
index bb5e3f4668..625bc305de 100644
--- a/services/repository/template.go
+++ b/services/repository/template.go
@@ -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
}
diff --git a/services/repository/transfer.go b/services/repository/transfer.go
index a0f4a7685c..2778f2e744 100644
--- a/services/repository/transfer.go
+++ b/services/repository/transfer.go
@@ -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
}
diff --git a/services/task/migrate.go b/services/task/migrate.go
index faca6908a2..307c60a09a 100644
--- a/services/task/migrate.go
+++ b/services/task/migrate.go
@@ -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
}
diff --git a/services/user/user.go b/services/user/user.go
index 4186efe682..9976bc7bd3 100644
--- a/services/user/user.go
+++ b/services/user/user.go
@@ -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
diff --git a/services/webhook/webhook.go b/services/webhook/webhook.go
index 342e764f4d..1780022eb4 100644
--- a/services/webhook/webhook.go
+++ b/services/webhook/webhook.go
@@ -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