Move some files into models' sub packages (#20262)
* Move some files into models' sub packages * Move functions * merge main branch * Fix check * fix check * Fix some tests * Fix lint * Fix lint * Revert lint changes * Fix error comments * Fix lint Co-authored-by: 6543 <6543@obermui.de>
This commit is contained in:
@@ -9,7 +9,7 @@ import (
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
activities_model "code.gitea.io/gitea/models/activities"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
@@ -23,7 +23,7 @@ func TestAPINotification(t *testing.T) {
|
||||
|
||||
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
||||
repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
|
||||
thread5 := unittest.AssertExistsAndLoadBean(t, &models.Notification{ID: 5})
|
||||
thread5 := unittest.AssertExistsAndLoadBean(t, &activities_model.Notification{ID: 5})
|
||||
assert.NoError(t, thread5.LoadAttributes())
|
||||
session := loginUser(t, user2.Name)
|
||||
token := getTokenForLoggedInUser(t, session)
|
||||
@@ -126,9 +126,9 @@ func TestAPINotification(t *testing.T) {
|
||||
req = NewRequest(t, "PATCH", fmt.Sprintf("/api/v1/notifications/threads/%d?token=%s", thread5.ID, token))
|
||||
session.MakeRequest(t, req, http.StatusResetContent)
|
||||
|
||||
assert.Equal(t, models.NotificationStatusUnread, thread5.Status)
|
||||
thread5 = unittest.AssertExistsAndLoadBean(t, &models.Notification{ID: 5})
|
||||
assert.Equal(t, models.NotificationStatusRead, thread5.Status)
|
||||
assert.Equal(t, activities_model.NotificationStatusUnread, thread5.Status)
|
||||
thread5 = unittest.AssertExistsAndLoadBean(t, &activities_model.Notification{ID: 5})
|
||||
assert.Equal(t, activities_model.NotificationStatusRead, thread5.Status)
|
||||
|
||||
// -- check notifications --
|
||||
req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/notifications/new?token=%s", token))
|
||||
@@ -141,7 +141,7 @@ func TestAPINotificationPUT(t *testing.T) {
|
||||
defer prepareTestEnv(t)()
|
||||
|
||||
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
||||
thread5 := unittest.AssertExistsAndLoadBean(t, &models.Notification{ID: 5})
|
||||
thread5 := unittest.AssertExistsAndLoadBean(t, &activities_model.Notification{ID: 5})
|
||||
assert.NoError(t, thread5.LoadAttributes())
|
||||
session := loginUser(t, user2.Name)
|
||||
token := getTokenForLoggedInUser(t, session)
|
||||
|
||||
@@ -10,7 +10,6 @@ import (
|
||||
"net/url"
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
@@ -84,7 +83,7 @@ func createNewReleaseUsingAPI(t *testing.T, session *TestSession, token string,
|
||||
|
||||
var newRelease api.Release
|
||||
DecodeJSON(t, resp, &newRelease)
|
||||
rel := &models.Release{
|
||||
rel := &repo_model.Release{
|
||||
ID: newRelease.ID,
|
||||
TagName: newRelease.TagName,
|
||||
Title: newRelease.Title,
|
||||
@@ -138,7 +137,7 @@ func TestAPICreateAndUpdateRelease(t *testing.T) {
|
||||
resp = session.MakeRequest(t, req, http.StatusOK)
|
||||
|
||||
DecodeJSON(t, resp, &newRelease)
|
||||
rel := &models.Release{
|
||||
rel := &repo_model.Release{
|
||||
ID: newRelease.ID,
|
||||
TagName: newRelease.TagName,
|
||||
Title: newRelease.Title,
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
auth_model "code.gitea.io/gitea/models/auth"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
@@ -27,7 +27,7 @@ func TestAPICreateAndDeleteToken(t *testing.T) {
|
||||
|
||||
var newAccessToken api.AccessToken
|
||||
DecodeJSON(t, resp, &newAccessToken)
|
||||
unittest.AssertExistsAndLoadBean(t, &models.AccessToken{
|
||||
unittest.AssertExistsAndLoadBean(t, &auth_model.AccessToken{
|
||||
ID: newAccessToken.ID,
|
||||
Name: newAccessToken.Name,
|
||||
Token: newAccessToken.Token,
|
||||
@@ -38,7 +38,7 @@ func TestAPICreateAndDeleteToken(t *testing.T) {
|
||||
req = AddBasicAuthHeader(req, user.Name)
|
||||
MakeRequest(t, req, http.StatusNoContent)
|
||||
|
||||
unittest.AssertNotExistsBean(t, &models.AccessToken{ID: newAccessToken.ID})
|
||||
unittest.AssertNotExistsBean(t, &auth_model.AccessToken{ID: newAccessToken.ID})
|
||||
|
||||
req = NewRequestWithJSON(t, "POST", "/api/v1/users/user1/tokens", map[string]string{
|
||||
"name": "test-key-2",
|
||||
@@ -51,7 +51,7 @@ func TestAPICreateAndDeleteToken(t *testing.T) {
|
||||
req = AddBasicAuthHeader(req, user.Name)
|
||||
MakeRequest(t, req, http.StatusNoContent)
|
||||
|
||||
unittest.AssertNotExistsBean(t, &models.AccessToken{ID: newAccessToken.ID})
|
||||
unittest.AssertNotExistsBean(t, &auth_model.AccessToken{ID: newAccessToken.ID})
|
||||
}
|
||||
|
||||
// TestAPIDeleteMissingToken ensures that error is thrown when token not found
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
activities_model "code.gitea.io/gitea/models/activities"
|
||||
"code.gitea.io/gitea/modules/timeutil"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -29,10 +29,10 @@ func TestUserHeatmap(t *testing.T) {
|
||||
urlStr := fmt.Sprintf("/api/v1/users/%s/heatmap?token=%s", normalUsername, token)
|
||||
req := NewRequest(t, "GET", urlStr)
|
||||
resp := MakeRequest(t, req, http.StatusOK)
|
||||
var heatmap []*models.UserHeatmapData
|
||||
var heatmap []*activities_model.UserHeatmapData
|
||||
DecodeJSON(t, resp, &heatmap)
|
||||
var dummyheatmap []*models.UserHeatmapData
|
||||
dummyheatmap = append(dummyheatmap, &models.UserHeatmapData{Timestamp: 1603227600, Contributions: 1})
|
||||
var dummyheatmap []*activities_model.UserHeatmapData
|
||||
dummyheatmap = append(dummyheatmap, &activities_model.UserHeatmapData{Timestamp: 1603227600, Contributions: 1})
|
||||
|
||||
assert.Equal(t, dummyheatmap, heatmap)
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
activities_model "code.gitea.io/gitea/models/activities"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
@@ -42,7 +42,7 @@ func TestEventSourceManagerRun(t *testing.T) {
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
data, ok := event.Data.(models.UserIDCount)
|
||||
data, ok := event.Data.(activities_model.UserIDCount)
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
@@ -55,7 +55,7 @@ func TestEventSourceManagerRun(t *testing.T) {
|
||||
|
||||
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
||||
repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
|
||||
thread5 := unittest.AssertExistsAndLoadBean(t, &models.Notification{ID: 5})
|
||||
thread5 := unittest.AssertExistsAndLoadBean(t, &activities_model.Notification{ID: 5})
|
||||
assert.NoError(t, thread5.LoadAttributes())
|
||||
session := loginUser(t, user2.Name)
|
||||
token := getTokenForLoggedInUser(t, session)
|
||||
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
@@ -38,7 +37,7 @@ func TestMirrorPull(t *testing.T) {
|
||||
Releases: false,
|
||||
}
|
||||
|
||||
mirrorRepo, err := repository.CreateRepository(user, user, models.CreateRepoOptions{
|
||||
mirrorRepo, err := repository.CreateRepository(user, user, repository.CreateRepoOptions{
|
||||
Name: opts.RepoName,
|
||||
Description: opts.Description,
|
||||
IsPrivate: opts.Private,
|
||||
@@ -57,11 +56,11 @@ func TestMirrorPull(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
defer gitRepo.Close()
|
||||
|
||||
findOptions := models.FindReleasesOptions{IncludeDrafts: true, IncludeTags: true}
|
||||
initCount, err := models.GetReleaseCountByRepoID(mirror.ID, findOptions)
|
||||
findOptions := repo_model.FindReleasesOptions{IncludeDrafts: true, IncludeTags: true}
|
||||
initCount, err := repo_model.GetReleaseCountByRepoID(mirror.ID, findOptions)
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.NoError(t, release_service.CreateRelease(gitRepo, &models.Release{
|
||||
assert.NoError(t, release_service.CreateRelease(gitRepo, &repo_model.Release{
|
||||
RepoID: repo.ID,
|
||||
Repo: repo,
|
||||
PublisherID: user.ID,
|
||||
@@ -81,18 +80,18 @@ func TestMirrorPull(t *testing.T) {
|
||||
ok := mirror_service.SyncPullMirror(ctx, mirror.ID)
|
||||
assert.True(t, ok)
|
||||
|
||||
count, err := models.GetReleaseCountByRepoID(mirror.ID, findOptions)
|
||||
count, err := repo_model.GetReleaseCountByRepoID(mirror.ID, findOptions)
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, initCount+1, count)
|
||||
|
||||
release, err := models.GetRelease(repo.ID, "v0.2")
|
||||
release, err := repo_model.GetRelease(repo.ID, "v0.2")
|
||||
assert.NoError(t, err)
|
||||
assert.NoError(t, release_service.DeleteReleaseByID(ctx, release.ID, user, true))
|
||||
|
||||
ok = mirror_service.SyncPullMirror(ctx, mirror.ID)
|
||||
assert.True(t, ok)
|
||||
|
||||
count, err = models.GetReleaseCountByRepoID(mirror.ID, findOptions)
|
||||
count, err = repo_model.GetReleaseCountByRepoID(mirror.ID, findOptions)
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, initCount, count)
|
||||
}
|
||||
|
||||
@@ -12,7 +12,6 @@ import (
|
||||
"strconv"
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
@@ -39,7 +38,7 @@ func testMirrorPush(t *testing.T, u *url.URL) {
|
||||
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
||||
srcRepo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
|
||||
|
||||
mirrorRepo, err := repository.CreateRepository(user, user, models.CreateRepoOptions{
|
||||
mirrorRepo, err := repository.CreateRepository(user, user, repository.CreateRepoOptions{
|
||||
Name: "test-push-mirror",
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
activities_model "code.gitea.io/gitea/models/activities"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
@@ -117,7 +117,7 @@ func testPrivateActivityHelperHasHeatmapContentFromPublic(t *testing.T) bool {
|
||||
req := NewRequestf(t, "GET", "/api/v1/users/%s/heatmap", privateActivityTestUser)
|
||||
resp := MakeRequest(t, req, http.StatusOK)
|
||||
|
||||
var items []*models.UserHeatmapData
|
||||
var items []*activities_model.UserHeatmapData
|
||||
DecodeJSON(t, resp, &items)
|
||||
|
||||
return len(items) != 0
|
||||
@@ -129,7 +129,7 @@ func testPrivateActivityHelperHasHeatmapContentFromSession(t *testing.T, session
|
||||
req := NewRequestf(t, "GET", "/api/v1/users/%s/heatmap?token=%s", privateActivityTestUser, token)
|
||||
resp := session.MakeRequest(t, req, http.StatusOK)
|
||||
|
||||
var items []*models.UserHeatmapData
|
||||
var items []*activities_model.UserHeatmapData
|
||||
DecodeJSON(t, resp, &items)
|
||||
|
||||
return len(items) != 0
|
||||
|
||||
@@ -25,6 +25,7 @@ import (
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/models/webhook"
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
repo_module "code.gitea.io/gitea/modules/repository"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/modules/test"
|
||||
"code.gitea.io/gitea/modules/translation"
|
||||
@@ -355,7 +356,7 @@ func TestConflictChecking(t *testing.T) {
|
||||
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
||||
|
||||
// Create new clean repo to test conflict checking.
|
||||
baseRepo, err := repo_service.CreateRepository(user, user, models.CreateRepoOptions{
|
||||
baseRepo, err := repo_service.CreateRepository(user, user, repo_module.CreateRepoOptions{
|
||||
Name: "conflict-checking",
|
||||
Description: "Tempo repo",
|
||||
AutoInit: true,
|
||||
|
||||
@@ -10,12 +10,12 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"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"
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
repo_module "code.gitea.io/gitea/modules/repository"
|
||||
pull_service "code.gitea.io/gitea/services/pull"
|
||||
repo_service "code.gitea.io/gitea/services/repository"
|
||||
files_service "code.gitea.io/gitea/services/repository/files"
|
||||
@@ -80,7 +80,7 @@ func TestAPIPullUpdateByRebase(t *testing.T) {
|
||||
}
|
||||
|
||||
func createOutdatedPR(t *testing.T, actor, forkOrg *user_model.User) *issues_model.PullRequest {
|
||||
baseRepo, err := repo_service.CreateRepository(actor, actor, models.CreateRepoOptions{
|
||||
baseRepo, err := repo_service.CreateRepository(actor, actor, repo_module.CreateRepoOptions{
|
||||
Name: "repo-pr-update",
|
||||
Description: "repo-tmp-pr-update description",
|
||||
AutoInit: true,
|
||||
|
||||
@@ -77,14 +77,14 @@ func TestCreateNewTagProtected(t *testing.T) {
|
||||
})
|
||||
|
||||
// Cleanup
|
||||
releases, err := models.GetReleasesByRepoID(repo.ID, models.FindReleasesOptions{
|
||||
releases, err := repo_model.GetReleasesByRepoID(repo.ID, repo_model.FindReleasesOptions{
|
||||
IncludeTags: true,
|
||||
TagNames: []string{"v-1", "v-1.1"},
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
|
||||
for _, release := range releases {
|
||||
err = models.DeleteReleaseByID(release.ID)
|
||||
err = repo_model.DeleteReleaseByID(release.ID)
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user