mirror of
https://github.com/go-gitea/gitea
synced 2025-07-15 23:17:19 +00:00
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>
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/modules/repository"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
|
||||
@@ -15,7 +16,7 @@ import (
|
||||
)
|
||||
|
||||
func TestUpdateIssuesCommit(t *testing.T) {
|
||||
assert.NoError(t, models.PrepareTestDatabase())
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
pushCommits := []*repository.PushCommit{
|
||||
{
|
||||
Sha1: "abcdef1",
|
||||
@@ -43,8 +44,8 @@ func TestUpdateIssuesCommit(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
user := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
|
||||
repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
|
||||
user := db.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
|
||||
repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
|
||||
repo.Owner = user
|
||||
|
||||
commentBean := &models.Comment{
|
||||
@@ -55,11 +56,11 @@ func TestUpdateIssuesCommit(t *testing.T) {
|
||||
}
|
||||
issueBean := &models.Issue{RepoID: repo.ID, Index: 4}
|
||||
|
||||
models.AssertNotExistsBean(t, commentBean)
|
||||
models.AssertNotExistsBean(t, &models.Issue{RepoID: repo.ID, Index: 2}, "is_closed=1")
|
||||
db.AssertNotExistsBean(t, commentBean)
|
||||
db.AssertNotExistsBean(t, &models.Issue{RepoID: repo.ID, Index: 2}, "is_closed=1")
|
||||
assert.NoError(t, UpdateIssuesCommit(user, repo, pushCommits, repo.DefaultBranch))
|
||||
models.AssertExistsAndLoadBean(t, commentBean)
|
||||
models.AssertExistsAndLoadBean(t, issueBean, "is_closed=1")
|
||||
db.AssertExistsAndLoadBean(t, commentBean)
|
||||
db.AssertExistsAndLoadBean(t, issueBean, "is_closed=1")
|
||||
models.CheckConsistencyFor(t, &models.Action{})
|
||||
|
||||
// Test that push to a non-default branch closes no issue.
|
||||
@@ -73,7 +74,7 @@ func TestUpdateIssuesCommit(t *testing.T) {
|
||||
Message: "close #1",
|
||||
},
|
||||
}
|
||||
repo = models.AssertExistsAndLoadBean(t, &models.Repository{ID: 3}).(*models.Repository)
|
||||
repo = db.AssertExistsAndLoadBean(t, &models.Repository{ID: 3}).(*models.Repository)
|
||||
commentBean = &models.Comment{
|
||||
Type: models.CommentTypeCommitRef,
|
||||
CommitSHA: "abcdef1",
|
||||
@@ -82,11 +83,11 @@ func TestUpdateIssuesCommit(t *testing.T) {
|
||||
}
|
||||
issueBean = &models.Issue{RepoID: repo.ID, Index: 1}
|
||||
|
||||
models.AssertNotExistsBean(t, commentBean)
|
||||
models.AssertNotExistsBean(t, &models.Issue{RepoID: repo.ID, Index: 1}, "is_closed=1")
|
||||
db.AssertNotExistsBean(t, commentBean)
|
||||
db.AssertNotExistsBean(t, &models.Issue{RepoID: repo.ID, Index: 1}, "is_closed=1")
|
||||
assert.NoError(t, UpdateIssuesCommit(user, repo, pushCommits, "non-existing-branch"))
|
||||
models.AssertExistsAndLoadBean(t, commentBean)
|
||||
models.AssertNotExistsBean(t, issueBean, "is_closed=1")
|
||||
db.AssertExistsAndLoadBean(t, commentBean)
|
||||
db.AssertNotExistsBean(t, issueBean, "is_closed=1")
|
||||
models.CheckConsistencyFor(t, &models.Action{})
|
||||
|
||||
pushCommits = []*repository.PushCommit{
|
||||
@@ -99,7 +100,7 @@ func TestUpdateIssuesCommit(t *testing.T) {
|
||||
Message: "close " + setting.AppURL + repo.FullName() + "/pulls/1",
|
||||
},
|
||||
}
|
||||
repo = models.AssertExistsAndLoadBean(t, &models.Repository{ID: 3}).(*models.Repository)
|
||||
repo = db.AssertExistsAndLoadBean(t, &models.Repository{ID: 3}).(*models.Repository)
|
||||
commentBean = &models.Comment{
|
||||
Type: models.CommentTypeCommitRef,
|
||||
CommitSHA: "abcdef3",
|
||||
@@ -108,16 +109,16 @@ func TestUpdateIssuesCommit(t *testing.T) {
|
||||
}
|
||||
issueBean = &models.Issue{RepoID: repo.ID, Index: 1}
|
||||
|
||||
models.AssertNotExistsBean(t, commentBean)
|
||||
models.AssertNotExistsBean(t, &models.Issue{RepoID: repo.ID, Index: 1}, "is_closed=1")
|
||||
db.AssertNotExistsBean(t, commentBean)
|
||||
db.AssertNotExistsBean(t, &models.Issue{RepoID: repo.ID, Index: 1}, "is_closed=1")
|
||||
assert.NoError(t, UpdateIssuesCommit(user, repo, pushCommits, repo.DefaultBranch))
|
||||
models.AssertExistsAndLoadBean(t, commentBean)
|
||||
models.AssertExistsAndLoadBean(t, issueBean, "is_closed=1")
|
||||
db.AssertExistsAndLoadBean(t, commentBean)
|
||||
db.AssertExistsAndLoadBean(t, issueBean, "is_closed=1")
|
||||
models.CheckConsistencyFor(t, &models.Action{})
|
||||
}
|
||||
|
||||
func TestUpdateIssuesCommit_Colon(t *testing.T) {
|
||||
assert.NoError(t, models.PrepareTestDatabase())
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
pushCommits := []*repository.PushCommit{
|
||||
{
|
||||
Sha1: "abcdef2",
|
||||
@@ -129,21 +130,21 @@ func TestUpdateIssuesCommit_Colon(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
user := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
|
||||
repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
|
||||
user := db.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
|
||||
repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
|
||||
repo.Owner = user
|
||||
|
||||
issueBean := &models.Issue{RepoID: repo.ID, Index: 4}
|
||||
|
||||
models.AssertNotExistsBean(t, &models.Issue{RepoID: repo.ID, Index: 2}, "is_closed=1")
|
||||
db.AssertNotExistsBean(t, &models.Issue{RepoID: repo.ID, Index: 2}, "is_closed=1")
|
||||
assert.NoError(t, UpdateIssuesCommit(user, repo, pushCommits, repo.DefaultBranch))
|
||||
models.AssertExistsAndLoadBean(t, issueBean, "is_closed=1")
|
||||
db.AssertExistsAndLoadBean(t, issueBean, "is_closed=1")
|
||||
models.CheckConsistencyFor(t, &models.Action{})
|
||||
}
|
||||
|
||||
func TestUpdateIssuesCommit_Issue5957(t *testing.T) {
|
||||
assert.NoError(t, models.PrepareTestDatabase())
|
||||
user := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
user := db.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
|
||||
|
||||
// Test that push to a non-default branch closes an issue.
|
||||
pushCommits := []*repository.PushCommit{
|
||||
@@ -157,7 +158,7 @@ func TestUpdateIssuesCommit_Issue5957(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 2}).(*models.Repository)
|
||||
repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 2}).(*models.Repository)
|
||||
commentBean := &models.Comment{
|
||||
Type: models.CommentTypeCommitRef,
|
||||
CommitSHA: "abcdef1",
|
||||
@@ -167,17 +168,17 @@ func TestUpdateIssuesCommit_Issue5957(t *testing.T) {
|
||||
|
||||
issueBean := &models.Issue{RepoID: repo.ID, Index: 2, ID: 7}
|
||||
|
||||
models.AssertNotExistsBean(t, commentBean)
|
||||
models.AssertNotExistsBean(t, issueBean, "is_closed=1")
|
||||
db.AssertNotExistsBean(t, commentBean)
|
||||
db.AssertNotExistsBean(t, issueBean, "is_closed=1")
|
||||
assert.NoError(t, UpdateIssuesCommit(user, repo, pushCommits, "non-existing-branch"))
|
||||
models.AssertExistsAndLoadBean(t, commentBean)
|
||||
models.AssertExistsAndLoadBean(t, issueBean, "is_closed=1")
|
||||
db.AssertExistsAndLoadBean(t, commentBean)
|
||||
db.AssertExistsAndLoadBean(t, issueBean, "is_closed=1")
|
||||
models.CheckConsistencyFor(t, &models.Action{})
|
||||
}
|
||||
|
||||
func TestUpdateIssuesCommit_AnotherRepo(t *testing.T) {
|
||||
assert.NoError(t, models.PrepareTestDatabase())
|
||||
user := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
user := db.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
|
||||
|
||||
// Test that a push to default branch closes issue in another repo
|
||||
// If the user also has push permissions to that repo
|
||||
@@ -192,7 +193,7 @@ func TestUpdateIssuesCommit_AnotherRepo(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 2}).(*models.Repository)
|
||||
repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 2}).(*models.Repository)
|
||||
commentBean := &models.Comment{
|
||||
Type: models.CommentTypeCommitRef,
|
||||
CommitSHA: "abcdef1",
|
||||
@@ -202,17 +203,17 @@ func TestUpdateIssuesCommit_AnotherRepo(t *testing.T) {
|
||||
|
||||
issueBean := &models.Issue{RepoID: 1, Index: 1, ID: 1}
|
||||
|
||||
models.AssertNotExistsBean(t, commentBean)
|
||||
models.AssertNotExistsBean(t, issueBean, "is_closed=1")
|
||||
db.AssertNotExistsBean(t, commentBean)
|
||||
db.AssertNotExistsBean(t, issueBean, "is_closed=1")
|
||||
assert.NoError(t, UpdateIssuesCommit(user, repo, pushCommits, repo.DefaultBranch))
|
||||
models.AssertExistsAndLoadBean(t, commentBean)
|
||||
models.AssertExistsAndLoadBean(t, issueBean, "is_closed=1")
|
||||
db.AssertExistsAndLoadBean(t, commentBean)
|
||||
db.AssertExistsAndLoadBean(t, issueBean, "is_closed=1")
|
||||
models.CheckConsistencyFor(t, &models.Action{})
|
||||
}
|
||||
|
||||
func TestUpdateIssuesCommit_AnotherRepo_FullAddress(t *testing.T) {
|
||||
assert.NoError(t, models.PrepareTestDatabase())
|
||||
user := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
user := db.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
|
||||
|
||||
// Test that a push to default branch closes issue in another repo
|
||||
// If the user also has push permissions to that repo
|
||||
@@ -227,7 +228,7 @@ func TestUpdateIssuesCommit_AnotherRepo_FullAddress(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 2}).(*models.Repository)
|
||||
repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 2}).(*models.Repository)
|
||||
commentBean := &models.Comment{
|
||||
Type: models.CommentTypeCommitRef,
|
||||
CommitSHA: "abcdef1",
|
||||
@@ -237,17 +238,17 @@ func TestUpdateIssuesCommit_AnotherRepo_FullAddress(t *testing.T) {
|
||||
|
||||
issueBean := &models.Issue{RepoID: 1, Index: 1, ID: 1}
|
||||
|
||||
models.AssertNotExistsBean(t, commentBean)
|
||||
models.AssertNotExistsBean(t, issueBean, "is_closed=1")
|
||||
db.AssertNotExistsBean(t, commentBean)
|
||||
db.AssertNotExistsBean(t, issueBean, "is_closed=1")
|
||||
assert.NoError(t, UpdateIssuesCommit(user, repo, pushCommits, repo.DefaultBranch))
|
||||
models.AssertExistsAndLoadBean(t, commentBean)
|
||||
models.AssertExistsAndLoadBean(t, issueBean, "is_closed=1")
|
||||
db.AssertExistsAndLoadBean(t, commentBean)
|
||||
db.AssertExistsAndLoadBean(t, issueBean, "is_closed=1")
|
||||
models.CheckConsistencyFor(t, &models.Action{})
|
||||
}
|
||||
|
||||
func TestUpdateIssuesCommit_AnotherRepoNoPermission(t *testing.T) {
|
||||
assert.NoError(t, models.PrepareTestDatabase())
|
||||
user := models.AssertExistsAndLoadBean(t, &models.User{ID: 10}).(*models.User)
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
user := db.AssertExistsAndLoadBean(t, &models.User{ID: 10}).(*models.User)
|
||||
|
||||
// Test that a push with close reference *can not* close issue
|
||||
// If the committer doesn't have push rights in that repo
|
||||
@@ -270,7 +271,7 @@ func TestUpdateIssuesCommit_AnotherRepoNoPermission(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 6}).(*models.Repository)
|
||||
repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 6}).(*models.Repository)
|
||||
commentBean := &models.Comment{
|
||||
Type: models.CommentTypeCommitRef,
|
||||
CommitSHA: "abcdef3",
|
||||
@@ -286,12 +287,12 @@ func TestUpdateIssuesCommit_AnotherRepoNoPermission(t *testing.T) {
|
||||
|
||||
issueBean := &models.Issue{RepoID: 3, Index: 1, ID: 6}
|
||||
|
||||
models.AssertNotExistsBean(t, commentBean)
|
||||
models.AssertNotExistsBean(t, commentBean2)
|
||||
models.AssertNotExistsBean(t, issueBean, "is_closed=1")
|
||||
db.AssertNotExistsBean(t, commentBean)
|
||||
db.AssertNotExistsBean(t, commentBean2)
|
||||
db.AssertNotExistsBean(t, issueBean, "is_closed=1")
|
||||
assert.NoError(t, UpdateIssuesCommit(user, repo, pushCommits, repo.DefaultBranch))
|
||||
models.AssertNotExistsBean(t, commentBean)
|
||||
models.AssertNotExistsBean(t, commentBean2)
|
||||
models.AssertNotExistsBean(t, issueBean, "is_closed=1")
|
||||
db.AssertNotExistsBean(t, commentBean)
|
||||
db.AssertNotExistsBean(t, commentBean2)
|
||||
db.AssertNotExistsBean(t, issueBean, "is_closed=1")
|
||||
models.CheckConsistencyFor(t, &models.Action{})
|
||||
}
|
||||
|
Reference in New Issue
Block a user