1
1
mirror of https://github.com/go-gitea/gitea synced 2025-08-29 12:58:29 +00:00

Remove incorrect "db.DefaultContext" usages (#35366)

This commit is contained in:
wxiaoguang
2025-08-28 11:52:43 +08:00
committed by GitHub
parent 7aef7ea2d4
commit 0cbaa0b662
256 changed files with 1951 additions and 2098 deletions

View File

@@ -6,7 +6,6 @@ package issue
import (
"testing"
"code.gitea.io/gitea/models/db"
issues_model "code.gitea.io/gitea/models/issues"
"code.gitea.io/gitea/models/unittest"
user_model "code.gitea.io/gitea/models/user"
@@ -18,30 +17,30 @@ func TestDeleteNotPassedAssignee(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
// Fake issue with assignees
issue, err := issues_model.GetIssueByID(db.DefaultContext, 1)
issue, err := issues_model.GetIssueByID(t.Context(), 1)
assert.NoError(t, err)
err = issue.LoadAttributes(db.DefaultContext)
err = issue.LoadAttributes(t.Context())
assert.NoError(t, err)
assert.Len(t, issue.Assignees, 1)
user1, err := user_model.GetUserByID(db.DefaultContext, 1) // This user is already assigned (see the definition in fixtures), so running UpdateAssignee should unassign him
user1, err := user_model.GetUserByID(t.Context(), 1) // This user is already assigned (see the definition in fixtures), so running UpdateAssignee should unassign him
assert.NoError(t, err)
// Check if he got removed
isAssigned, err := issues_model.IsUserAssignedToIssue(db.DefaultContext, issue, user1)
isAssigned, err := issues_model.IsUserAssignedToIssue(t.Context(), issue, user1)
assert.NoError(t, err)
assert.True(t, isAssigned)
// Clean everyone
err = DeleteNotPassedAssignee(db.DefaultContext, issue, user1, []*user_model.User{})
err = DeleteNotPassedAssignee(t.Context(), issue, user1, []*user_model.User{})
assert.NoError(t, err)
assert.Empty(t, issue.Assignees)
// Reload to check they're gone
issue.ResetAttributesLoaded()
assert.NoError(t, issue.LoadAssignees(db.DefaultContext))
assert.NoError(t, issue.LoadAssignees(t.Context()))
assert.Empty(t, issue.Assignees)
assert.Empty(t, issue.Assignee)
}

View File

@@ -7,7 +7,6 @@ import (
"testing"
activities_model "code.gitea.io/gitea/models/activities"
"code.gitea.io/gitea/models/db"
issues_model "code.gitea.io/gitea/models/issues"
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/unittest"
@@ -61,7 +60,7 @@ func TestUpdateIssuesCommit(t *testing.T) {
unittest.AssertNotExistsBean(t, commentBean)
unittest.AssertNotExistsBean(t, &issues_model.Issue{RepoID: repo.ID, Index: 2}, "is_closed=1")
assert.NoError(t, UpdateIssuesCommit(db.DefaultContext, user, repo, pushCommits, repo.DefaultBranch))
assert.NoError(t, UpdateIssuesCommit(t.Context(), user, repo, pushCommits, repo.DefaultBranch))
unittest.AssertExistsAndLoadBean(t, commentBean)
unittest.AssertExistsAndLoadBean(t, issueBean, "is_closed=1")
unittest.CheckConsistencyFor(t, &activities_model.Action{})
@@ -88,7 +87,7 @@ func TestUpdateIssuesCommit(t *testing.T) {
unittest.AssertNotExistsBean(t, commentBean)
unittest.AssertNotExistsBean(t, &issues_model.Issue{RepoID: repo.ID, Index: 1}, "is_closed=1")
assert.NoError(t, UpdateIssuesCommit(db.DefaultContext, user, repo, pushCommits, "non-existing-branch"))
assert.NoError(t, UpdateIssuesCommit(t.Context(), user, repo, pushCommits, "non-existing-branch"))
unittest.AssertExistsAndLoadBean(t, commentBean)
unittest.AssertNotExistsBean(t, issueBean, "is_closed=1")
unittest.CheckConsistencyFor(t, &activities_model.Action{})
@@ -114,7 +113,7 @@ func TestUpdateIssuesCommit(t *testing.T) {
unittest.AssertNotExistsBean(t, commentBean)
unittest.AssertNotExistsBean(t, &issues_model.Issue{RepoID: repo.ID, Index: 1}, "is_closed=1")
assert.NoError(t, UpdateIssuesCommit(db.DefaultContext, user, repo, pushCommits, repo.DefaultBranch))
assert.NoError(t, UpdateIssuesCommit(t.Context(), user, repo, pushCommits, repo.DefaultBranch))
unittest.AssertExistsAndLoadBean(t, commentBean)
unittest.AssertExistsAndLoadBean(t, issueBean, "is_closed=1")
unittest.CheckConsistencyFor(t, &activities_model.Action{})
@@ -140,7 +139,7 @@ func TestUpdateIssuesCommit_Colon(t *testing.T) {
issueBean := &issues_model.Issue{RepoID: repo.ID, Index: 4}
unittest.AssertNotExistsBean(t, &issues_model.Issue{RepoID: repo.ID, Index: 2}, "is_closed=1")
assert.NoError(t, UpdateIssuesCommit(db.DefaultContext, user, repo, pushCommits, repo.DefaultBranch))
assert.NoError(t, UpdateIssuesCommit(t.Context(), user, repo, pushCommits, repo.DefaultBranch))
unittest.AssertExistsAndLoadBean(t, issueBean, "is_closed=1")
unittest.CheckConsistencyFor(t, &activities_model.Action{})
}
@@ -173,7 +172,7 @@ func TestUpdateIssuesCommit_Issue5957(t *testing.T) {
unittest.AssertNotExistsBean(t, commentBean)
unittest.AssertNotExistsBean(t, issueBean, "is_closed=1")
assert.NoError(t, UpdateIssuesCommit(db.DefaultContext, user, repo, pushCommits, "non-existing-branch"))
assert.NoError(t, UpdateIssuesCommit(t.Context(), user, repo, pushCommits, "non-existing-branch"))
unittest.AssertExistsAndLoadBean(t, commentBean)
unittest.AssertExistsAndLoadBean(t, issueBean, "is_closed=1")
unittest.CheckConsistencyFor(t, &activities_model.Action{})
@@ -208,7 +207,7 @@ func TestUpdateIssuesCommit_AnotherRepo(t *testing.T) {
unittest.AssertNotExistsBean(t, commentBean)
unittest.AssertNotExistsBean(t, issueBean, "is_closed=1")
assert.NoError(t, UpdateIssuesCommit(db.DefaultContext, user, repo, pushCommits, repo.DefaultBranch))
assert.NoError(t, UpdateIssuesCommit(t.Context(), user, repo, pushCommits, repo.DefaultBranch))
unittest.AssertExistsAndLoadBean(t, commentBean)
unittest.AssertExistsAndLoadBean(t, issueBean, "is_closed=1")
unittest.CheckConsistencyFor(t, &activities_model.Action{})
@@ -243,7 +242,7 @@ func TestUpdateIssuesCommit_AnotherRepo_FullAddress(t *testing.T) {
unittest.AssertNotExistsBean(t, commentBean)
unittest.AssertNotExistsBean(t, issueBean, "is_closed=1")
assert.NoError(t, UpdateIssuesCommit(db.DefaultContext, user, repo, pushCommits, repo.DefaultBranch))
assert.NoError(t, UpdateIssuesCommit(t.Context(), user, repo, pushCommits, repo.DefaultBranch))
unittest.AssertExistsAndLoadBean(t, commentBean)
unittest.AssertExistsAndLoadBean(t, issueBean, "is_closed=1")
unittest.CheckConsistencyFor(t, &activities_model.Action{})
@@ -293,7 +292,7 @@ func TestUpdateIssuesCommit_AnotherRepoNoPermission(t *testing.T) {
unittest.AssertNotExistsBean(t, commentBean)
unittest.AssertNotExistsBean(t, commentBean2)
unittest.AssertNotExistsBean(t, issueBean, "is_closed=1")
assert.NoError(t, UpdateIssuesCommit(db.DefaultContext, user, repo, pushCommits, repo.DefaultBranch))
assert.NoError(t, UpdateIssuesCommit(t.Context(), user, repo, pushCommits, repo.DefaultBranch))
unittest.AssertNotExistsBean(t, commentBean)
unittest.AssertNotExistsBean(t, commentBean2)
unittest.AssertNotExistsBean(t, issueBean, "is_closed=1")

View File

@@ -6,7 +6,6 @@ package issue
import (
"testing"
"code.gitea.io/gitea/models/db"
issues_model "code.gitea.io/gitea/models/issues"
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/unittest"
@@ -35,7 +34,7 @@ func TestGetRefEndNamesAndURLs(t *testing.T) {
func TestIssue_DeleteIssue(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
issueIDs, err := issues_model.GetIssueIDsByRepoID(db.DefaultContext, 1)
issueIDs, err := issues_model.GetIssueIDsByRepoID(t.Context(), 1)
assert.NoError(t, err)
assert.Len(t, issueIDs, 5)
@@ -44,43 +43,43 @@ func TestIssue_DeleteIssue(t *testing.T) {
ID: issueIDs[2],
}
_, err = deleteIssue(db.DefaultContext, issue)
_, err = deleteIssue(t.Context(), issue)
assert.NoError(t, err)
issueIDs, err = issues_model.GetIssueIDsByRepoID(db.DefaultContext, 1)
issueIDs, err = issues_model.GetIssueIDsByRepoID(t.Context(), 1)
assert.NoError(t, err)
assert.Len(t, issueIDs, 4)
// check attachment removal
attachments, err := repo_model.GetAttachmentsByIssueID(db.DefaultContext, 4)
attachments, err := repo_model.GetAttachmentsByIssueID(t.Context(), 4)
assert.NoError(t, err)
issue, err = issues_model.GetIssueByID(db.DefaultContext, 4)
issue, err = issues_model.GetIssueByID(t.Context(), 4)
assert.NoError(t, err)
_, err = deleteIssue(db.DefaultContext, issue)
_, err = deleteIssue(t.Context(), issue)
assert.NoError(t, err)
assert.Len(t, attachments, 2)
for i := range attachments {
attachment, err := repo_model.GetAttachmentByUUID(db.DefaultContext, attachments[i].UUID)
attachment, err := repo_model.GetAttachmentByUUID(t.Context(), attachments[i].UUID)
assert.Error(t, err)
assert.True(t, repo_model.IsErrAttachmentNotExist(err))
assert.Nil(t, attachment)
}
// check issue dependencies
user, err := user_model.GetUserByID(db.DefaultContext, 1)
user, err := user_model.GetUserByID(t.Context(), 1)
assert.NoError(t, err)
issue1, err := issues_model.GetIssueByID(db.DefaultContext, 1)
issue1, err := issues_model.GetIssueByID(t.Context(), 1)
assert.NoError(t, err)
issue2, err := issues_model.GetIssueByID(db.DefaultContext, 2)
issue2, err := issues_model.GetIssueByID(t.Context(), 2)
assert.NoError(t, err)
err = issues_model.CreateIssueDependency(db.DefaultContext, user, issue1, issue2)
err = issues_model.CreateIssueDependency(t.Context(), user, issue1, issue2)
assert.NoError(t, err)
left, err := issues_model.IssueNoDependenciesLeft(db.DefaultContext, issue1)
left, err := issues_model.IssueNoDependenciesLeft(t.Context(), issue1)
assert.NoError(t, err)
assert.False(t, left)
_, err = deleteIssue(db.DefaultContext, issue2)
_, err = deleteIssue(t.Context(), issue2)
assert.NoError(t, err)
left, err = issues_model.IssueNoDependenciesLeft(db.DefaultContext, issue1)
left, err = issues_model.IssueNoDependenciesLeft(t.Context(), issue1)
assert.NoError(t, err)
assert.True(t, left)
}

View File

@@ -6,7 +6,6 @@ package issue
import (
"testing"
"code.gitea.io/gitea/models/db"
issues_model "code.gitea.io/gitea/models/issues"
"code.gitea.io/gitea/models/unittest"
user_model "code.gitea.io/gitea/models/user"
@@ -33,7 +32,7 @@ func TestIssue_AddLabels(t *testing.T) {
labels[i] = unittest.AssertExistsAndLoadBean(t, &issues_model.Label{ID: labelID})
}
doer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: test.doerID})
assert.NoError(t, AddLabels(db.DefaultContext, issue, doer, labels))
assert.NoError(t, AddLabels(t.Context(), issue, doer, labels))
for _, labelID := range test.labelIDs {
unittest.AssertExistsAndLoadBean(t, &issues_model.IssueLabel{IssueID: test.issueID, LabelID: labelID})
}
@@ -56,7 +55,7 @@ func TestIssue_AddLabel(t *testing.T) {
issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: test.issueID})
label := unittest.AssertExistsAndLoadBean(t, &issues_model.Label{ID: test.labelID})
doer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: test.doerID})
assert.NoError(t, AddLabel(db.DefaultContext, issue, doer, label))
assert.NoError(t, AddLabel(t.Context(), issue, doer, label))
unittest.AssertExistsAndLoadBean(t, &issues_model.IssueLabel{IssueID: test.issueID, LabelID: test.labelID})
}
}

View File

@@ -6,7 +6,6 @@ package issue
import (
"testing"
"code.gitea.io/gitea/models/db"
issues_model "code.gitea.io/gitea/models/issues"
"code.gitea.io/gitea/models/unittest"
user_model "code.gitea.io/gitea/models/user"
@@ -23,8 +22,8 @@ func TestChangeMilestoneAssign(t *testing.T) {
oldMilestoneID := issue.MilestoneID
issue.MilestoneID = 2
assert.NoError(t, issue.LoadMilestone(db.DefaultContext))
assert.NoError(t, ChangeMilestoneAssign(db.DefaultContext, issue, doer, oldMilestoneID))
assert.NoError(t, issue.LoadMilestone(t.Context()))
assert.NoError(t, ChangeMilestoneAssign(t.Context(), issue, doer, oldMilestoneID))
unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{
IssueID: issue.ID,
Type: issues_model.CommentTypeMilestone,
@@ -36,7 +35,7 @@ func TestChangeMilestoneAssign(t *testing.T) {
oldMilestoneID = issue.MilestoneID
issue.MilestoneID = 0
assert.NoError(t, ChangeMilestoneAssign(db.DefaultContext, issue, doer, oldMilestoneID))
assert.NoError(t, ChangeMilestoneAssign(t.Context(), issue, doer, oldMilestoneID))
assert.EqualValues(t, 0, issue.MilestoneID)
assert.Nil(t, issue.Milestone)
}

View File

@@ -6,7 +6,6 @@ package issue
import (
"testing"
"code.gitea.io/gitea/models/db"
issues_model "code.gitea.io/gitea/models/issues"
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/unittest"
@@ -20,9 +19,9 @@ func addReaction(t *testing.T, doer *user_model.User, issue *issues_model.Issue,
var reaction *issues_model.Reaction
var err error
if comment == nil {
reaction, err = CreateIssueReaction(db.DefaultContext, doer, issue, content)
reaction, err = CreateIssueReaction(t.Context(), doer, issue, content)
} else {
reaction, err = CreateCommentReaction(db.DefaultContext, doer, comment, content)
reaction, err = CreateCommentReaction(t.Context(), doer, comment, content)
}
assert.NoError(t, err)
assert.NotNil(t, reaction)
@@ -47,7 +46,7 @@ func TestIssueAddDuplicateReaction(t *testing.T) {
addReaction(t, user1, issue, nil, "heart")
reaction, err := CreateIssueReaction(db.DefaultContext, user1, issue, "heart")
reaction, err := CreateIssueReaction(t.Context(), user1, issue, "heart")
assert.Error(t, err)
assert.Equal(t, issues_model.ErrReactionAlreadyExist{Reaction: "heart"}, err)
@@ -63,7 +62,7 @@ func TestIssueDeleteReaction(t *testing.T) {
addReaction(t, user1, issue, nil, "heart")
err := issues_model.DeleteIssueReaction(db.DefaultContext, user1.ID, issue.ID, "heart")
err := issues_model.DeleteIssueReaction(t.Context(), user1.ID, issue.ID, "heart")
assert.NoError(t, err)
unittest.AssertNotExistsBean(t, &issues_model.Reaction{Type: "heart", UserID: user1.ID, IssueID: issue.ID})
@@ -91,12 +90,12 @@ func TestIssueReactionCount(t *testing.T) {
addReaction(t, user4, issue, nil, "heart")
addReaction(t, ghost, issue, nil, "-1")
reactionsList, _, err := issues_model.FindReactions(db.DefaultContext, issues_model.FindReactionsOptions{
reactionsList, _, err := issues_model.FindReactions(t.Context(), issues_model.FindReactionsOptions{
IssueID: issue.ID,
})
assert.NoError(t, err)
assert.Len(t, reactionsList, 7)
_, err = reactionsList.LoadUsers(db.DefaultContext, repo)
_, err = reactionsList.LoadUsers(t.Context(), repo)
assert.NoError(t, err)
reactions := reactionsList.GroupByType()
@@ -137,7 +136,7 @@ func TestIssueCommentDeleteReaction(t *testing.T) {
addReaction(t, org3, nil, comment, "heart")
addReaction(t, user4, nil, comment, "+1")
reactionsList, _, err := issues_model.FindReactions(db.DefaultContext, issues_model.FindReactionsOptions{
reactionsList, _, err := issues_model.FindReactions(t.Context(), issues_model.FindReactionsOptions{
IssueID: comment.IssueID,
CommentID: comment.ID,
})
@@ -156,7 +155,7 @@ func TestIssueCommentReactionCount(t *testing.T) {
comment := unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{ID: 1})
addReaction(t, user1, nil, comment, "heart")
assert.NoError(t, issues_model.DeleteCommentReaction(db.DefaultContext, user1.ID, comment.IssueID, comment.ID, "heart"))
assert.NoError(t, issues_model.DeleteCommentReaction(t.Context(), user1.ID, comment.IssueID, comment.ID, "heart"))
unittest.AssertNotExistsBean(t, &issues_model.Reaction{Type: "heart", UserID: user1.ID, IssueID: comment.IssueID, CommentID: comment.ID})
}

View File

@@ -6,7 +6,6 @@ package issue
import (
"testing"
"code.gitea.io/gitea/models/db"
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/unittest"
"code.gitea.io/gitea/modules/optional"
@@ -44,7 +43,7 @@ func Test_Suggestion(t *testing.T) {
for _, testCase := range testCases {
t.Run(testCase.keyword, func(t *testing.T) {
issues, err := GetSuggestion(db.DefaultContext, repo1, testCase.isPull, testCase.keyword)
issues, err := GetSuggestion(t.Context(), repo1, testCase.isPull, testCase.keyword)
assert.NoError(t, err)
issueIndexes := make([]int64, 0, len(issues))