mirror of
https://github.com/go-gitea/gitea
synced 2025-07-03 09:07: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:
@ -9,6 +9,7 @@ import (
|
||||
"time"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
@ -17,8 +18,8 @@ import (
|
||||
)
|
||||
|
||||
func TestToCommitMeta(t *testing.T) {
|
||||
assert.NoError(t, models.PrepareTestDatabase())
|
||||
headRepo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
headRepo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
|
||||
sha1, _ := git.NewIDFromString("0000000000000000000000000000000000000000")
|
||||
signature := &git.Signature{Name: "Test Signature", Email: "test@email.com", When: time.Unix(0, 0)}
|
||||
tag := &git.Tag{
|
||||
|
@ -10,6 +10,7 @@ import (
|
||||
"time"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/modules/timeutil"
|
||||
@ -18,9 +19,9 @@ import (
|
||||
)
|
||||
|
||||
func TestLabel_ToLabel(t *testing.T) {
|
||||
assert.NoError(t, models.PrepareTestDatabase())
|
||||
label := models.AssertExistsAndLoadBean(t, &models.Label{ID: 1}).(*models.Label)
|
||||
repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: label.RepoID}).(*models.Repository)
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
label := db.AssertExistsAndLoadBean(t, &models.Label{ID: 1}).(*models.Label)
|
||||
repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: label.RepoID}).(*models.Repository)
|
||||
assert.Equal(t, &api.Label{
|
||||
ID: label.ID,
|
||||
Name: label.Name,
|
||||
|
@ -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("..", ".."))
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/modules/structs"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
@ -15,9 +16,9 @@ import (
|
||||
|
||||
func TestPullRequest_APIFormat(t *testing.T) {
|
||||
//with HeadRepo
|
||||
assert.NoError(t, models.PrepareTestDatabase())
|
||||
headRepo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
|
||||
pr := models.AssertExistsAndLoadBean(t, &models.PullRequest{ID: 1}).(*models.PullRequest)
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
headRepo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
|
||||
pr := db.AssertExistsAndLoadBean(t, &models.PullRequest{ID: 1}).(*models.PullRequest)
|
||||
assert.NoError(t, pr.LoadAttributes())
|
||||
assert.NoError(t, pr.LoadIssue())
|
||||
apiPullRequest := ToAPIPullRequest(pr)
|
||||
@ -31,7 +32,7 @@ func TestPullRequest_APIFormat(t *testing.T) {
|
||||
}, apiPullRequest.Head)
|
||||
|
||||
//withOut HeadRepo
|
||||
pr = models.AssertExistsAndLoadBean(t, &models.PullRequest{ID: 1}).(*models.PullRequest)
|
||||
pr = db.AssertExistsAndLoadBean(t, &models.PullRequest{ID: 1}).(*models.PullRequest)
|
||||
assert.NoError(t, pr.LoadIssue())
|
||||
assert.NoError(t, pr.LoadAttributes())
|
||||
// simulate fork deletion
|
||||
|
@ -8,20 +8,21 @@ import (
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestUser_ToUser(t *testing.T) {
|
||||
assert.NoError(t, models.PrepareTestDatabase())
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
|
||||
user1 := models.AssertExistsAndLoadBean(t, &models.User{ID: 1, IsAdmin: true}).(*models.User)
|
||||
user1 := db.AssertExistsAndLoadBean(t, &models.User{ID: 1, IsAdmin: true}).(*models.User)
|
||||
|
||||
apiUser := toUser(user1, true, true)
|
||||
assert.True(t, apiUser.IsAdmin)
|
||||
|
||||
user2 := models.AssertExistsAndLoadBean(t, &models.User{ID: 2, IsAdmin: false}).(*models.User)
|
||||
user2 := db.AssertExistsAndLoadBean(t, &models.User{ID: 2, IsAdmin: false}).(*models.User)
|
||||
|
||||
apiUser = toUser(user2, true, true)
|
||||
assert.False(t, apiUser.IsAdmin)
|
||||
@ -30,7 +31,7 @@ func TestUser_ToUser(t *testing.T) {
|
||||
assert.False(t, apiUser.IsAdmin)
|
||||
assert.EqualValues(t, api.VisibleTypePublic.String(), apiUser.Visibility)
|
||||
|
||||
user31 := models.AssertExistsAndLoadBean(t, &models.User{ID: 31, IsAdmin: false, Visibility: api.VisibleTypePrivate}).(*models.User)
|
||||
user31 := db.AssertExistsAndLoadBean(t, &models.User{ID: 31, IsAdmin: false, Visibility: api.VisibleTypePrivate}).(*models.User)
|
||||
|
||||
apiUser = toUser(user31, true, true)
|
||||
assert.False(t, apiUser.IsAdmin)
|
||||
|
@ -8,6 +8,7 @@ import (
|
||||
"context"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/models/migrations"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
@ -15,7 +16,7 @@ import (
|
||||
|
||||
func checkDBConsistency(logger log.Logger, autofix bool) error {
|
||||
// make sure DB version is uptodate
|
||||
if err := models.NewEngine(context.Background(), migrations.EnsureUpToDate); err != nil {
|
||||
if err := db.NewEngine(context.Background(), migrations.EnsureUpToDate); err != nil {
|
||||
logger.Critical("Model version on the database does not match the current Gitea version. Model consistency will not be checked until the database is upgraded")
|
||||
return err
|
||||
}
|
||||
@ -225,14 +226,14 @@ func checkDBConsistency(logger log.Logger, autofix bool) error {
|
||||
// TODO: function to recalc all counters
|
||||
|
||||
if setting.Database.UsePostgreSQL {
|
||||
count, err = models.CountBadSequences()
|
||||
count, err = db.CountBadSequences()
|
||||
if err != nil {
|
||||
logger.Critical("Error: %v whilst checking sequence values", err)
|
||||
return err
|
||||
}
|
||||
if count > 0 {
|
||||
if autofix {
|
||||
err := models.FixBadSequences()
|
||||
err := db.FixBadSequences()
|
||||
if err != nil {
|
||||
logger.Critical("Error: %v whilst attempting to fix sequences", err)
|
||||
return err
|
||||
|
@ -7,13 +7,13 @@ package doctor
|
||||
import (
|
||||
"context"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/models/migrations"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
)
|
||||
|
||||
func checkDBVersion(logger log.Logger, autofix bool) error {
|
||||
if err := models.NewEngine(context.Background(), migrations.EnsureUpToDate); err != nil {
|
||||
if err := db.NewEngine(context.Background(), migrations.EnsureUpToDate); err != nil {
|
||||
if !autofix {
|
||||
logger.Critical("Error: %v during ensure up to date", err)
|
||||
return err
|
||||
@ -21,7 +21,7 @@ func checkDBVersion(logger log.Logger, autofix bool) error {
|
||||
logger.Warn("Got Error: %v during ensure up to date", err)
|
||||
logger.Warn("Attempting to migrate to the latest DB version to fix this.")
|
||||
|
||||
err = models.NewEngine(context.Background(), migrations.Migrate)
|
||||
err = db.NewEngine(context.Background(), migrations.Migrate)
|
||||
if err != nil {
|
||||
logger.Critical("Error: %v during migration", err)
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
)
|
||||
@ -47,7 +47,7 @@ func initDBDisableConsole(disableConsole bool) error {
|
||||
setting.InitDBConfig()
|
||||
|
||||
setting.NewXORMLogService(disableConsole)
|
||||
if err := models.SetEngine(); err != nil {
|
||||
if err := db.SetEngine(); err != nil {
|
||||
return fmt.Errorf("models.SetEngine: %v", err)
|
||||
}
|
||||
return nil
|
||||
|
@ -9,14 +9,16 @@ 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"
|
||||
|
||||
"xorm.io/builder"
|
||||
)
|
||||
|
||||
func iteratePRs(repo *models.Repository, each func(*models.Repository, *models.PullRequest) error) error {
|
||||
return models.Iterate(
|
||||
models.DefaultDBContext(),
|
||||
return db.Iterate(
|
||||
db.DefaultContext(),
|
||||
new(models.PullRequest),
|
||||
builder.Eq{"base_repo_id": repo.ID},
|
||||
func(idx int, bean interface{}) error {
|
||||
|
@ -12,19 +12,21 @@ 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/repository"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
|
||||
lru "github.com/hashicorp/golang-lru"
|
||||
"xorm.io/builder"
|
||||
)
|
||||
|
||||
func iterateRepositories(each func(*models.Repository) error) error {
|
||||
err := models.Iterate(
|
||||
models.DefaultDBContext(),
|
||||
err := db.Iterate(
|
||||
db.DefaultContext(),
|
||||
new(models.Repository),
|
||||
builder.Gt{"id": 0},
|
||||
func(idx int, bean interface{}) error {
|
||||
|
@ -8,14 +8,14 @@ import (
|
||||
"io/ioutil"
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestBleveIndexAndSearch(t *testing.T) {
|
||||
models.PrepareTestEnv(t)
|
||||
db.PrepareTestEnv(t)
|
||||
|
||||
dir, err := ioutil.TempDir("", "bleve.index")
|
||||
assert.NoError(t, err)
|
||||
|
@ -8,13 +8,12 @@ import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestESIndexAndSearch(t *testing.T) {
|
||||
models.PrepareTestEnv(t)
|
||||
db.PrepareTestEnv(t)
|
||||
|
||||
u := os.Getenv("TEST_INDEXER_CODE_ES_URL")
|
||||
if u == "" {
|
||||
|
@ -12,6 +12,7 @@ import (
|
||||
"time"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/modules/graceful"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/queue"
|
||||
@ -285,7 +286,7 @@ func UpdateRepoIndexer(repo *models.Repository) {
|
||||
func populateRepoIndexer(ctx context.Context) {
|
||||
log.Info("Populating the repo indexer with existing repositories")
|
||||
|
||||
exist, err := models.IsTableNotEmpty("repository")
|
||||
exist, err := db.IsTableNotEmpty("repository")
|
||||
if err != nil {
|
||||
log.Fatal("System error: %v", err)
|
||||
} else if !exist {
|
||||
@ -295,12 +296,12 @@ func populateRepoIndexer(ctx context.Context) {
|
||||
// if there is any existing repo indexer metadata in the DB, delete it
|
||||
// since we are starting afresh. Also, xorm requires deletes to have a
|
||||
// condition, and we want to delete everything, thus 1=1.
|
||||
if err := models.DeleteAllRecords("repo_indexer_status"); err != nil {
|
||||
if err := db.DeleteAllRecords("repo_indexer_status"); err != nil {
|
||||
log.Fatal("System error: %v", err)
|
||||
}
|
||||
|
||||
var maxRepoID int64
|
||||
if maxRepoID, err = models.GetMaxID("repository"); err != nil {
|
||||
if maxRepoID, err = db.GetMaxID("repository"); err != nil {
|
||||
log.Fatal("System error: %v", err)
|
||||
}
|
||||
|
||||
|
@ -8,13 +8,12 @@ import (
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
models.MainTest(m, filepath.Join("..", "..", ".."))
|
||||
db.MainTest(m, filepath.Join("..", "..", ".."))
|
||||
}
|
||||
|
||||
func testIndexer(name string, t *testing.T, indexer Indexer) {
|
||||
|
@ -11,7 +11,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
|
||||
@ -21,11 +21,11 @@ import (
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
models.MainTest(m, filepath.Join("..", "..", ".."))
|
||||
db.MainTest(m, filepath.Join("..", "..", ".."))
|
||||
}
|
||||
|
||||
func TestBleveSearchIssues(t *testing.T) {
|
||||
assert.NoError(t, models.PrepareTestDatabase())
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
setting.Cfg = ini.Empty()
|
||||
|
||||
tmpIndexerDir, err := ioutil.TempDir("", "issues-indexer")
|
||||
@ -74,7 +74,7 @@ func TestBleveSearchIssues(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDBSearchIssues(t *testing.T) {
|
||||
assert.NoError(t, models.PrepareTestDatabase())
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
|
||||
setting.Indexer.IssueType = "db"
|
||||
InitIssueIndexer(true)
|
||||
|
@ -6,6 +6,7 @@ package stats
|
||||
|
||||
import (
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/modules/graceful"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
)
|
||||
@ -39,7 +40,7 @@ func populateRepoIndexer() {
|
||||
|
||||
isShutdown := graceful.GetManager().IsShutdown()
|
||||
|
||||
exist, err := models.IsTableNotEmpty("repository")
|
||||
exist, err := db.IsTableNotEmpty("repository")
|
||||
if err != nil {
|
||||
log.Fatal("System error: %v", err)
|
||||
} else if !exist {
|
||||
@ -47,7 +48,7 @@ func populateRepoIndexer() {
|
||||
}
|
||||
|
||||
var maxRepoID int64
|
||||
if maxRepoID, err = models.GetMaxID("repository"); err != nil {
|
||||
if maxRepoID, err = db.GetMaxID("repository"); err != nil {
|
||||
log.Fatal("System error: %v", err)
|
||||
}
|
||||
|
||||
|
@ -10,6 +10,7 @@ import (
|
||||
"time"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
|
||||
"gopkg.in/ini.v1"
|
||||
@ -18,11 +19,11 @@ import (
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
models.MainTest(m, filepath.Join("..", "..", ".."))
|
||||
db.MainTest(m, filepath.Join("..", "..", ".."))
|
||||
}
|
||||
|
||||
func TestRepoStatsIndex(t *testing.T) {
|
||||
assert.NoError(t, models.PrepareTestDatabase())
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
setting.Cfg = ini.Empty()
|
||||
|
||||
setting.NewQueueService()
|
||||
|
@ -16,6 +16,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/log"
|
||||
"code.gitea.io/gitea/modules/migrations/base"
|
||||
@ -69,17 +70,17 @@ func NewGiteaLocalUploader(ctx context.Context, doer *models.User, repoOwner, re
|
||||
func (g *GiteaLocalUploader) MaxBatchInsertSize(tp string) int {
|
||||
switch tp {
|
||||
case "issue":
|
||||
return models.MaxBatchInsertSize(new(models.Issue))
|
||||
return db.MaxBatchInsertSize(new(models.Issue))
|
||||
case "comment":
|
||||
return models.MaxBatchInsertSize(new(models.Comment))
|
||||
return db.MaxBatchInsertSize(new(models.Comment))
|
||||
case "milestone":
|
||||
return models.MaxBatchInsertSize(new(models.Milestone))
|
||||
return db.MaxBatchInsertSize(new(models.Milestone))
|
||||
case "label":
|
||||
return models.MaxBatchInsertSize(new(models.Label))
|
||||
return db.MaxBatchInsertSize(new(models.Label))
|
||||
case "release":
|
||||
return models.MaxBatchInsertSize(new(models.Release))
|
||||
return db.MaxBatchInsertSize(new(models.Release))
|
||||
case "pullrequest":
|
||||
return models.MaxBatchInsertSize(new(models.PullRequest))
|
||||
return db.MaxBatchInsertSize(new(models.PullRequest))
|
||||
}
|
||||
return 10
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ import (
|
||||
"time"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/modules/graceful"
|
||||
"code.gitea.io/gitea/modules/migrations/base"
|
||||
"code.gitea.io/gitea/modules/structs"
|
||||
@ -23,9 +24,9 @@ func TestGiteaUploadRepo(t *testing.T) {
|
||||
// FIXME: Since no accesskey or user/password will trigger rate limit of github, just skip
|
||||
t.Skip()
|
||||
|
||||
models.PrepareTestEnv(t)
|
||||
db.PrepareTestEnv(t)
|
||||
|
||||
user := models.AssertExistsAndLoadBean(t, &models.User{ID: 1}).(*models.User)
|
||||
user := db.AssertExistsAndLoadBean(t, &models.User{ID: 1}).(*models.User)
|
||||
|
||||
var (
|
||||
downloader = NewGithubDownloaderV3(context.Background(), "https://github.com", "", "", "", "go-xorm", "builder")
|
||||
@ -50,7 +51,7 @@ func TestGiteaUploadRepo(t *testing.T) {
|
||||
}, nil)
|
||||
assert.NoError(t, err)
|
||||
|
||||
repo := models.AssertExistsAndLoadBean(t, &models.Repository{OwnerID: user.ID, Name: repoName}).(*models.Repository)
|
||||
repo := db.AssertExistsAndLoadBean(t, &models.Repository{OwnerID: user.ID, Name: repoName}).(*models.Repository)
|
||||
assert.True(t, repo.HasWiki())
|
||||
assert.EqualValues(t, models.RepositoryReady, repo.Status)
|
||||
|
||||
|
@ -10,14 +10,14 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/modules/migrations/base"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
models.MainTest(m, filepath.Join("..", ".."))
|
||||
db.MainTest(m, filepath.Join("..", ".."))
|
||||
}
|
||||
|
||||
func timePtr(t time.Time) *time.Time {
|
||||
|
@ -9,16 +9,17 @@ import (
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestMigrateWhiteBlocklist(t *testing.T) {
|
||||
assert.NoError(t, models.PrepareTestDatabase())
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
|
||||
adminUser := models.AssertExistsAndLoadBean(t, &models.User{Name: "user1"}).(*models.User)
|
||||
nonAdminUser := models.AssertExistsAndLoadBean(t, &models.User{Name: "user2"}).(*models.User)
|
||||
adminUser := db.AssertExistsAndLoadBean(t, &models.User{Name: "user1"}).(*models.User)
|
||||
nonAdminUser := db.AssertExistsAndLoadBean(t, &models.User{Name: "user2"}).(*models.User)
|
||||
|
||||
setting.Migrations.AllowedDomains = []string{"github.com"}
|
||||
assert.NoError(t, Init())
|
||||
|
@ -10,18 +10,19 @@ import (
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
models.MainTest(m, filepath.Join("..", "..", ".."))
|
||||
db.MainTest(m, filepath.Join("..", "..", ".."))
|
||||
}
|
||||
|
||||
func TestRenameRepoAction(t *testing.T) {
|
||||
assert.NoError(t, models.PrepareTestDatabase())
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
|
||||
user := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
|
||||
repo := models.AssertExistsAndLoadBean(t, &models.Repository{OwnerID: user.ID}).(*models.Repository)
|
||||
user := db.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
|
||||
repo := db.AssertExistsAndLoadBean(t, &models.Repository{OwnerID: user.ID}).(*models.Repository)
|
||||
repo.Owner = user
|
||||
|
||||
oldRepoName := repo.Name
|
||||
@ -38,10 +39,10 @@ func TestRenameRepoAction(t *testing.T) {
|
||||
IsPrivate: repo.IsPrivate,
|
||||
Content: oldRepoName,
|
||||
}
|
||||
models.AssertNotExistsBean(t, actionBean)
|
||||
db.AssertNotExistsBean(t, actionBean)
|
||||
|
||||
NewNotifier().NotifyRenameRepository(user, repo, oldRepoName)
|
||||
|
||||
models.AssertExistsAndLoadBean(t, actionBean)
|
||||
db.AssertExistsAndLoadBean(t, actionBean)
|
||||
models.CheckConsistencyFor(t, &models.Action{})
|
||||
}
|
||||
|
@ -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{})
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ package repofiles
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/modules/test"
|
||||
|
||||
@ -15,7 +15,7 @@ import (
|
||||
)
|
||||
|
||||
func TestGetBlobBySHA(t *testing.T) {
|
||||
models.PrepareTestEnv(t)
|
||||
db.PrepareTestEnv(t)
|
||||
ctx := test.MockContext(t, "user2/repo1")
|
||||
test.LoadRepo(t, ctx, 1)
|
||||
test.LoadRepoCommit(t, ctx)
|
||||
|
@ -8,7 +8,7 @@ import (
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/modules/test"
|
||||
|
||||
@ -16,7 +16,7 @@ import (
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
models.MainTest(m, filepath.Join("..", ".."))
|
||||
db.MainTest(m, filepath.Join("..", ".."))
|
||||
}
|
||||
|
||||
func getExpectedReadmeContentsResponse() *api.ContentsResponse {
|
||||
@ -49,7 +49,7 @@ func getExpectedReadmeContentsResponse() *api.ContentsResponse {
|
||||
}
|
||||
|
||||
func TestGetContents(t *testing.T) {
|
||||
models.PrepareTestEnv(t)
|
||||
db.PrepareTestEnv(t)
|
||||
ctx := test.MockContext(t, "user2/repo1")
|
||||
ctx.SetParams(":id", "1")
|
||||
test.LoadRepo(t, ctx, 1)
|
||||
@ -77,7 +77,7 @@ func TestGetContents(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetContentsOrListForDir(t *testing.T) {
|
||||
models.PrepareTestEnv(t)
|
||||
db.PrepareTestEnv(t)
|
||||
ctx := test.MockContext(t, "user2/repo1")
|
||||
ctx.SetParams(":id", "1")
|
||||
test.LoadRepo(t, ctx, 1)
|
||||
@ -112,7 +112,7 @@ func TestGetContentsOrListForDir(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetContentsOrListForFile(t *testing.T) {
|
||||
models.PrepareTestEnv(t)
|
||||
db.PrepareTestEnv(t)
|
||||
ctx := test.MockContext(t, "user2/repo1")
|
||||
ctx.SetParams(":id", "1")
|
||||
test.LoadRepo(t, ctx, 1)
|
||||
@ -140,7 +140,7 @@ func TestGetContentsOrListForFile(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetContentsErrors(t *testing.T) {
|
||||
models.PrepareTestEnv(t)
|
||||
db.PrepareTestEnv(t)
|
||||
ctx := test.MockContext(t, "user2/repo1")
|
||||
ctx.SetParams(":id", "1")
|
||||
test.LoadRepo(t, ctx, 1)
|
||||
@ -171,7 +171,7 @@ func TestGetContentsErrors(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetContentsOrListErrors(t *testing.T) {
|
||||
models.PrepareTestEnv(t)
|
||||
db.PrepareTestEnv(t)
|
||||
ctx := test.MockContext(t, "user2/repo1")
|
||||
ctx.SetParams(":id", "1")
|
||||
test.LoadRepo(t, ctx, 1)
|
||||
@ -202,7 +202,7 @@ func TestGetContentsOrListErrors(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetContentsOrListOfEmptyRepos(t *testing.T) {
|
||||
models.PrepareTestEnv(t)
|
||||
db.PrepareTestEnv(t)
|
||||
ctx := test.MockContext(t, "user2/repo15")
|
||||
ctx.SetParams(":id", "15")
|
||||
test.LoadRepo(t, ctx, 15)
|
||||
|
@ -8,6 +8,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/modules/test"
|
||||
"code.gitea.io/gitea/services/gitdiff"
|
||||
|
||||
@ -15,7 +16,7 @@ import (
|
||||
)
|
||||
|
||||
func TestGetDiffPreview(t *testing.T) {
|
||||
models.PrepareTestEnv(t)
|
||||
db.PrepareTestEnv(t)
|
||||
ctx := test.MockContext(t, "user2/repo1")
|
||||
ctx.SetParams(":id", "1")
|
||||
test.LoadRepo(t, ctx, 1)
|
||||
@ -128,7 +129,7 @@ func TestGetDiffPreview(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetDiffPreviewErrors(t *testing.T) {
|
||||
models.PrepareTestEnv(t)
|
||||
db.PrepareTestEnv(t)
|
||||
ctx := test.MockContext(t, "user2/repo1")
|
||||
ctx.SetParams(":id", "1")
|
||||
test.LoadRepo(t, ctx, 1)
|
||||
|
@ -7,7 +7,7 @@ package repofiles
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
@ -81,7 +81,7 @@ func getExpectedFileResponse() *api.FileResponse {
|
||||
}
|
||||
|
||||
func TestGetFileResponseFromCommit(t *testing.T) {
|
||||
models.PrepareTestEnv(t)
|
||||
db.PrepareTestEnv(t)
|
||||
ctx := test.MockContext(t, "user2/repo1")
|
||||
ctx.SetParams(":id", "1")
|
||||
test.LoadRepo(t, ctx, 1)
|
||||
|
@ -7,7 +7,7 @@ package repofiles
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/modules/test"
|
||||
|
||||
@ -15,7 +15,7 @@ import (
|
||||
)
|
||||
|
||||
func TestGetTreeBySHA(t *testing.T) {
|
||||
models.PrepareTestEnv(t)
|
||||
db.PrepareTestEnv(t)
|
||||
ctx := test.MockContext(t, "user2/repo1")
|
||||
test.LoadRepo(t, ctx, 1)
|
||||
test.LoadRepoCommit(t, ctx)
|
||||
|
@ -11,6 +11,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/setting"
|
||||
@ -46,7 +47,7 @@ func AdoptRepository(doer, u *models.User, opts models.CreateRepoOptions) (*mode
|
||||
IsEmpty: !opts.AutoInit,
|
||||
}
|
||||
|
||||
if err := models.WithTx(func(ctx models.DBContext) error {
|
||||
if err := db.WithTx(func(ctx *db.Context) error {
|
||||
repoPath := models.RepoPath(u.Name, repo.Name)
|
||||
isExist, err := util.IsExist(repoPath)
|
||||
if err != nil {
|
||||
|
@ -11,6 +11,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/log"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
@ -22,8 +23,8 @@ import (
|
||||
func GitFsck(ctx context.Context, timeout time.Duration, args []string) error {
|
||||
log.Trace("Doing: GitFsck")
|
||||
|
||||
if err := models.Iterate(
|
||||
models.DefaultDBContext(),
|
||||
if err := db.Iterate(
|
||||
db.DefaultContext(),
|
||||
new(models.Repository),
|
||||
builder.Expr("id>0 AND is_fsck_enabled=?", true),
|
||||
func(idx int, bean interface{}) error {
|
||||
@ -57,8 +58,8 @@ func GitGcRepos(ctx context.Context, timeout time.Duration, args ...string) erro
|
||||
log.Trace("Doing: GitGcRepos")
|
||||
args = append([]string{"gc"}, args...)
|
||||
|
||||
if err := models.Iterate(
|
||||
models.DefaultDBContext(),
|
||||
if err := db.Iterate(
|
||||
db.DefaultContext(),
|
||||
new(models.Repository),
|
||||
builder.Gt{"id": 0},
|
||||
func(idx int, bean interface{}) error {
|
||||
@ -93,7 +94,7 @@ func GitGcRepos(ctx context.Context, timeout time.Duration, args ...string) erro
|
||||
}
|
||||
|
||||
// Now update the size of the repository
|
||||
if err := repo.UpdateSize(models.DefaultDBContext()); err != nil {
|
||||
if err := repo.UpdateSize(db.DefaultContext()); err != nil {
|
||||
log.Error("Updating size as part of garbage collection failed for %v. Stdout: %s\nError: %v", repo, stdout, err)
|
||||
desc := fmt.Sprintf("Updating size as part of garbage collection failed for %s. Stdout: %s\nError: %v", repo.RepoPath(), stdout, err)
|
||||
if err = models.CreateRepositoryNotice(desc); err != nil {
|
||||
@ -114,8 +115,8 @@ func GitGcRepos(ctx context.Context, timeout time.Duration, args ...string) erro
|
||||
|
||||
func gatherMissingRepoRecords(ctx context.Context) ([]*models.Repository, error) {
|
||||
repos := make([]*models.Repository, 0, 10)
|
||||
if err := models.Iterate(
|
||||
models.DefaultDBContext(),
|
||||
if err := db.Iterate(
|
||||
db.DefaultContext(),
|
||||
new(models.Repository),
|
||||
builder.Gt{"id": 0},
|
||||
func(idx int, bean interface{}) error {
|
||||
|
@ -11,12 +11,13 @@ import (
|
||||
"time"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestPushCommits_ToAPIPayloadCommits(t *testing.T) {
|
||||
assert.NoError(t, models.PrepareTestDatabase())
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
|
||||
pushCommits := NewPushCommits()
|
||||
pushCommits.Commits = []*PushCommit{
|
||||
@ -47,7 +48,7 @@ func TestPushCommits_ToAPIPayloadCommits(t *testing.T) {
|
||||
}
|
||||
pushCommits.HeadCommit = &PushCommit{Sha1: "69554a6"}
|
||||
|
||||
repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 16}).(*models.Repository)
|
||||
repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 16}).(*models.Repository)
|
||||
payloadCommits, headCommit, err := pushCommits.ToAPIPayloadCommits(repo.RepoPath(), "/user2/repo16")
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, payloadCommits, 3)
|
||||
@ -99,7 +100,7 @@ func TestPushCommits_ToAPIPayloadCommits(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestPushCommits_AvatarLink(t *testing.T) {
|
||||
assert.NoError(t, models.PrepareTestDatabase())
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
|
||||
pushCommits := NewPushCommits()
|
||||
pushCommits.Commits = []*PushCommit{
|
||||
|
@ -9,6 +9,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/setting"
|
||||
@ -54,7 +55,7 @@ func CreateRepository(doer, u *models.User, opts models.CreateRepoOptions) (*mod
|
||||
|
||||
var rollbackRepo *models.Repository
|
||||
|
||||
if err := models.WithTx(func(ctx models.DBContext) error {
|
||||
if err := db.WithTx(func(ctx *db.Context) error {
|
||||
if err := models.CreateRepository(ctx, doer, u, repo, false); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -9,16 +9,17 @@ import (
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/modules/structs"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestIncludesAllRepositoriesTeams(t *testing.T) {
|
||||
assert.NoError(t, models.PrepareTestDatabase())
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
|
||||
testTeamRepositories := func(teamID int64, repoIds []int64) {
|
||||
team := models.AssertExistsAndLoadBean(t, &models.Team{ID: teamID}).(*models.Team)
|
||||
team := db.AssertExistsAndLoadBean(t, &models.Team{ID: teamID}).(*models.Team)
|
||||
assert.NoError(t, team.GetRepositories(&models.SearchTeamOptions{}), "%s: GetRepositories", team.Name)
|
||||
assert.Len(t, team.Repos, team.NumRepos, "%s: len repo", team.Name)
|
||||
assert.Len(t, team.Repos, len(repoIds), "%s: repo count", team.Name)
|
||||
|
@ -10,6 +10,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/log"
|
||||
"code.gitea.io/gitea/modules/structs"
|
||||
@ -78,7 +79,7 @@ func ForkRepository(doer, owner *models.User, opts models.ForkRepoOptions) (_ *m
|
||||
panic(panicErr)
|
||||
}()
|
||||
|
||||
err = models.WithTx(func(ctx models.DBContext) error {
|
||||
err = db.WithTx(func(ctx *db.Context) error {
|
||||
if err = models.CreateRepository(ctx, doer, owner, repo, false); err != nil {
|
||||
return err
|
||||
}
|
||||
@ -122,7 +123,7 @@ func ForkRepository(doer, owner *models.User, opts models.ForkRepoOptions) (_ *m
|
||||
}
|
||||
|
||||
// even if below operations failed, it could be ignored. And they will be retried
|
||||
ctx := models.DefaultDBContext()
|
||||
ctx := db.DefaultContext()
|
||||
if err := repo.UpdateSize(ctx); err != nil {
|
||||
log.Error("Failed to update size for repository: %v", err)
|
||||
}
|
||||
@ -135,7 +136,7 @@ func ForkRepository(doer, owner *models.User, opts models.ForkRepoOptions) (_ *m
|
||||
|
||||
// ConvertForkToNormalRepository convert the provided repo from a forked repo to normal repo
|
||||
func ConvertForkToNormalRepository(repo *models.Repository) error {
|
||||
err := models.WithTx(func(ctx models.DBContext) error {
|
||||
err := db.WithTx(func(ctx *db.Context) error {
|
||||
repo, err := models.GetRepositoryByIDCtx(ctx, repo.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -8,15 +8,16 @@ import (
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestForkRepository(t *testing.T) {
|
||||
assert.NoError(t, models.PrepareTestDatabase())
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
|
||||
// user 13 has already forked repo10
|
||||
user := models.AssertExistsAndLoadBean(t, &models.User{ID: 13}).(*models.User)
|
||||
repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 10}).(*models.Repository)
|
||||
user := db.AssertExistsAndLoadBean(t, &models.User{ID: 13}).(*models.User)
|
||||
repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 10}).(*models.Repository)
|
||||
|
||||
fork, err := ForkRepository(user, user, models.ForkRepoOptions{
|
||||
BaseRepo: repo,
|
||||
|
@ -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/log"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
@ -185,7 +186,7 @@ func generateRepoCommit(repo, templateRepo, generateRepo *models.Repository, tmp
|
||||
return initRepoCommit(tmpDir, repo, repo.Owner, templateRepo.DefaultBranch)
|
||||
}
|
||||
|
||||
func generateGitContent(ctx models.DBContext, repo, templateRepo, generateRepo *models.Repository) (err error) {
|
||||
func generateGitContent(ctx *db.Context, repo, templateRepo, generateRepo *models.Repository) (err error) {
|
||||
tmpDir, err := ioutil.TempDir(os.TempDir(), "gitea-"+repo.Name)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed to create temp dir for repository %s: %v", repo.RepoPath(), err)
|
||||
@ -223,7 +224,7 @@ func generateGitContent(ctx models.DBContext, repo, templateRepo, generateRepo *
|
||||
}
|
||||
|
||||
// GenerateGitContent generates git content from a template repository
|
||||
func GenerateGitContent(ctx models.DBContext, templateRepo, generateRepo *models.Repository) error {
|
||||
func GenerateGitContent(ctx *db.Context, templateRepo, generateRepo *models.Repository) error {
|
||||
if err := generateGitContent(ctx, generateRepo, templateRepo, generateRepo); err != nil {
|
||||
return err
|
||||
}
|
||||
@ -239,7 +240,7 @@ func GenerateGitContent(ctx models.DBContext, templateRepo, generateRepo *models
|
||||
}
|
||||
|
||||
// GenerateRepository generates a repository from a template
|
||||
func GenerateRepository(ctx models.DBContext, doer, owner *models.User, templateRepo *models.Repository, opts models.GenerateRepoOptions) (_ *models.Repository, err error) {
|
||||
func GenerateRepository(ctx *db.Context, doer, owner *models.User, templateRepo *models.Repository, opts models.GenerateRepoOptions) (_ *models.Repository, err error) {
|
||||
generateRepo := &models.Repository{
|
||||
OwnerID: owner.ID,
|
||||
Owner: owner,
|
||||
|
@ -12,6 +12,7 @@ import (
|
||||
"path/filepath"
|
||||
|
||||
"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/setting"
|
||||
@ -220,8 +221,8 @@ func CheckDelegateHooks(repoPath string) ([]string, error) {
|
||||
func SyncRepositoryHooks(ctx context.Context) error {
|
||||
log.Trace("Doing: SyncRepositoryHooks")
|
||||
|
||||
if err := models.Iterate(
|
||||
models.DefaultDBContext(),
|
||||
if err := db.Iterate(
|
||||
db.DefaultContext(),
|
||||
new(models.Repository),
|
||||
builder.Gt{"id": 0},
|
||||
func(idx int, bean interface{}) error {
|
||||
|
@ -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/log"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
@ -22,7 +23,7 @@ import (
|
||||
"github.com/unknwon/com"
|
||||
)
|
||||
|
||||
func prepareRepoCommit(ctx models.DBContext, repo *models.Repository, tmpDir, repoPath string, opts models.CreateRepoOptions) error {
|
||||
func prepareRepoCommit(ctx *db.Context, repo *models.Repository, tmpDir, repoPath string, opts models.CreateRepoOptions) error {
|
||||
commitTimeStr := time.Now().Format(time.RFC3339)
|
||||
authorSig := repo.Owner.NewGitSig()
|
||||
|
||||
@ -196,7 +197,7 @@ func checkInitRepository(owner, name string) (err error) {
|
||||
return nil
|
||||
}
|
||||
|
||||
func adoptRepository(ctx models.DBContext, repoPath string, u *models.User, repo *models.Repository, opts models.CreateRepoOptions) (err error) {
|
||||
func adoptRepository(ctx *db.Context, repoPath string, u *models.User, repo *models.Repository, opts models.CreateRepoOptions) (err error) {
|
||||
isExist, err := util.IsExist(repoPath)
|
||||
if err != nil {
|
||||
log.Error("Unable to check if %s exists. Error: %v", repoPath, err)
|
||||
@ -283,7 +284,7 @@ func adoptRepository(ctx models.DBContext, repoPath string, u *models.User, repo
|
||||
}
|
||||
|
||||
// InitRepository initializes README and .gitignore if needed.
|
||||
func initRepository(ctx models.DBContext, repoPath string, u *models.User, repo *models.Repository, opts models.CreateRepoOptions) (err error) {
|
||||
func initRepository(ctx *db.Context, repoPath string, u *models.User, repo *models.Repository, opts models.CreateRepoOptions) (err error) {
|
||||
if err = checkInitRepository(repo.OwnerName, repo.Name); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -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("..", ".."))
|
||||
}
|
||||
|
@ -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/lfs"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
@ -132,7 +133,7 @@ func MigrateRepositoryGitData(ctx context.Context, u *models.User, repo *models.
|
||||
}
|
||||
}
|
||||
|
||||
if err = repo.UpdateSize(models.DefaultDBContext()); err != nil {
|
||||
if err = repo.UpdateSize(db.DefaultContext()); err != nil {
|
||||
log.Error("Failed to update size for repository: %v", err)
|
||||
}
|
||||
|
||||
|
@ -10,13 +10,14 @@ import (
|
||||
"time"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
"code.gitea.io/gitea/modules/timeutil"
|
||||
)
|
||||
|
||||
// PushUpdateAddDeleteTags updates a number of added and delete tags
|
||||
func PushUpdateAddDeleteTags(repo *models.Repository, gitRepo *git.Repository, addTags, delTags []string) error {
|
||||
return models.WithTx(func(ctx models.DBContext) error {
|
||||
return db.WithTx(func(ctx *db.Context) error {
|
||||
if err := models.PushUpdateDeleteTagsContext(ctx, repo, delTags); err != nil {
|
||||
return err
|
||||
}
|
||||
@ -25,7 +26,7 @@ func PushUpdateAddDeleteTags(repo *models.Repository, gitRepo *git.Repository, a
|
||||
}
|
||||
|
||||
// pushUpdateAddTags updates a number of add tags
|
||||
func pushUpdateAddTags(ctx models.DBContext, repo *models.Repository, gitRepo *git.Repository, tags []string) error {
|
||||
func pushUpdateAddTags(ctx *db.Context, repo *models.Repository, gitRepo *git.Repository, tags []string) error {
|
||||
if len(tags) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
"code.gitea.io/gitea/modules/web/middleware"
|
||||
@ -52,7 +53,7 @@ func MockContext(t *testing.T, path string) *context.Context {
|
||||
// LoadRepo load a repo into a test context.
|
||||
func LoadRepo(t *testing.T, ctx *context.Context, repoID int64) {
|
||||
ctx.Repo = &context.Repository{}
|
||||
ctx.Repo.Repository = models.AssertExistsAndLoadBean(t, &models.Repository{ID: repoID}).(*models.Repository)
|
||||
ctx.Repo.Repository = db.AssertExistsAndLoadBean(t, &models.Repository{ID: repoID}).(*models.Repository)
|
||||
var err error
|
||||
ctx.Repo.Owner, err = models.GetUserByID(ctx.Repo.Repository.OwnerID)
|
||||
assert.NoError(t, err)
|
||||
@ -77,7 +78,7 @@ func LoadRepoCommit(t *testing.T, ctx *context.Context) {
|
||||
|
||||
// LoadUser load a user into a test context.
|
||||
func LoadUser(t *testing.T, ctx *context.Context, userID int64) {
|
||||
ctx.User = models.AssertExistsAndLoadBean(t, &models.User{ID: userID}).(*models.User)
|
||||
ctx.User = db.AssertExistsAndLoadBean(t, &models.User{ID: userID}).(*models.User)
|
||||
}
|
||||
|
||||
// LoadGitRepo load a git repo into a test context. Requires that ctx.Repo has
|
||||
|
Reference in New Issue
Block a user