summaryrefslogtreecommitdiffstats
path: root/models/issues
diff options
context:
space:
mode:
authorwxiaoguang <wxiaoguang@gmail.com>2023-04-15 02:18:28 +0800
committerGitHub <noreply@github.com>2023-04-14 14:18:28 -0400
commitcfe3d6e9b507a9331328e55ff98a1f582abae185 (patch)
tree94b035bd2859291a16edda27822b570bdd611a35 /models/issues
parentb667634b32e240f3f3260ab7e304f72f4ff75659 (diff)
downloadgitea-cfe3d6e9b507a9331328e55ff98a1f582abae185.tar.gz
gitea-cfe3d6e9b507a9331328e55ff98a1f582abae185.zip
Make more functions use ctx instead of db.DefaultContext (#24068)
Continue the "ctx refactoring" work. There are still a lot db.DefaultContext, incorrect context could cause database deadlock errors.
Diffstat (limited to 'models/issues')
-rw-r--r--models/issues/assignees.go4
-rw-r--r--models/issues/assignees_test.go6
-rw-r--r--models/issues/issue.go4
-rw-r--r--models/issues/issue_xref_test.go2
4 files changed, 8 insertions, 8 deletions
diff --git a/models/issues/assignees.go b/models/issues/assignees.go
index 16f675a83f..fdd0d6f227 100644
--- a/models/issues/assignees.go
+++ b/models/issues/assignees.go
@@ -63,8 +63,8 @@ func IsUserAssignedToIssue(ctx context.Context, issue *Issue, user *user_model.U
}
// ToggleIssueAssignee changes a user between assigned and not assigned for this issue, and make issue comment for it.
-func ToggleIssueAssignee(issue *Issue, doer *user_model.User, assigneeID int64) (removed bool, comment *Comment, err error) {
- ctx, committer, err := db.TxContext(db.DefaultContext)
+func ToggleIssueAssignee(ctx context.Context, issue *Issue, doer *user_model.User, assigneeID int64) (removed bool, comment *Comment, err error) {
+ ctx, committer, err := db.TxContext(ctx)
if err != nil {
return false, nil, err
}
diff --git a/models/issues/assignees_test.go b/models/issues/assignees_test.go
index 8a2cef8acd..2185f6fc42 100644
--- a/models/issues/assignees_test.go
+++ b/models/issues/assignees_test.go
@@ -24,17 +24,17 @@ func TestUpdateAssignee(t *testing.T) {
// Assign multiple users
user2, err := user_model.GetUserByID(db.DefaultContext, 2)
assert.NoError(t, err)
- _, _, err = issues_model.ToggleIssueAssignee(issue, &user_model.User{ID: 1}, user2.ID)
+ _, _, err = issues_model.ToggleIssueAssignee(db.DefaultContext, issue, &user_model.User{ID: 1}, user2.ID)
assert.NoError(t, err)
user3, err := user_model.GetUserByID(db.DefaultContext, 3)
assert.NoError(t, err)
- _, _, err = issues_model.ToggleIssueAssignee(issue, &user_model.User{ID: 1}, user3.ID)
+ _, _, err = issues_model.ToggleIssueAssignee(db.DefaultContext, issue, &user_model.User{ID: 1}, user3.ID)
assert.NoError(t, err)
user1, err := user_model.GetUserByID(db.DefaultContext, 1) // This user is already assigned (see the definition in fixtures), so running UpdateAssignee should unassign him
assert.NoError(t, err)
- _, _, err = issues_model.ToggleIssueAssignee(issue, &user_model.User{ID: 1}, user1.ID)
+ _, _, err = issues_model.ToggleIssueAssignee(db.DefaultContext, issue, &user_model.User{ID: 1}, user1.ID)
assert.NoError(t, err)
// Check if he got removed
diff --git a/models/issues/issue.go b/models/issues/issue.go
index 64b0edd3e7..5836030476 100644
--- a/models/issues/issue.go
+++ b/models/issues/issue.go
@@ -743,8 +743,8 @@ func ChangeIssueStatus(ctx context.Context, issue *Issue, doer *user_model.User,
}
// ChangeIssueTitle changes the title of this issue, as the given user.
-func ChangeIssueTitle(issue *Issue, doer *user_model.User, oldTitle string) (err error) {
- ctx, committer, err := db.TxContext(db.DefaultContext)
+func ChangeIssueTitle(ctx context.Context, issue *Issue, doer *user_model.User, oldTitle string) (err error) {
+ ctx, committer, err := db.TxContext(ctx)
if err != nil {
return err
}
diff --git a/models/issues/issue_xref_test.go b/models/issues/issue_xref_test.go
index 6d96c398d0..6e94c26272 100644
--- a/models/issues/issue_xref_test.go
+++ b/models/issues/issue_xref_test.go
@@ -83,7 +83,7 @@ func TestXRef_NeuterCrossReferences(t *testing.T) {
d := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
i.Title = "title2, no mentions"
- assert.NoError(t, issues_model.ChangeIssueTitle(i, d, title))
+ assert.NoError(t, issues_model.ChangeIssueTitle(db.DefaultContext, i, d, title))
ref = unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{IssueID: itarget.ID, RefIssueID: i.ID, RefCommentID: 0})
assert.Equal(t, issues_model.CommentTypeIssueRef, ref.Type)