1
0
Fork 0

More `db.DefaultContext` refactor (#27265)

Part of #27065

This PR touches functions used in templates. As templates are not static
typed, errors are harder to find, but I hope I catch it all. I think
some tests from other persons do not hurt.
This commit is contained in:
JakobDev 2023-09-29 14:12:54 +02:00 committed by GitHub
parent 3945c26722
commit cf0df023be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
66 changed files with 455 additions and 456 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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