aboutsummaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
Diffstat (limited to 'models')
-rw-r--r--models/activities/action.go93
-rw-r--r--models/activities/action_test.go8
-rw-r--r--models/activities/notification.go24
-rw-r--r--models/activities/notification_test.go6
-rw-r--r--models/activities/user_heatmap.go2
-rw-r--r--models/git/commit_status.go2
-rw-r--r--models/issues/comment.go102
-rw-r--r--models/issues/comment_code.go4
-rw-r--r--models/issues/comment_test.go2
-rw-r--r--models/issues/issue_test.go2
-rw-r--r--models/issues/issue_update.go34
-rw-r--r--models/issues/issue_xref.go30
-rw-r--r--models/issues/review.go52
-rw-r--r--models/issues/review_test.go2
-rw-r--r--models/project/board.go22
-rw-r--r--models/project/issue.go16
-rw-r--r--models/project/project.go18
-rw-r--r--models/project/project_test.go4
-rw-r--r--models/repo/collaboration.go10
-rw-r--r--models/repo/collaboration_test.go16
-rw-r--r--models/repo/mirror.go12
21 files changed, 230 insertions, 231 deletions
diff --git a/models/activities/action.go b/models/activities/action.go
index 07c8053425..67828f65a1 100644
--- a/models/activities/action.go
+++ b/models/activities/action.go
@@ -208,91 +208,91 @@ func (a *Action) loadRepo(ctx context.Context) {
}
// GetActFullName gets the action's user full name.
-func (a *Action) GetActFullName() string {
- a.LoadActUser(db.DefaultContext)
+func (a *Action) GetActFullName(ctx context.Context) string {
+ a.LoadActUser(ctx)
return a.ActUser.FullName
}
// GetActUserName gets the action's user name.
-func (a *Action) GetActUserName() string {
- a.LoadActUser(db.DefaultContext)
+func (a *Action) GetActUserName(ctx context.Context) string {
+ a.LoadActUser(ctx)
return a.ActUser.Name
}
// ShortActUserName gets the action's user name trimmed to max 20
// chars.
-func (a *Action) ShortActUserName() string {
- return base.EllipsisString(a.GetActUserName(), 20)
+func (a *Action) ShortActUserName(ctx context.Context) string {
+ return base.EllipsisString(a.GetActUserName(ctx), 20)
}
// GetDisplayName gets the action's display name based on DEFAULT_SHOW_FULL_NAME, or falls back to the username if it is blank.
-func (a *Action) GetDisplayName() string {
+func (a *Action) GetDisplayName(ctx context.Context) string {
if setting.UI.DefaultShowFullName {
- trimmedFullName := strings.TrimSpace(a.GetActFullName())
+ trimmedFullName := strings.TrimSpace(a.GetActFullName(ctx))
if len(trimmedFullName) > 0 {
return trimmedFullName
}
}
- return a.ShortActUserName()
+ return a.ShortActUserName(ctx)
}
// GetDisplayNameTitle gets the action's display name used for the title (tooltip) based on DEFAULT_SHOW_FULL_NAME
-func (a *Action) GetDisplayNameTitle() string {
+func (a *Action) GetDisplayNameTitle(ctx context.Context) string {
if setting.UI.DefaultShowFullName {
- return a.ShortActUserName()
+ return a.ShortActUserName(ctx)
}
- return a.GetActFullName()
+ return a.GetActFullName(ctx)
}
// GetRepoUserName returns the name of the action repository owner.
-func (a *Action) GetRepoUserName() string {
- a.loadRepo(db.DefaultContext)
+func (a *Action) GetRepoUserName(ctx context.Context) string {
+ a.loadRepo(ctx)
return a.Repo.OwnerName
}
// ShortRepoUserName returns the name of the action repository owner
// trimmed to max 20 chars.
-func (a *Action) ShortRepoUserName() string {
- return base.EllipsisString(a.GetRepoUserName(), 20)
+func (a *Action) ShortRepoUserName(ctx context.Context) string {
+ return base.EllipsisString(a.GetRepoUserName(ctx), 20)
}
// GetRepoName returns the name of the action repository.
-func (a *Action) GetRepoName() string {
- a.loadRepo(db.DefaultContext)
+func (a *Action) GetRepoName(ctx context.Context) string {
+ a.loadRepo(ctx)
return a.Repo.Name
}
// ShortRepoName returns the name of the action repository
// trimmed to max 33 chars.
-func (a *Action) ShortRepoName() string {
- return base.EllipsisString(a.GetRepoName(), 33)
+func (a *Action) ShortRepoName(ctx context.Context) string {
+ return base.EllipsisString(a.GetRepoName(ctx), 33)
}
// GetRepoPath returns the virtual path to the action repository.
-func (a *Action) GetRepoPath() string {
- return path.Join(a.GetRepoUserName(), a.GetRepoName())
+func (a *Action) GetRepoPath(ctx context.Context) string {
+ return path.Join(a.GetRepoUserName(ctx), a.GetRepoName(ctx))
}
// ShortRepoPath returns the virtual path to the action repository
// trimmed to max 20 + 1 + 33 chars.
-func (a *Action) ShortRepoPath() string {
- return path.Join(a.ShortRepoUserName(), a.ShortRepoName())
+func (a *Action) ShortRepoPath(ctx context.Context) string {
+ return path.Join(a.ShortRepoUserName(ctx), a.ShortRepoName(ctx))
}
// GetRepoLink returns relative link to action repository.
-func (a *Action) GetRepoLink() string {
+func (a *Action) GetRepoLink(ctx context.Context) string {
// path.Join will skip empty strings
- return path.Join(setting.AppSubURL, "/", url.PathEscape(a.GetRepoUserName()), url.PathEscape(a.GetRepoName()))
+ return path.Join(setting.AppSubURL, "/", url.PathEscape(a.GetRepoUserName(ctx)), url.PathEscape(a.GetRepoName(ctx)))
}
// GetRepoAbsoluteLink returns the absolute link to action repository.
-func (a *Action) GetRepoAbsoluteLink() string {
- return setting.AppURL + url.PathEscape(a.GetRepoUserName()) + "/" + url.PathEscape(a.GetRepoName())
+func (a *Action) GetRepoAbsoluteLink(ctx context.Context) string {
+ return setting.AppURL + url.PathEscape(a.GetRepoUserName(ctx)) + "/" + url.PathEscape(a.GetRepoName(ctx))
}
// GetCommentHTMLURL returns link to action comment.
-func (a *Action) GetCommentHTMLURL() string {
- return a.getCommentHTMLURL(db.DefaultContext)
+func (a *Action) GetCommentHTMLURL(ctx context.Context) string {
+ return a.getCommentHTMLURL(ctx)
}
func (a *Action) loadComment(ctx context.Context) (err error) {
@@ -309,7 +309,7 @@ func (a *Action) getCommentHTMLURL(ctx context.Context) string {
}
_ = a.loadComment(ctx)
if a.Comment != nil {
- return a.Comment.HTMLURL()
+ return a.Comment.HTMLURL(ctx)
}
if len(a.GetIssueInfos()) == 0 {
return "#"
@@ -334,8 +334,8 @@ func (a *Action) getCommentHTMLURL(ctx context.Context) string {
}
// GetCommentLink returns link to action comment.
-func (a *Action) GetCommentLink() string {
- return a.getCommentLink(db.DefaultContext)
+func (a *Action) GetCommentLink(ctx context.Context) string {
+ return a.getCommentLink(ctx)
}
func (a *Action) getCommentLink(ctx context.Context) string {
@@ -344,7 +344,7 @@ func (a *Action) getCommentLink(ctx context.Context) string {
}
_ = a.loadComment(ctx)
if a.Comment != nil {
- return a.Comment.Link()
+ return a.Comment.Link(ctx)
}
if len(a.GetIssueInfos()) == 0 {
return "#"
@@ -374,8 +374,8 @@ func (a *Action) GetBranch() string {
}
// GetRefLink returns the action's ref link.
-func (a *Action) GetRefLink() string {
- return git.RefURL(a.GetRepoLink(), a.RefName)
+func (a *Action) GetRefLink(ctx context.Context) string {
+ return git.RefURL(a.GetRepoLink(ctx), a.RefName)
}
// GetTag returns the action's repository tag.
@@ -399,11 +399,10 @@ func (a *Action) GetIssueInfos() []string {
return strings.SplitN(a.Content, "|", 3)
}
-// GetIssueTitle returns the title of first issue associated
-// with the action. This function will be invoked in template so keep db.DefaultContext here
-func (a *Action) GetIssueTitle() string {
+// GetIssueTitle returns the title of first issue associated with the action.
+func (a *Action) GetIssueTitle(ctx context.Context) string {
index, _ := strconv.ParseInt(a.GetIssueInfos()[0], 10, 64)
- issue, err := issues_model.GetIssueByIndex(db.DefaultContext, a.RepoID, index)
+ issue, err := issues_model.GetIssueByIndex(ctx, a.RepoID, index)
if err != nil {
log.Error("GetIssueByIndex: %v", err)
return "500 when get issue"
@@ -442,7 +441,7 @@ func GetFeeds(ctx context.Context, opts GetFeedsOptions) (ActionList, int64, err
return nil, 0, fmt.Errorf("need at least one of these filters: RequestedUser, RequestedTeam, RequestedRepo")
}
- cond, err := activityQueryCondition(opts)
+ cond, err := activityQueryCondition(ctx, opts)
if err != nil {
return nil, 0, err
}
@@ -473,11 +472,11 @@ func ActivityReadable(user, doer *user_model.User) bool {
doer != nil && (doer.IsAdmin || user.ID == doer.ID)
}
-func activityQueryCondition(opts GetFeedsOptions) (builder.Cond, error) {
+func activityQueryCondition(ctx context.Context, opts GetFeedsOptions) (builder.Cond, error) {
cond := builder.NewCond()
if opts.RequestedTeam != nil && opts.RequestedUser == nil {
- org, err := user_model.GetUserByID(db.DefaultContext, opts.RequestedTeam.OrgID)
+ org, err := user_model.GetUserByID(ctx, opts.RequestedTeam.OrgID)
if err != nil {
return nil, err
}
@@ -564,12 +563,12 @@ func activityQueryCondition(opts GetFeedsOptions) (builder.Cond, error) {
}
// DeleteOldActions deletes all old actions from database.
-func DeleteOldActions(olderThan time.Duration) (err error) {
+func DeleteOldActions(ctx context.Context, olderThan time.Duration) (err error) {
if olderThan <= 0 {
return nil
}
- _, err = db.GetEngine(db.DefaultContext).Where("created_unix < ?", time.Now().Add(-olderThan).Unix()).Delete(&Action{})
+ _, err = db.GetEngine(ctx).Where("created_unix < ?", time.Now().Add(-olderThan).Unix()).Delete(&Action{})
return err
}
@@ -679,8 +678,8 @@ func NotifyWatchers(ctx context.Context, actions ...*Action) error {
}
// NotifyWatchersActions creates batch of actions for every watcher.
-func NotifyWatchersActions(acts []*Action) error {
- ctx, committer, err := db.TxContext(db.DefaultContext)
+func NotifyWatchersActions(ctx context.Context, acts []*Action) error {
+ ctx, committer, err := db.TxContext(ctx)
if err != nil {
return err
}
diff --git a/models/activities/action_test.go b/models/activities/action_test.go
index 9a42740880..5467bd35fb 100644
--- a/models/activities/action_test.go
+++ b/models/activities/action_test.go
@@ -24,7 +24,7 @@ func TestAction_GetRepoPath(t *testing.T) {
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
action := &activities_model.Action{RepoID: repo.ID}
- assert.Equal(t, path.Join(owner.Name, repo.Name), action.GetRepoPath())
+ assert.Equal(t, path.Join(owner.Name, repo.Name), action.GetRepoPath(db.DefaultContext))
}
func TestAction_GetRepoLink(t *testing.T) {
@@ -35,9 +35,9 @@ func TestAction_GetRepoLink(t *testing.T) {
action := &activities_model.Action{RepoID: repo.ID, CommentID: comment.ID}
setting.AppSubURL = "/suburl"
expected := path.Join(setting.AppSubURL, owner.Name, repo.Name)
- assert.Equal(t, expected, action.GetRepoLink())
- assert.Equal(t, repo.HTMLURL(), action.GetRepoAbsoluteLink())
- assert.Equal(t, comment.HTMLURL(), action.GetCommentHTMLURL())
+ assert.Equal(t, expected, action.GetRepoLink(db.DefaultContext))
+ assert.Equal(t, repo.HTMLURL(), action.GetRepoAbsoluteLink(db.DefaultContext))
+ assert.Equal(t, comment.HTMLURL(db.DefaultContext), action.GetCommentHTMLURL(db.DefaultContext))
}
func TestGetFeeds(t *testing.T) {
diff --git a/models/activities/notification.go b/models/activities/notification.go
index ef263ef735..7c794564b6 100644
--- a/models/activities/notification.go
+++ b/models/activities/notification.go
@@ -175,8 +175,8 @@ func CreateRepoTransferNotification(ctx context.Context, doer, newOwner *user_mo
// CreateOrUpdateIssueNotifications creates an issue notification
// for each watcher, or updates it if already exists
// receiverID > 0 just send to receiver, else send to all watcher
-func CreateOrUpdateIssueNotifications(issueID, commentID, notificationAuthorID, receiverID int64) error {
- ctx, committer, err := db.TxContext(db.DefaultContext)
+func CreateOrUpdateIssueNotifications(ctx context.Context, issueID, commentID, notificationAuthorID, receiverID int64) error {
+ ctx, committer, err := db.TxContext(ctx)
if err != nil {
return err
}
@@ -435,21 +435,21 @@ func (n *Notification) loadUser(ctx context.Context) (err error) {
}
// GetRepo returns the repo of the notification
-func (n *Notification) GetRepo() (*repo_model.Repository, error) {
- return n.Repository, n.loadRepo(db.DefaultContext)
+func (n *Notification) GetRepo(ctx context.Context) (*repo_model.Repository, error) {
+ return n.Repository, n.loadRepo(ctx)
}
// GetIssue returns the issue of the notification
-func (n *Notification) GetIssue() (*issues_model.Issue, error) {
- return n.Issue, n.loadIssue(db.DefaultContext)
+func (n *Notification) GetIssue(ctx context.Context) (*issues_model.Issue, error) {
+ return n.Issue, n.loadIssue(ctx)
}
// HTMLURL formats a URL-string to the notification
-func (n *Notification) HTMLURL() string {
+func (n *Notification) HTMLURL(ctx context.Context) string {
switch n.Source {
case NotificationSourceIssue, NotificationSourcePullRequest:
if n.Comment != nil {
- return n.Comment.HTMLURL()
+ return n.Comment.HTMLURL(ctx)
}
return n.Issue.HTMLURL()
case NotificationSourceCommit:
@@ -461,11 +461,11 @@ func (n *Notification) HTMLURL() string {
}
// Link formats a relative URL-string to the notification
-func (n *Notification) Link() string {
+func (n *Notification) Link(ctx context.Context) string {
switch n.Source {
case NotificationSourceIssue, NotificationSourcePullRequest:
if n.Comment != nil {
- return n.Comment.Link()
+ return n.Comment.Link(ctx)
}
return n.Issue.Link()
case NotificationSourceCommit:
@@ -733,12 +733,12 @@ type UserIDCount struct {
}
// GetUIDsAndNotificationCounts between the two provided times
-func GetUIDsAndNotificationCounts(since, until timeutil.TimeStamp) ([]UserIDCount, error) {
+func GetUIDsAndNotificationCounts(ctx context.Context, since, until timeutil.TimeStamp) ([]UserIDCount, error) {
sql := `SELECT user_id, count(*) AS count FROM notification ` +
`WHERE user_id IN (SELECT user_id FROM notification WHERE updated_unix >= ? AND ` +
`updated_unix < ?) AND status = ? GROUP BY user_id`
var res []UserIDCount
- return res, db.GetEngine(db.DefaultContext).SQL(sql, since, until, NotificationStatusUnread).Find(&res)
+ return res, db.GetEngine(ctx).SQL(sql, since, until, NotificationStatusUnread).Find(&res)
}
// SetIssueReadBy sets issue to be read by given user.
diff --git a/models/activities/notification_test.go b/models/activities/notification_test.go
index 2d4c369a99..b90ce70536 100644
--- a/models/activities/notification_test.go
+++ b/models/activities/notification_test.go
@@ -20,7 +20,7 @@ func TestCreateOrUpdateIssueNotifications(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 1})
- assert.NoError(t, activities_model.CreateOrUpdateIssueNotifications(issue.ID, 0, 2, 0))
+ assert.NoError(t, activities_model.CreateOrUpdateIssueNotifications(db.DefaultContext, issue.ID, 0, 2, 0))
// User 9 is inactive, thus notifications for user 1 and 4 are created
notf := unittest.AssertExistsAndLoadBean(t, &activities_model.Notification{UserID: 1, IssueID: issue.ID})
@@ -50,7 +50,7 @@ func TestNotificationsForUser(t *testing.T) {
func TestNotification_GetRepo(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
notf := unittest.AssertExistsAndLoadBean(t, &activities_model.Notification{RepoID: 1})
- repo, err := notf.GetRepo()
+ repo, err := notf.GetRepo(db.DefaultContext)
assert.NoError(t, err)
assert.Equal(t, repo, notf.Repository)
assert.EqualValues(t, notf.RepoID, repo.ID)
@@ -59,7 +59,7 @@ func TestNotification_GetRepo(t *testing.T) {
func TestNotification_GetIssue(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
notf := unittest.AssertExistsAndLoadBean(t, &activities_model.Notification{RepoID: 1})
- issue, err := notf.GetIssue()
+ issue, err := notf.GetIssue(db.DefaultContext)
assert.NoError(t, err)
assert.Equal(t, issue, notf.Issue)
assert.EqualValues(t, notf.IssueID, issue.ID)
diff --git a/models/activities/user_heatmap.go b/models/activities/user_heatmap.go
index 9f7b8bbdc4..78fcd76d43 100644
--- a/models/activities/user_heatmap.go
+++ b/models/activities/user_heatmap.go
@@ -47,7 +47,7 @@ func getUserHeatmapData(ctx context.Context, user *user_model.User, team *organi
groupByName = groupBy
}
- cond, err := activityQueryCondition(GetFeedsOptions{
+ cond, err := activityQueryCondition(ctx, GetFeedsOptions{
RequestedUser: user,
RequestedTeam: team,
Actor: doer,
diff --git a/models/git/commit_status.go b/models/git/commit_status.go
index 24fee8c3b4..acb0110200 100644
--- a/models/git/commit_status.go
+++ b/models/git/commit_status.go
@@ -514,7 +514,7 @@ func ConvertFromGitCommit(ctx context.Context, commits []*git.Commit, repo *repo
user_model.ValidateCommitsWithEmails(ctx, commits),
repo.GetTrustModel(),
func(user *user_model.User) (bool, error) {
- return repo_model.IsOwnerMemberCollaborator(repo, user.ID)
+ return repo_model.IsOwnerMemberCollaborator(ctx, repo, user.ID)
},
),
repo,
diff --git a/models/issues/comment.go b/models/issues/comment.go
index 8b1b18051e..6f16a866ff 100644
--- a/models/issues/comment.go
+++ b/models/issues/comment.go
@@ -371,42 +371,42 @@ func (c *Comment) AfterDelete(ctx context.Context) {
}
// HTMLURL formats a URL-string to the issue-comment
-func (c *Comment) HTMLURL() string {
- err := c.LoadIssue(db.DefaultContext)
+func (c *Comment) HTMLURL(ctx context.Context) string {
+ err := c.LoadIssue(ctx)
if err != nil { // Silently dropping errors :unamused:
log.Error("LoadIssue(%d): %v", c.IssueID, err)
return ""
}
- err = c.Issue.LoadRepo(db.DefaultContext)
+ err = c.Issue.LoadRepo(ctx)
if err != nil { // Silently dropping errors :unamused:
log.Error("loadRepo(%d): %v", c.Issue.RepoID, err)
return ""
}
- return c.Issue.HTMLURL() + c.hashLink()
+ return c.Issue.HTMLURL() + c.hashLink(ctx)
}
// Link formats a relative URL-string to the issue-comment
-func (c *Comment) Link() string {
- err := c.LoadIssue(db.DefaultContext)
+func (c *Comment) Link(ctx context.Context) string {
+ err := c.LoadIssue(ctx)
if err != nil { // Silently dropping errors :unamused:
log.Error("LoadIssue(%d): %v", c.IssueID, err)
return ""
}
- err = c.Issue.LoadRepo(db.DefaultContext)
+ err = c.Issue.LoadRepo(ctx)
if err != nil { // Silently dropping errors :unamused:
log.Error("loadRepo(%d): %v", c.Issue.RepoID, err)
return ""
}
- return c.Issue.Link() + c.hashLink()
+ return c.Issue.Link() + c.hashLink(ctx)
}
-func (c *Comment) hashLink() string {
+func (c *Comment) hashLink(ctx context.Context) string {
if c.Type == CommentTypeCode {
if c.ReviewID == 0 {
return "/files#" + c.HashTag()
}
if c.Review == nil {
- if err := c.LoadReview(); err != nil {
+ if err := c.LoadReview(ctx); err != nil {
log.Warn("LoadReview(%d): %v", c.ReviewID, err)
return "/files#" + c.HashTag()
}
@@ -419,13 +419,13 @@ func (c *Comment) hashLink() string {
}
// APIURL formats a API-string to the issue-comment
-func (c *Comment) APIURL() string {
- err := c.LoadIssue(db.DefaultContext)
+func (c *Comment) APIURL(ctx context.Context) string {
+ err := c.LoadIssue(ctx)
if err != nil { // Silently dropping errors :unamused:
log.Error("LoadIssue(%d): %v", c.IssueID, err)
return ""
}
- err = c.Issue.LoadRepo(db.DefaultContext)
+ err = c.Issue.LoadRepo(ctx)
if err != nil { // Silently dropping errors :unamused:
log.Error("loadRepo(%d): %v", c.Issue.RepoID, err)
return ""
@@ -435,8 +435,8 @@ func (c *Comment) APIURL() string {
}
// IssueURL formats a URL-string to the issue
-func (c *Comment) IssueURL() string {
- err := c.LoadIssue(db.DefaultContext)
+func (c *Comment) IssueURL(ctx context.Context) string {
+ err := c.LoadIssue(ctx)
if err != nil { // Silently dropping errors :unamused:
log.Error("LoadIssue(%d): %v", c.IssueID, err)
return ""
@@ -446,7 +446,7 @@ func (c *Comment) IssueURL() string {
return ""
}
- err = c.Issue.LoadRepo(db.DefaultContext)
+ err = c.Issue.LoadRepo(ctx)
if err != nil { // Silently dropping errors :unamused:
log.Error("loadRepo(%d): %v", c.Issue.RepoID, err)
return ""
@@ -455,14 +455,14 @@ func (c *Comment) IssueURL() string {
}
// PRURL formats a URL-string to the pull-request
-func (c *Comment) PRURL() string {
- err := c.LoadIssue(db.DefaultContext)
+func (c *Comment) PRURL(ctx context.Context) string {
+ err := c.LoadIssue(ctx)
if err != nil { // Silently dropping errors :unamused:
log.Error("LoadIssue(%d): %v", c.IssueID, err)
return ""
}
- err = c.Issue.LoadRepo(db.DefaultContext)
+ err = c.Issue.LoadRepo(ctx)
if err != nil { // Silently dropping errors :unamused:
log.Error("loadRepo(%d): %v", c.Issue.RepoID, err)
return ""
@@ -490,9 +490,9 @@ func (c *Comment) EventTag() string {
}
// LoadLabel if comment.Type is CommentTypeLabel, then load Label
-func (c *Comment) LoadLabel() error {
+func (c *Comment) LoadLabel(ctx context.Context) error {
var label Label
- has, err := db.GetEngine(db.DefaultContext).ID(c.LabelID).Get(&label)
+ has, err := db.GetEngine(ctx).ID(c.LabelID).Get(&label)
if err != nil {
return err
} else if has {
@@ -506,10 +506,10 @@ func (c *Comment) LoadLabel() error {
}
// LoadProject if comment.Type is CommentTypeProject, then load project.
-func (c *Comment) LoadProject() error {
+func (c *Comment) LoadProject(ctx context.Context) error {
if c.OldProjectID > 0 {
var oldProject project_model.Project
- has, err := db.GetEngine(db.DefaultContext).ID(c.OldProjectID).Get(&oldProject)
+ has, err := db.GetEngine(ctx).ID(c.OldProjectID).Get(&oldProject)
if err != nil {
return err
} else if has {
@@ -519,7 +519,7 @@ func (c *Comment) LoadProject() error {
if c.ProjectID > 0 {
var project project_model.Project
- has, err := db.GetEngine(db.DefaultContext).ID(c.ProjectID).Get(&project)
+ has, err := db.GetEngine(ctx).ID(c.ProjectID).Get(&project)
if err != nil {
return err
} else if has {
@@ -569,8 +569,8 @@ func (c *Comment) LoadAttachments(ctx context.Context) error {
}
// UpdateAttachments update attachments by UUIDs for the comment
-func (c *Comment) UpdateAttachments(uuids []string) error {
- ctx, committer, err := db.TxContext(db.DefaultContext)
+func (c *Comment) UpdateAttachments(ctx context.Context, uuids []string) error {
+ ctx, committer, err := db.TxContext(ctx)
if err != nil {
return err
}
@@ -591,11 +591,11 @@ func (c *Comment) UpdateAttachments(uuids []string) error {
}
// LoadAssigneeUserAndTeam if comment.Type is CommentTypeAssignees, then load assignees
-func (c *Comment) LoadAssigneeUserAndTeam() error {
+func (c *Comment) LoadAssigneeUserAndTeam(ctx context.Context) error {
var err error
if c.AssigneeID > 0 && c.Assignee == nil {
- c.Assignee, err = user_model.GetUserByID(db.DefaultContext, c.AssigneeID)
+ c.Assignee, err = user_model.GetUserByID(ctx, c.AssigneeID)
if err != nil {
if !user_model.IsErrUserNotExist(err) {
return err
@@ -603,20 +603,20 @@ func (c *Comment) LoadAssigneeUserAndTeam() error {
c.Assignee = user_model.NewGhostUser()
}
} else if c.AssigneeTeamID > 0 && c.AssigneeTeam == nil {
- if err = c.LoadIssue(db.DefaultContext); err != nil {
+ if err = c.LoadIssue(ctx); err != nil {
return err
}
- if err = c.Issue.LoadRepo(db.DefaultContext); err != nil {
+ if err = c.Issue.LoadRepo(ctx); err != nil {
return err
}
- if err = c.Issue.Repo.LoadOwner(db.DefaultContext); err != nil {
+ if err = c.Issue.Repo.LoadOwner(ctx); err != nil {
return err
}
if c.Issue.Repo.Owner.IsOrganization() {
- c.AssigneeTeam, err = organization.GetTeamByID(db.DefaultContext, c.AssigneeTeamID)
+ c.AssigneeTeam, err = organization.GetTeamByID(ctx, c.AssigneeTeamID)
if err != nil && !organization.IsErrTeamNotExist(err) {
return err
}
@@ -626,11 +626,11 @@ func (c *Comment) LoadAssigneeUserAndTeam() error {
}
// LoadResolveDoer if comment.Type is CommentTypeCode and ResolveDoerID not zero, then load resolveDoer
-func (c *Comment) LoadResolveDoer() (err error) {
+func (c *Comment) LoadResolveDoer(ctx context.Context) (err error) {
if c.ResolveDoerID == 0 || c.Type != CommentTypeCode {
return nil
}
- c.ResolveDoer, err = user_model.GetUserByID(db.DefaultContext, c.ResolveDoerID)
+ c.ResolveDoer, err = user_model.GetUserByID(ctx, c.ResolveDoerID)
if err != nil {
if user_model.IsErrUserNotExist(err) {
c.ResolveDoer = user_model.NewGhostUser()
@@ -646,11 +646,11 @@ func (c *Comment) IsResolved() bool {
}
// LoadDepIssueDetails loads Dependent Issue Details
-func (c *Comment) LoadDepIssueDetails() (err error) {
+func (c *Comment) LoadDepIssueDetails(ctx context.Context) (err error) {
if c.DependentIssueID <= 0 || c.DependentIssue != nil {
return nil
}
- c.DependentIssue, err = GetIssueByID(db.DefaultContext, c.DependentIssueID)
+ c.DependentIssue, err = GetIssueByID(ctx, c.DependentIssueID)
return err
}
@@ -683,8 +683,8 @@ func (c *Comment) loadReactions(ctx context.Context, repo *repo_model.Repository
}
// LoadReactions loads comment reactions
-func (c *Comment) LoadReactions(repo *repo_model.Repository) error {
- return c.loadReactions(db.DefaultContext, repo)
+func (c *Comment) LoadReactions(ctx context.Context, repo *repo_model.Repository) error {
+ return c.loadReactions(ctx, repo)
}
func (c *Comment) loadReview(ctx context.Context) (err error) {
@@ -698,8 +698,8 @@ func (c *Comment) loadReview(ctx context.Context) (err error) {
}
// LoadReview loads the associated review
-func (c *Comment) LoadReview() error {
- return c.loadReview(db.DefaultContext)
+func (c *Comment) LoadReview(ctx context.Context) error {
+ return c.loadReview(ctx)
}
// DiffSide returns "previous" if Comment.Line is a LOC of the previous changes and "proposed" if it is a LOC of the proposed changes.
@@ -719,13 +719,13 @@ func (c *Comment) UnsignedLine() uint64 {
}
// CodeCommentLink returns the url to a comment in code
-func (c *Comment) CodeCommentLink() string {
- err := c.LoadIssue(db.DefaultContext)
+func (c *Comment) CodeCommentLink(ctx context.Context) string {
+ err := c.LoadIssue(ctx)
if err != nil { // Silently dropping errors :unamused:
log.Error("LoadIssue(%d): %v", c.IssueID, err)
return ""
}
- err = c.Issue.LoadRepo(db.DefaultContext)
+ err = c.Issue.LoadRepo(ctx)
if err != nil { // Silently dropping errors :unamused:
log.Error("loadRepo(%d): %v", c.Issue.RepoID, err)
return ""
@@ -1074,8 +1074,8 @@ func FindComments(ctx context.Context, opts *FindCommentsOptions) (CommentList,
}
// CountComments count all comments according options by ignoring pagination
-func CountComments(opts *FindCommentsOptions) (int64, error) {
- sess := db.GetEngine(db.DefaultContext).Where(opts.ToConds())
+func CountComments(ctx context.Context, opts *FindCommentsOptions) (int64, error) {
+ sess := db.GetEngine(ctx).Where(opts.ToConds())
if opts.RepoID > 0 {
sess.Join("INNER", "issue", "issue.id = comment.issue_id")
}
@@ -1089,8 +1089,8 @@ func UpdateCommentInvalidate(ctx context.Context, c *Comment) error {
}
// UpdateComment updates information of comment.
-func UpdateComment(c *Comment, doer *user_model.User) error {
- ctx, committer, err := db.TxContext(db.DefaultContext)
+func UpdateComment(ctx context.Context, c *Comment, doer *user_model.User) error {
+ ctx, committer, err := db.TxContext(ctx)
if err != nil {
return err
}
@@ -1147,8 +1147,8 @@ func DeleteComment(ctx context.Context, comment *Comment) error {
}
// UpdateCommentsMigrationsByType updates comments' migrations information via given git service type and original id and poster id
-func UpdateCommentsMigrationsByType(tp structs.GitServiceType, originalAuthorID string, posterID int64) error {
- _, err := db.GetEngine(db.DefaultContext).Table("comment").
+func UpdateCommentsMigrationsByType(ctx context.Context, tp structs.GitServiceType, originalAuthorID string, posterID int64) error {
+ _, err := db.GetEngine(ctx).Table("comment").
Where(builder.In("issue_id",
builder.Select("issue.id").
From("issue").
@@ -1250,7 +1250,7 @@ func (c *Comment) HasOriginalAuthor() bool {
}
// InsertIssueComments inserts many comments of issues.
-func InsertIssueComments(comments []*Comment) error {
+func InsertIssueComments(ctx context.Context, comments []*Comment) error {
if len(comments) == 0 {
return nil
}
@@ -1260,7 +1260,7 @@ func InsertIssueComments(comments []*Comment) error {
issueIDs.Add(comment.IssueID)
}
- ctx, committer, err := db.TxContext(db.DefaultContext)
+ ctx, committer, err := db.TxContext(ctx)
if err != nil {
return err
}
diff --git a/models/issues/comment_code.go b/models/issues/comment_code.go
index d447d7542c..49927fbbe2 100644
--- a/models/issues/comment_code.go
+++ b/models/issues/comment_code.go
@@ -99,11 +99,11 @@ func findCodeComments(ctx context.Context, opts FindCommentsOptions, issue *Issu
comments[n] = comment
n++
- if err := comment.LoadResolveDoer(); err != nil {
+ if err := comment.LoadResolveDoer(ctx); err != nil {
return nil, err
}
- if err := comment.LoadReactions(issue.Repo); err != nil {
+ if err := comment.LoadReactions(ctx, issue.Repo); err != nil {
return nil, err
}
diff --git a/models/issues/comment_test.go b/models/issues/comment_test.go
index 90db476571..c5bbfdedc2 100644
--- a/models/issues/comment_test.go
+++ b/models/issues/comment_test.go
@@ -89,7 +89,7 @@ func TestMigrate_InsertIssueComments(t *testing.T) {
Reactions: []*issues_model.Reaction{reaction},
}
- err := issues_model.InsertIssueComments([]*issues_model.Comment{comment})
+ err := issues_model.InsertIssueComments(db.DefaultContext, []*issues_model.Comment{comment})
assert.NoError(t, err)
issueModified := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 1})
diff --git a/models/issues/issue_test.go b/models/issues/issue_test.go
index 7301995524..5993e918e7 100644
--- a/models/issues/issue_test.go
+++ b/models/issues/issue_test.go
@@ -253,7 +253,7 @@ func testInsertIssue(t *testing.T, title, content string, expectIndex int64) *is
Title: title,
Content: content,
}
- err := issues_model.NewIssue(repo, &issue, nil, nil)
+ err := issues_model.NewIssue(db.DefaultContext, repo, &issue, nil, nil)
assert.NoError(t, err)
has, err := db.GetEngine(db.DefaultContext).ID(issue.ID).Get(&newIssue)
diff --git a/models/issues/issue_update.go b/models/issues/issue_update.go
index 9607b21a67..a8097fa3b4 100644
--- a/models/issues/issue_update.go
+++ b/models/issues/issue_update.go
@@ -165,8 +165,8 @@ func ChangeIssueTitle(ctx context.Context, issue *Issue, doer *user_model.User,
}
// ChangeIssueRef changes the branch of this issue, as the given user.
-func ChangeIssueRef(issue *Issue, doer *user_model.User, oldRef string) (err error) {
- ctx, committer, err := db.TxContext(db.DefaultContext)
+func ChangeIssueRef(ctx context.Context, issue *Issue, doer *user_model.User, oldRef string) (err error) {
+ ctx, committer, err := db.TxContext(ctx)
if err != nil {
return err
}
@@ -215,8 +215,8 @@ func AddDeletePRBranchComment(ctx context.Context, doer *user_model.User, repo *
}
// UpdateIssueAttachments update attachments by UUIDs for the issue
-func UpdateIssueAttachments(issueID int64, uuids []string) (err error) {
- ctx, committer, err := db.TxContext(db.DefaultContext)
+func UpdateIssueAttachments(ctx context.Context, issueID int64, uuids []string) (err error) {
+ ctx, committer, err := db.TxContext(ctx)
if err != nil {
return err
}
@@ -235,8 +235,8 @@ func UpdateIssueAttachments(issueID int64, uuids []string) (err error) {
}
// ChangeIssueContent changes issue content, as the given user.
-func ChangeIssueContent(issue *Issue, doer *user_model.User, content string) (err error) {
- ctx, committer, err := db.TxContext(db.DefaultContext)
+func ChangeIssueContent(ctx context.Context, issue *Issue, doer *user_model.User, content string) (err error) {
+ ctx, committer, err := db.TxContext(ctx)
if err != nil {
return err
}
@@ -381,8 +381,8 @@ func NewIssueWithIndex(ctx context.Context, doer *user_model.User, opts NewIssue
}
// NewIssue creates new issue with labels for repository.
-func NewIssue(repo *repo_model.Repository, issue *Issue, labelIDs []int64, uuids []string) (err error) {
- ctx, committer, err := db.TxContext(db.DefaultContext)
+func NewIssue(ctx context.Context, repo *repo_model.Repository, issue *Issue, labelIDs []int64, uuids []string) (err error) {
+ ctx, committer, err := db.TxContext(ctx)
if err != nil {
return err
}
@@ -432,8 +432,8 @@ func UpdateIssueMentions(ctx context.Context, issueID int64, mentions []*user_mo
// UpdateIssueByAPI updates all allowed fields of given issue.
// If the issue status is changed a statusChangeComment is returned
// similarly if the title is changed the titleChanged bool is set to true
-func UpdateIssueByAPI(issue *Issue, doer *user_model.User) (statusChangeComment *Comment, titleChanged bool, err error) {
- ctx, committer, err := db.TxContext(db.DefaultContext)
+func UpdateIssueByAPI(ctx context.Context, issue *Issue, doer *user_model.User) (statusChangeComment *Comment, titleChanged bool, err error) {
+ ctx, committer, err := db.TxContext(ctx)
if err != nil {
return nil, false, err
}
@@ -486,12 +486,12 @@ func UpdateIssueByAPI(issue *Issue, doer *user_model.User) (statusChangeComment
}
// UpdateIssueDeadline updates an issue deadline and adds comments. Setting a deadline to 0 means deleting it.
-func UpdateIssueDeadline(issue *Issue, deadlineUnix timeutil.TimeStamp, doer *user_model.User) (err error) {
+func UpdateIssueDeadline(ctx context.Context, issue *Issue, deadlineUnix timeutil.TimeStamp, doer *user_model.User) (err error) {
// if the deadline hasn't changed do nothing
if issue.DeadlineUnix == deadlineUnix {
return nil
}
- ctx, committer, err := db.TxContext(db.DefaultContext)
+ ctx, committer, err := db.TxContext(ctx)
if err != nil {
return err
}
@@ -669,8 +669,8 @@ func ResolveIssueMentionsByVisibility(ctx context.Context, issue *Issue, doer *u
}
// UpdateIssuesMigrationsByType updates all migrated repositories' issues from gitServiceType to replace originalAuthorID to posterID
-func UpdateIssuesMigrationsByType(gitServiceType api.GitServiceType, originalAuthorID string, posterID int64) error {
- _, err := db.GetEngine(db.DefaultContext).Table("issue").
+func UpdateIssuesMigrationsByType(ctx context.Context, gitServiceType api.GitServiceType, originalAuthorID string, posterID int64) error {
+ _, err := db.GetEngine(ctx).Table("issue").
Where("repo_id IN (SELECT id FROM repository WHERE original_service_type = ?)", gitServiceType).
And("original_author_id = ?", originalAuthorID).
Update(map[string]any{
@@ -682,8 +682,8 @@ func UpdateIssuesMigrationsByType(gitServiceType api.GitServiceType, originalAut
}
// UpdateReactionsMigrationsByType updates all migrated repositories' reactions from gitServiceType to replace originalAuthorID to posterID
-func UpdateReactionsMigrationsByType(gitServiceType api.GitServiceType, originalAuthorID string, userID int64) error {
- _, err := db.GetEngine(db.DefaultContext).Table("reaction").
+func UpdateReactionsMigrationsByType(ctx context.Context, gitServiceType api.GitServiceType, originalAuthorID string, userID int64) error {
+ _, err := db.GetEngine(ctx).Table("reaction").
Where("original_author_id = ?", originalAuthorID).
And(migratedIssueCond(gitServiceType)).
Update(map[string]any{
@@ -809,7 +809,7 @@ func DeleteOrphanedIssues(ctx context.Context) error {
// Remove issue attachment files.
for i := range attachmentPaths {
- system_model.RemoveAllWithNotice(db.DefaultContext, "Delete issue attachment", attachmentPaths[i])
+ system_model.RemoveAllWithNotice(ctx, "Delete issue attachment", attachmentPaths[i])
}
return nil
}
diff --git a/models/issues/issue_xref.go b/models/issues/issue_xref.go
index a1086f9e81..77ef53a013 100644
--- a/models/issues/issue_xref.go
+++ b/models/issues/issue_xref.go
@@ -252,22 +252,22 @@ func (c *Comment) neuterCrossReferences(ctx context.Context) error {
}
// LoadRefComment loads comment that created this reference from database
-func (c *Comment) LoadRefComment() (err error) {
+func (c *Comment) LoadRefComment(ctx context.Context) (err error) {
if c.RefComment != nil {
return nil
}
- c.RefComment, err = GetCommentByID(db.DefaultContext, c.RefCommentID)
+ c.RefComment, err = GetCommentByID(ctx, c.RefCommentID)
return err
}
// LoadRefIssue loads comment that created this reference from database
-func (c *Comment) LoadRefIssue() (err error) {
+func (c *Comment) LoadRefIssue(ctx context.Context) (err error) {
if c.RefIssue != nil {
return nil
}
- c.RefIssue, err = GetIssueByID(db.DefaultContext, c.RefIssueID)
+ c.RefIssue, err = GetIssueByID(ctx, c.RefIssueID)
if err == nil {
- err = c.RefIssue.LoadRepo(db.DefaultContext)
+ err = c.RefIssue.LoadRepo(ctx)
}
return err
}
@@ -278,21 +278,21 @@ func CommentTypeIsRef(t CommentType) bool {
}
// RefCommentLink returns the relative URL for the comment that created this reference
-func (c *Comment) RefCommentLink() string {
+func (c *Comment) RefCommentLink(ctx context.Context) string {
// Edge case for when the reference is inside the title or the description of the referring issue
if c.RefCommentID == 0 {
- return c.RefIssueLink()
+ return c.RefIssueLink(ctx)
}
- if err := c.LoadRefComment(); err != nil { // Silently dropping errors :unamused:
+ if err := c.LoadRefComment(ctx); err != nil { // Silently dropping errors :unamused:
log.Error("LoadRefComment(%d): %v", c.RefCommentID, err)
return ""
}
- return c.RefComment.Link()
+ return c.RefComment.Link(ctx)
}
// RefIssueLink returns the relative URL of the issue where this reference was created
-func (c *Comment) RefIssueLink() string {
- if err := c.LoadRefIssue(); err != nil { // Silently dropping errors :unamused:
+func (c *Comment) RefIssueLink(ctx context.Context) string {
+ if err := c.LoadRefIssue(ctx); err != nil { // Silently dropping errors :unamused:
log.Error("LoadRefIssue(%d): %v", c.RefCommentID, err)
return ""
}
@@ -300,8 +300,8 @@ func (c *Comment) RefIssueLink() string {
}
// RefIssueTitle returns the title of the issue where this reference was created
-func (c *Comment) RefIssueTitle() string {
- if err := c.LoadRefIssue(); err != nil { // Silently dropping errors :unamused:
+func (c *Comment) RefIssueTitle(ctx context.Context) string {
+ if err := c.LoadRefIssue(ctx); err != nil { // Silently dropping errors :unamused:
log.Error("LoadRefIssue(%d): %v", c.RefCommentID, err)
return ""
}
@@ -309,8 +309,8 @@ func (c *Comment) RefIssueTitle() string {
}
// RefIssueIdent returns the user friendly identity (e.g. "#1234") of the issue where this reference was created
-func (c *Comment) RefIssueIdent() string {
- if err := c.LoadRefIssue(); err != nil { // Silently dropping errors :unamused:
+func (c *Comment) RefIssueIdent(ctx context.Context) string {
+ if err := c.LoadRefIssue(ctx); err != nil { // Silently dropping errors :unamused:
log.Error("LoadRefIssue(%d): %v", c.RefCommentID, err)
return ""
}
diff --git a/models/issues/review.go b/models/issues/review.go
index f7ef16f6c9..8b64ba8048 100644
--- a/models/issues/review.go
+++ b/models/issues/review.go
@@ -329,8 +329,8 @@ func GetCurrentReview(ctx context.Context, reviewer *user_model.User, issue *Iss
}
// ReviewExists returns whether a review exists for a particular line of code in the PR
-func ReviewExists(issue *Issue, treePath string, line int64) (bool, error) {
- return db.GetEngine(db.DefaultContext).Cols("id").Exist(&Comment{IssueID: issue.ID, TreePath: treePath, Line: line, Type: CommentTypeCode})
+func ReviewExists(ctx context.Context, issue *Issue, treePath string, line int64) (bool, error) {
+ return db.GetEngine(ctx).Cols("id").Exist(&Comment{IssueID: issue.ID, TreePath: treePath, Line: line, Type: CommentTypeCode})
}
// ContentEmptyErr represents an content empty error
@@ -347,8 +347,8 @@ func IsContentEmptyErr(err error) bool {
}
// SubmitReview creates a review out of the existing pending review or creates a new one if no pending review exist
-func SubmitReview(doer *user_model.User, issue *Issue, reviewType ReviewType, content, commitID string, stale bool, attachmentUUIDs []string) (*Review, *Comment, error) {
- ctx, committer, err := db.TxContext(db.DefaultContext)
+func SubmitReview(ctx context.Context, doer *user_model.User, issue *Issue, reviewType ReviewType, content, commitID string, stale bool, attachmentUUIDs []string) (*Review, *Comment, error) {
+ ctx, committer, err := db.TxContext(ctx)
if err != nil {
return nil, nil, err
}
@@ -494,15 +494,15 @@ func GetTeamReviewerByIssueIDAndTeamID(ctx context.Context, issueID, teamID int6
}
// MarkReviewsAsStale marks existing reviews as stale
-func MarkReviewsAsStale(issueID int64) (err error) {
- _, err = db.GetEngine(db.DefaultContext).Exec("UPDATE `review` SET stale=? WHERE issue_id=?", true, issueID)
+func MarkReviewsAsStale(ctx context.Context, issueID int64) (err error) {
+ _, err = db.GetEngine(ctx).Exec("UPDATE `review` SET stale=? WHERE issue_id=?", true, issueID)
return err
}
// MarkReviewsAsNotStale marks existing reviews as not stale for a giving commit SHA
-func MarkReviewsAsNotStale(issueID int64, commitID string) (err error) {
- _, err = db.GetEngine(db.DefaultContext).Exec("UPDATE `review` SET stale=? WHERE issue_id=? AND commit_id=?", false, issueID, commitID)
+func MarkReviewsAsNotStale(ctx context.Context, issueID int64, commitID string) (err error) {
+ _, err = db.GetEngine(ctx).Exec("UPDATE `review` SET stale=? WHERE issue_id=? AND commit_id=?", false, issueID, commitID)
return err
}
@@ -525,8 +525,8 @@ func DismissReview(ctx context.Context, review *Review, isDismiss bool) (err err
}
// InsertReviews inserts review and review comments
-func InsertReviews(reviews []*Review) error {
- ctx, committer, err := db.TxContext(db.DefaultContext)
+func InsertReviews(ctx context.Context, reviews []*Review) error {
+ ctx, committer, err := db.TxContext(ctx)
if err != nil {
return err
}
@@ -803,7 +803,7 @@ func RemoveTeamReviewRequest(ctx context.Context, issue *Issue, reviewer *organi
}
// MarkConversation Add or remove Conversation mark for a code comment
-func MarkConversation(comment *Comment, doer *user_model.User, isResolve bool) (err error) {
+func MarkConversation(ctx context.Context, comment *Comment, doer *user_model.User, isResolve bool) (err error) {
if comment.Type != CommentTypeCode {
return nil
}
@@ -813,7 +813,7 @@ func MarkConversation(comment *Comment, doer *user_model.User, isResolve bool) (
return nil
}
- if _, err = db.GetEngine(db.DefaultContext).Exec("UPDATE `comment` SET resolve_doer_id=? WHERE id=?", doer.ID, comment.ID); err != nil {
+ if _, err = db.GetEngine(ctx).Exec("UPDATE `comment` SET resolve_doer_id=? WHERE id=?", doer.ID, comment.ID); err != nil {
return err
}
} else {
@@ -821,7 +821,7 @@ func MarkConversation(comment *Comment, doer *user_model.User, isResolve bool) (
return nil
}
- if _, err = db.GetEngine(db.DefaultContext).Exec("UPDATE `comment` SET resolve_doer_id=? WHERE id=?", 0, comment.ID); err != nil {
+ if _, err = db.GetEngine(ctx).Exec("UPDATE `comment` SET resolve_doer_id=? WHERE id=?", 0, comment.ID); err != nil {
return err
}
}
@@ -831,24 +831,24 @@ func MarkConversation(comment *Comment, doer *user_model.User, isResolve bool) (
// CanMarkConversation Add or remove Conversation mark for a code comment permission check
// the PR writer , offfcial reviewer and poster can do it
-func CanMarkConversation(issue *Issue, doer *user_model.User) (permResult bool, err error) {
+func CanMarkConversation(ctx context.Context, issue *Issue, doer *user_model.User) (permResult bool, err error) {
if doer == nil || issue == nil {
return false, fmt.Errorf("issue or doer is nil")
}
if doer.ID != issue.PosterID {
- if err = issue.LoadRepo(db.DefaultContext); err != nil {
+ if err = issue.LoadRepo(ctx); err != nil {
return false, err
}
- p, err := access_model.GetUserRepoPermission(db.DefaultContext, issue.Repo, doer)
+ p, err := access_model.GetUserRepoPermission(ctx, issue.Repo, doer)
if err != nil {
return false, err
}
permResult = p.CanAccess(perm.AccessModeWrite, unit.TypePullRequests)
if !permResult {
- if permResult, err = IsOfficialReviewer(db.DefaultContext, issue, doer); err != nil {
+ if permResult, err = IsOfficialReviewer(ctx, issue, doer); err != nil {
return false, err
}
}
@@ -862,8 +862,8 @@ func CanMarkConversation(issue *Issue, doer *user_model.User) (permResult bool,
}
// DeleteReview delete a review and it's code comments
-func DeleteReview(r *Review) error {
- ctx, committer, err := db.TxContext(db.DefaultContext)
+func DeleteReview(ctx context.Context, r *Review) error {
+ ctx, committer, err := db.TxContext(ctx)
if err != nil {
return err
}
@@ -912,7 +912,7 @@ func DeleteReview(r *Review) error {
}
// GetCodeCommentsCount return count of CodeComments a Review has
-func (r *Review) GetCodeCommentsCount() int {
+func (r *Review) GetCodeCommentsCount(ctx context.Context) int {
opts := FindCommentsOptions{
Type: CommentTypeCode,
IssueID: r.IssueID,
@@ -923,7 +923,7 @@ func (r *Review) GetCodeCommentsCount() int {
conds = conds.And(builder.Eq{"invalidated": false})
}
- count, err := db.GetEngine(db.DefaultContext).Where(conds).Count(new(Comment))
+ count, err := db.GetEngine(ctx).Where(conds).Count(new(Comment))
if err != nil {
return 0
}
@@ -931,18 +931,18 @@ func (r *Review) GetCodeCommentsCount() int {
}
// HTMLURL formats a URL-string to the related review issue-comment
-func (r *Review) HTMLURL() string {
+func (r *Review) HTMLURL(ctx context.Context) string {
opts := FindCommentsOptions{
Type: CommentTypeReview,
IssueID: r.IssueID,
ReviewID: r.ID,
}
comment := new(Comment)
- has, err := db.GetEngine(db.DefaultContext).Where(opts.ToConds()).Get(comment)
+ has, err := db.GetEngine(ctx).Where(opts.ToConds()).Get(comment)
if err != nil || !has {
return ""
}
- return comment.HTMLURL()
+ return comment.HTMLURL(ctx)
}
// RemapExternalUser ExternalUserRemappable interface
@@ -963,8 +963,8 @@ func (r *Review) GetExternalName() string { return r.OriginalAuthor }
func (r *Review) GetExternalID() int64 { return r.OriginalAuthorID }
// UpdateReviewsMigrationsByType updates reviews' migrations information via given git service type and original id and poster id
-func UpdateReviewsMigrationsByType(tp structs.GitServiceType, originalAuthorID string, posterID int64) error {
- _, err := db.GetEngine(db.DefaultContext).Table("review").
+func UpdateReviewsMigrationsByType(ctx context.Context, tp structs.GitServiceType, originalAuthorID string, posterID int64) error {
+ _, err := db.GetEngine(ctx).Table("review").
Where("original_author_id = ?", originalAuthorID).
And(migratedIssueCond(tp)).
Update(map[string]any{
diff --git a/models/issues/review_test.go b/models/issues/review_test.go
index cd5b221bcd..63e2aef2cc 100644
--- a/models/issues/review_test.go
+++ b/models/issues/review_test.go
@@ -248,7 +248,7 @@ func TestDeleteReview(t *testing.T) {
})
assert.NoError(t, err)
- assert.NoError(t, issues_model.DeleteReview(review2))
+ assert.NoError(t, issues_model.DeleteReview(db.DefaultContext, review2))
_, err = issues_model.GetReviewByID(db.DefaultContext, review2.ID)
assert.Error(t, err)
diff --git a/models/project/board.go b/models/project/board.go
index 2ab1d5c7b5..3e2d8e0472 100644
--- a/models/project/board.go
+++ b/models/project/board.go
@@ -69,8 +69,8 @@ func (Board) TableName() string {
}
// NumIssues return counter of all issues assigned to the board
-func (b *Board) NumIssues() int {
- c, err := db.GetEngine(db.DefaultContext).Table("project_issue").
+func (b *Board) NumIssues(ctx context.Context) int {
+ c, err := db.GetEngine(ctx).Table("project_issue").
Where("project_id=?", b.ProjectID).
And("project_board_id=?", b.ID).
GroupBy("issue_id").
@@ -142,18 +142,18 @@ func createBoardsForProjectsType(ctx context.Context, project *Project) error {
}
// NewBoard adds a new project board to a given project
-func NewBoard(board *Board) error {
+func NewBoard(ctx context.Context, board *Board) error {
if len(board.Color) != 0 && !BoardColorPattern.MatchString(board.Color) {
return fmt.Errorf("bad color code: %s", board.Color)
}
- _, err := db.GetEngine(db.DefaultContext).Insert(board)
+ _, err := db.GetEngine(ctx).Insert(board)
return err
}
// DeleteBoardByID removes all issues references to the project board.
-func DeleteBoardByID(boardID int64) error {
- ctx, committer, err := db.TxContext(db.DefaultContext)
+func DeleteBoardByID(ctx context.Context, boardID int64) error {
+ ctx, committer, err := db.TxContext(ctx)
if err != nil {
return err
}
@@ -265,8 +265,8 @@ func (p *Project) getDefaultBoard(ctx context.Context) (*Board, error) {
// SetDefaultBoard represents a board for issues not assigned to one
// if boardID is 0 unset default
-func SetDefaultBoard(projectID, boardID int64) error {
- _, err := db.GetEngine(db.DefaultContext).Where(builder.Eq{
+func SetDefaultBoard(ctx context.Context, projectID, boardID int64) error {
+ _, err := db.GetEngine(ctx).Where(builder.Eq{
"project_id": projectID,
"`default`": true,
}).Cols("`default`").Update(&Board{Default: false})
@@ -275,7 +275,7 @@ func SetDefaultBoard(projectID, boardID int64) error {
}
if boardID > 0 {
- _, err = db.GetEngine(db.DefaultContext).ID(boardID).Where(builder.Eq{"project_id": projectID}).
+ _, err = db.GetEngine(ctx).ID(boardID).Where(builder.Eq{"project_id": projectID}).
Cols("`default`").Update(&Board{Default: true})
}
@@ -283,9 +283,9 @@ func SetDefaultBoard(projectID, boardID int64) error {
}
// UpdateBoardSorting update project board sorting
-func UpdateBoardSorting(bs BoardList) error {
+func UpdateBoardSorting(ctx context.Context, bs BoardList) error {
for i := range bs {
- _, err := db.GetEngine(db.DefaultContext).ID(bs[i].ID).Cols(
+ _, err := db.GetEngine(ctx).ID(bs[i].ID).Cols(
"sorting",
).Update(bs[i])
if err != nil {
diff --git a/models/project/issue.go b/models/project/issue.go
index 3269197d6c..ebc9719de5 100644
--- a/models/project/issue.go
+++ b/models/project/issue.go
@@ -34,8 +34,8 @@ func deleteProjectIssuesByProjectID(ctx context.Context, projectID int64) error
}
// NumIssues return counter of all issues assigned to a project
-func (p *Project) NumIssues() int {
- c, err := db.GetEngine(db.DefaultContext).Table("project_issue").
+func (p *Project) NumIssues(ctx context.Context) int {
+ c, err := db.GetEngine(ctx).Table("project_issue").
Where("project_id=?", p.ID).
GroupBy("issue_id").
Cols("issue_id").
@@ -48,8 +48,8 @@ func (p *Project) NumIssues() int {
}
// NumClosedIssues return counter of closed issues assigned to a project
-func (p *Project) NumClosedIssues() int {
- c, err := db.GetEngine(db.DefaultContext).Table("project_issue").
+func (p *Project) NumClosedIssues(ctx context.Context) int {
+ c, err := db.GetEngine(ctx).Table("project_issue").
Join("INNER", "issue", "project_issue.issue_id=issue.id").
Where("project_issue.project_id=? AND issue.is_closed=?", p.ID, true).
Cols("issue_id").
@@ -62,8 +62,8 @@ func (p *Project) NumClosedIssues() int {
}
// NumOpenIssues return counter of open issues assigned to a project
-func (p *Project) NumOpenIssues() int {
- c, err := db.GetEngine(db.DefaultContext).Table("project_issue").
+func (p *Project) NumOpenIssues(ctx context.Context) int {
+ c, err := db.GetEngine(ctx).Table("project_issue").
Join("INNER", "issue", "project_issue.issue_id=issue.id").
Where("project_issue.project_id=? AND issue.is_closed=?", p.ID, false).
Cols("issue_id").
@@ -76,8 +76,8 @@ func (p *Project) NumOpenIssues() int {
}
// MoveIssuesOnProjectBoard moves or keeps issues in a column and sorts them inside that column
-func MoveIssuesOnProjectBoard(board *Board, sortedIssueIDs map[int64]int64) error {
- return db.WithTx(db.DefaultContext, func(ctx context.Context) error {
+func MoveIssuesOnProjectBoard(ctx context.Context, board *Board, sortedIssueIDs map[int64]int64) error {
+ return db.WithTx(ctx, func(ctx context.Context) error {
sess := db.GetEngine(ctx)
issueIDs := make([]int64, 0, len(sortedIssueIDs))
diff --git a/models/project/project.go b/models/project/project.go
index 8056aba252..3a1bfe1dbd 100644
--- a/models/project/project.go
+++ b/models/project/project.go
@@ -124,9 +124,9 @@ func (p *Project) LoadRepo(ctx context.Context) (err error) {
}
// Link returns the project's relative URL.
-func (p *Project) Link() string {
+func (p *Project) Link(ctx context.Context) string {
if p.OwnerID > 0 {
- err := p.LoadOwner(db.DefaultContext)
+ err := p.LoadOwner(ctx)
if err != nil {
log.Error("LoadOwner: %v", err)
return ""
@@ -134,7 +134,7 @@ func (p *Project) Link() string {
return fmt.Sprintf("%s/-/projects/%d", p.Owner.HomeLink(), p.ID)
}
if p.RepoID > 0 {
- err := p.LoadRepo(db.DefaultContext)
+ err := p.LoadRepo(ctx)
if err != nil {
log.Error("LoadRepo: %v", err)
return ""
@@ -261,7 +261,7 @@ func FindProjects(ctx context.Context, opts SearchOptions) ([]*Project, int64, e
}
// NewProject creates a new Project
-func NewProject(p *Project) error {
+func NewProject(ctx context.Context, p *Project) error {
if !IsBoardTypeValid(p.BoardType) {
p.BoardType = BoardTypeNone
}
@@ -274,7 +274,7 @@ func NewProject(p *Project) error {
return util.NewInvalidArgumentErrorf("project type is not valid")
}
- ctx, committer, err := db.TxContext(db.DefaultContext)
+ ctx, committer, err := db.TxContext(ctx)
if err != nil {
return err
}
@@ -348,8 +348,8 @@ func updateRepositoryProjectCount(ctx context.Context, repoID int64) error {
}
// ChangeProjectStatusByRepoIDAndID toggles a project between opened and closed
-func ChangeProjectStatusByRepoIDAndID(repoID, projectID int64, isClosed bool) error {
- ctx, committer, err := db.TxContext(db.DefaultContext)
+func ChangeProjectStatusByRepoIDAndID(ctx context.Context, repoID, projectID int64, isClosed bool) error {
+ ctx, committer, err := db.TxContext(ctx)
if err != nil {
return err
}
@@ -372,8 +372,8 @@ func ChangeProjectStatusByRepoIDAndID(repoID, projectID int64, isClosed bool) er
}
// ChangeProjectStatus toggle a project between opened and closed
-func ChangeProjectStatus(p *Project, isClosed bool) error {
- ctx, committer, err := db.TxContext(db.DefaultContext)
+func ChangeProjectStatus(ctx context.Context, p *Project, isClosed bool) error {
+ ctx, committer, err := db.TxContext(ctx)
if err != nil {
return err
}
diff --git a/models/project/project_test.go b/models/project/project_test.go
index d1a4715653..6b5bd5b371 100644
--- a/models/project/project_test.go
+++ b/models/project/project_test.go
@@ -60,7 +60,7 @@ func TestProject(t *testing.T) {
CreatorID: 2,
}
- assert.NoError(t, NewProject(project))
+ assert.NoError(t, NewProject(db.DefaultContext, project))
_, err := GetProjectByID(db.DefaultContext, project.ID)
assert.NoError(t, err)
@@ -74,7 +74,7 @@ func TestProject(t *testing.T) {
assert.Equal(t, project.Title, projectFromDB.Title)
- assert.NoError(t, ChangeProjectStatus(project, true))
+ assert.NoError(t, ChangeProjectStatus(db.DefaultContext, project, true))
// Retrieve from DB afresh to check if it is truly closed
projectFromDB, err = GetProjectByID(db.DefaultContext, project.ID)
diff --git a/models/repo/collaboration.go b/models/repo/collaboration.go
index 7989e5bdf9..2018ae2a7d 100644
--- a/models/repo/collaboration.go
+++ b/models/repo/collaboration.go
@@ -62,8 +62,8 @@ func GetCollaborators(ctx context.Context, repoID int64, listOptions db.ListOpti
}
// CountCollaborators returns total number of collaborators for a repository
-func CountCollaborators(repoID int64) (int64, error) {
- return db.GetEngine(db.DefaultContext).Where("repo_id = ? ", repoID).Count(&Collaboration{})
+func CountCollaborators(ctx context.Context, repoID int64) (int64, error) {
+ return db.GetEngine(ctx).Where("repo_id = ? ", repoID).Count(&Collaboration{})
}
// GetCollaboration get collaboration for a repository id with a user id
@@ -138,11 +138,11 @@ func ChangeCollaborationAccessMode(ctx context.Context, repo *Repository, uid in
}
// IsOwnerMemberCollaborator checks if a provided user is the owner, a collaborator or a member of a team in a repository
-func IsOwnerMemberCollaborator(repo *Repository, userID int64) (bool, error) {
+func IsOwnerMemberCollaborator(ctx context.Context, repo *Repository, userID int64) (bool, error) {
if repo.OwnerID == userID {
return true, nil
}
- teamMember, err := db.GetEngine(db.DefaultContext).Join("INNER", "team_repo", "team_repo.team_id = team_user.team_id").
+ teamMember, err := db.GetEngine(ctx).Join("INNER", "team_repo", "team_repo.team_id = team_user.team_id").
Join("INNER", "team_unit", "team_unit.team_id = team_user.team_id").
Where("team_repo.repo_id = ?", repo.ID).
And("team_unit.`type` = ?", unit.TypeCode).
@@ -154,5 +154,5 @@ func IsOwnerMemberCollaborator(repo *Repository, userID int64) (bool, error) {
return true, nil
}
- return db.GetEngine(db.DefaultContext).Get(&Collaboration{RepoID: repo.ID, UserID: userID})
+ return db.GetEngine(ctx).Get(&Collaboration{RepoID: repo.ID, UserID: userID})
}
diff --git a/models/repo/collaboration_test.go b/models/repo/collaboration_test.go
index a29dfe99a5..38114c307f 100644
--- a/models/repo/collaboration_test.go
+++ b/models/repo/collaboration_test.go
@@ -89,17 +89,17 @@ func TestRepository_CountCollaborators(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 4})
- count, err := repo_model.CountCollaborators(repo1.ID)
+ count, err := repo_model.CountCollaborators(db.DefaultContext, repo1.ID)
assert.NoError(t, err)
assert.EqualValues(t, 2, count)
repo2 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 22})
- count, err = repo_model.CountCollaborators(repo2.ID)
+ count, err = repo_model.CountCollaborators(db.DefaultContext, repo2.ID)
assert.NoError(t, err)
assert.EqualValues(t, 2, count)
// Non-existent repository.
- count, err = repo_model.CountCollaborators(unittest.NonexistentID)
+ count, err = repo_model.CountCollaborators(db.DefaultContext, unittest.NonexistentID)
assert.NoError(t, err)
assert.EqualValues(t, 0, count)
}
@@ -110,31 +110,31 @@ func TestRepository_IsOwnerMemberCollaborator(t *testing.T) {
repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 3})
// Organisation owner.
- actual, err := repo_model.IsOwnerMemberCollaborator(repo1, 2)
+ actual, err := repo_model.IsOwnerMemberCollaborator(db.DefaultContext, repo1, 2)
assert.NoError(t, err)
assert.True(t, actual)
// Team member.
- actual, err = repo_model.IsOwnerMemberCollaborator(repo1, 4)
+ actual, err = repo_model.IsOwnerMemberCollaborator(db.DefaultContext, repo1, 4)
assert.NoError(t, err)
assert.True(t, actual)
// Normal user.
- actual, err = repo_model.IsOwnerMemberCollaborator(repo1, 1)
+ actual, err = repo_model.IsOwnerMemberCollaborator(db.DefaultContext, repo1, 1)
assert.NoError(t, err)
assert.False(t, actual)
repo2 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 4})
// Collaborator.
- actual, err = repo_model.IsOwnerMemberCollaborator(repo2, 4)
+ actual, err = repo_model.IsOwnerMemberCollaborator(db.DefaultContext, repo2, 4)
assert.NoError(t, err)
assert.True(t, actual)
repo3 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 15})
// Repository owner.
- actual, err = repo_model.IsOwnerMemberCollaborator(repo3, 2)
+ actual, err = repo_model.IsOwnerMemberCollaborator(db.DefaultContext, repo3, 2)
assert.NoError(t, err)
assert.True(t, actual)
}
diff --git a/models/repo/mirror.go b/models/repo/mirror.go
index fffc7577c7..be7b785612 100644
--- a/models/repo/mirror.go
+++ b/models/repo/mirror.go
@@ -47,12 +47,12 @@ func (m *Mirror) BeforeInsert() {
}
// GetRepository returns the repository.
-func (m *Mirror) GetRepository() *Repository {
+func (m *Mirror) GetRepository(ctx context.Context) *Repository {
if m.Repo != nil {
return m.Repo
}
var err error
- m.Repo, err = GetRepositoryByID(db.DefaultContext, m.RepoID)
+ m.Repo, err = GetRepositoryByID(ctx, m.RepoID)
if err != nil {
log.Error("getRepositoryByID[%d]: %v", m.ID, err)
}
@@ -99,14 +99,14 @@ func TouchMirror(ctx context.Context, m *Mirror) error {
}
// DeleteMirrorByRepoID deletes a mirror by repoID
-func DeleteMirrorByRepoID(repoID int64) error {
- _, err := db.GetEngine(db.DefaultContext).Delete(&Mirror{RepoID: repoID})
+func DeleteMirrorByRepoID(ctx context.Context, repoID int64) error {
+ _, err := db.GetEngine(ctx).Delete(&Mirror{RepoID: repoID})
return err
}
// MirrorsIterate iterates all mirror repositories.
-func MirrorsIterate(limit int, f func(idx int, bean any) error) error {
- sess := db.GetEngine(db.DefaultContext).
+func MirrorsIterate(ctx context.Context, limit int, f func(idx int, bean any) error) error {
+ sess := db.GetEngine(ctx).
Where("next_update_unix<=?", time.Now().Unix()).
And("next_update_unix!=0").
OrderBy("updated_unix ASC")