aboutsummaryrefslogtreecommitdiffstats
path: root/services/issue
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2021-09-19 19:49:59 +0800
committerGitHub <noreply@github.com>2021-09-19 19:49:59 +0800
commita4bfef265d9e512830350635a0489c2cdcd6508f (patch)
tree1e3c2ec94276dfcb2f8ba73a2ac075ba39c4a34a /services/issue
parent462306e263db5a809dbe2cdf62e99307aeff28de (diff)
downloadgitea-a4bfef265d9e512830350635a0489c2cdcd6508f.tar.gz
gitea-a4bfef265d9e512830350635a0489c2cdcd6508f.zip
Move db related basic functions to models/db (#17075)
* Move db related basic functions to models/db * Fix lint * Fix lint * Fix test * Fix lint * Fix lint * revert unnecessary change * Fix test * Fix wrong replace string * Use *Context * Correct committer spelling and fix wrong replaced words Co-authored-by: zeripath <art27@cantab.net>
Diffstat (limited to 'services/issue')
-rw-r--r--services/issue/assignee_test.go3
-rw-r--r--services/issue/issue.go3
-rw-r--r--services/issue/label_test.go21
-rw-r--r--services/issue/main_test.go4
4 files changed, 17 insertions, 14 deletions
diff --git a/services/issue/assignee_test.go b/services/issue/assignee_test.go
index 2d96368ec7..5684ed6d89 100644
--- a/services/issue/assignee_test.go
+++ b/services/issue/assignee_test.go
@@ -8,11 +8,12 @@ import (
"testing"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
"github.com/stretchr/testify/assert"
)
func TestDeleteNotPassedAssignee(t *testing.T) {
- assert.NoError(t, models.PrepareTestDatabase())
+ assert.NoError(t, db.PrepareTestDatabase())
// Fake issue with assignees
issue, err := models.GetIssueWithAttrsByID(1)
diff --git a/services/issue/issue.go b/services/issue/issue.go
index 90f689a55c..b2ac24e088 100644
--- a/services/issue/issue.go
+++ b/services/issue/issue.go
@@ -6,6 +6,7 @@ package issue
import (
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/notification"
"code.gitea.io/gitea/modules/util"
@@ -23,7 +24,7 @@ func NewIssue(repo *models.Repository, issue *models.Issue, labelIDs []int64, uu
}
}
- mentions, err := issue.FindAndUpdateIssueMentions(models.DefaultDBContext(), issue.Poster, issue.Content)
+ mentions, err := issue.FindAndUpdateIssueMentions(db.DefaultContext(), issue.Poster, issue.Content)
if err != nil {
return err
}
diff --git a/services/issue/label_test.go b/services/issue/label_test.go
index 0652028943..8a3a77ecb0 100644
--- a/services/issue/label_test.go
+++ b/services/issue/label_test.go
@@ -8,6 +8,7 @@ import (
"testing"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
"github.com/stretchr/testify/assert"
)
@@ -23,16 +24,16 @@ func TestIssue_AddLabels(t *testing.T) {
{2, []int64{}, 1}, // pull-request, empty
}
for _, test := range tests {
- assert.NoError(t, models.PrepareTestDatabase())
- issue := models.AssertExistsAndLoadBean(t, &models.Issue{ID: test.issueID}).(*models.Issue)
+ assert.NoError(t, db.PrepareTestDatabase())
+ issue := db.AssertExistsAndLoadBean(t, &models.Issue{ID: test.issueID}).(*models.Issue)
labels := make([]*models.Label, len(test.labelIDs))
for i, labelID := range test.labelIDs {
- labels[i] = models.AssertExistsAndLoadBean(t, &models.Label{ID: labelID}).(*models.Label)
+ labels[i] = db.AssertExistsAndLoadBean(t, &models.Label{ID: labelID}).(*models.Label)
}
- doer := models.AssertExistsAndLoadBean(t, &models.User{ID: test.doerID}).(*models.User)
+ doer := db.AssertExistsAndLoadBean(t, &models.User{ID: test.doerID}).(*models.User)
assert.NoError(t, AddLabels(issue, doer, labels))
for _, labelID := range test.labelIDs {
- models.AssertExistsAndLoadBean(t, &models.IssueLabel{IssueID: test.issueID, LabelID: labelID})
+ db.AssertExistsAndLoadBean(t, &models.IssueLabel{IssueID: test.issueID, LabelID: labelID})
}
}
}
@@ -49,11 +50,11 @@ func TestIssue_AddLabel(t *testing.T) {
{2, 1, 2}, // pull-request, already-added label
}
for _, test := range tests {
- assert.NoError(t, models.PrepareTestDatabase())
- issue := models.AssertExistsAndLoadBean(t, &models.Issue{ID: test.issueID}).(*models.Issue)
- label := models.AssertExistsAndLoadBean(t, &models.Label{ID: test.labelID}).(*models.Label)
- doer := models.AssertExistsAndLoadBean(t, &models.User{ID: test.doerID}).(*models.User)
+ assert.NoError(t, db.PrepareTestDatabase())
+ issue := db.AssertExistsAndLoadBean(t, &models.Issue{ID: test.issueID}).(*models.Issue)
+ label := db.AssertExistsAndLoadBean(t, &models.Label{ID: test.labelID}).(*models.Label)
+ doer := db.AssertExistsAndLoadBean(t, &models.User{ID: test.doerID}).(*models.User)
assert.NoError(t, AddLabel(issue, doer, label))
- models.AssertExistsAndLoadBean(t, &models.IssueLabel{IssueID: test.issueID, LabelID: test.labelID})
+ db.AssertExistsAndLoadBean(t, &models.IssueLabel{IssueID: test.issueID, LabelID: test.labelID})
}
}
diff --git a/services/issue/main_test.go b/services/issue/main_test.go
index b056678a42..1349837949 100644
--- a/services/issue/main_test.go
+++ b/services/issue/main_test.go
@@ -8,9 +8,9 @@ import (
"path/filepath"
"testing"
- "code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
)
func TestMain(m *testing.M) {
- models.MainTest(m, filepath.Join("..", ".."))
+ db.MainTest(m, filepath.Join("..", ".."))
}