aboutsummaryrefslogtreecommitdiffstats
path: root/services/pull
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/pull
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/pull')
-rw-r--r--services/pull/check_test.go9
-rw-r--r--services/pull/main_test.go4
-rw-r--r--services/pull/pull.go3
-rw-r--r--services/pull/review.go5
4 files changed, 12 insertions, 9 deletions
diff --git a/services/pull/check_test.go b/services/pull/check_test.go
index f6614ea0ad..8beea3d56d 100644
--- a/services/pull/check_test.go
+++ b/services/pull/check_test.go
@@ -11,13 +11,14 @@ import (
"time"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/queue"
"github.com/stretchr/testify/assert"
)
func TestPullRequest_AddToTaskQueue(t *testing.T) {
- assert.NoError(t, models.PrepareTestDatabase())
+ assert.NoError(t, db.PrepareTestDatabase())
idChan := make(chan int64, 10)
@@ -41,11 +42,11 @@ func TestPullRequest_AddToTaskQueue(t *testing.T) {
prQueue = q.(queue.UniqueQueue)
- pr := models.AssertExistsAndLoadBean(t, &models.PullRequest{ID: 2}).(*models.PullRequest)
+ pr := db.AssertExistsAndLoadBean(t, &models.PullRequest{ID: 2}).(*models.PullRequest)
AddToTaskQueue(pr)
assert.Eventually(t, func() bool {
- pr = models.AssertExistsAndLoadBean(t, &models.PullRequest{ID: 2}).(*models.PullRequest)
+ pr = db.AssertExistsAndLoadBean(t, &models.PullRequest{ID: 2}).(*models.PullRequest)
return pr.Status == models.PullRequestStatusChecking
}, 1*time.Second, 100*time.Millisecond)
@@ -70,7 +71,7 @@ func TestPullRequest_AddToTaskQueue(t *testing.T) {
assert.False(t, has)
assert.NoError(t, err)
- pr = models.AssertExistsAndLoadBean(t, &models.PullRequest{ID: 2}).(*models.PullRequest)
+ pr = db.AssertExistsAndLoadBean(t, &models.PullRequest{ID: 2}).(*models.PullRequest)
assert.Equal(t, models.PullRequestStatusChecking, pr.Status)
for _, callback := range queueShutdown {
diff --git a/services/pull/main_test.go b/services/pull/main_test.go
index 6c49e8fbf2..c8d3394e8e 100644
--- a/services/pull/main_test.go
+++ b/services/pull/main_test.go
@@ -9,9 +9,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("..", ".."))
}
diff --git a/services/pull/pull.go b/services/pull/pull.go
index 23407ea67b..d78d9b1bd0 100644
--- a/services/pull/pull.go
+++ b/services/pull/pull.go
@@ -14,6 +14,7 @@ import (
"time"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/graceful"
"code.gitea.io/gitea/modules/json"
@@ -58,7 +59,7 @@ func NewPullRequest(repo *models.Repository, pull *models.Issue, labelIDs []int6
return err
}
- mentions, err := pull.FindAndUpdateIssueMentions(models.DefaultDBContext(), pull.Poster, pull.Content)
+ mentions, err := pull.FindAndUpdateIssueMentions(db.DefaultContext(), pull.Poster, pull.Content)
if err != nil {
return err
}
diff --git a/services/pull/review.go b/services/pull/review.go
index 3aa4570620..ce34cc59df 100644
--- a/services/pull/review.go
+++ b/services/pull/review.go
@@ -12,6 +12,7 @@ import (
"strings"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/notification"
@@ -58,7 +59,7 @@ func CreateCodeComment(doer *models.User, gitRepo *git.Repository, issue *models
return nil, err
}
- mentions, err := issue.FindAndUpdateIssueMentions(models.DefaultDBContext(), doer, comment.Content)
+ mentions, err := issue.FindAndUpdateIssueMentions(db.DefaultContext(), doer, comment.Content)
if err != nil {
return nil, err
}
@@ -245,7 +246,7 @@ func SubmitReview(doer *models.User, gitRepo *git.Repository, issue *models.Issu
return nil, nil, err
}
- ctx := models.DefaultDBContext()
+ ctx := db.DefaultContext()
mentions, err := issue.FindAndUpdateIssueMentions(ctx, doer, comm.Content)
if err != nil {
return nil, nil, err