Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move some files into models' sub packages #20262

Merged
merged 25 commits into from Aug 25, 2022
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 17 additions & 18 deletions cmd/admin.go
Expand Up @@ -13,9 +13,8 @@ import (
"strings"
"text/tabwriter"

"code.gitea.io/gitea/models"
asymkey_model "code.gitea.io/gitea/models/asymkey"
"code.gitea.io/gitea/models/auth"
auth_model "code.gitea.io/gitea/models/auth"
"code.gitea.io/gitea/models/db"
repo_model "code.gitea.io/gitea/models/repo"
user_model "code.gitea.io/gitea/models/user"
Expand Down Expand Up @@ -593,12 +592,12 @@ func runCreateUser(c *cli.Context) error {
}

if c.Bool("access-token") {
t := &models.AccessToken{
t := &auth_model.AccessToken{
Name: "gitea-admin",
UID: u.ID,
}

if err := models.NewAccessToken(t); err != nil {
if err := auth_model.NewAccessToken(t); err != nil {
return err
}

Expand Down Expand Up @@ -700,12 +699,12 @@ func runGenerateAccessToken(c *cli.Context) error {
return err
}

t := &models.AccessToken{
t := &auth_model.AccessToken{
Name: c.String("token-name"),
UID: user.ID,
}

if err := models.NewAccessToken(t); err != nil {
if err := auth_model.NewAccessToken(t); err != nil {
return err
}

Expand Down Expand Up @@ -779,9 +778,9 @@ func runRepoSyncReleases(_ *cli.Context) error {
}

func getReleaseCount(id int64) (int64, error) {
return models.GetReleaseCountByRepoID(
return repo_model.GetReleaseCountByRepoID(
id,
models.FindReleasesOptions{
repo_model.FindReleasesOptions{
IncludeTags: true,
},
)
Expand Down Expand Up @@ -844,8 +843,8 @@ func runAddOauth(c *cli.Context) error {
return err
}

return auth.CreateSource(&auth.Source{
Type: auth.OAuth2,
return auth_model.CreateSource(&auth_model.Source{
Type: auth_model.OAuth2,
Name: c.String("name"),
IsActive: true,
Cfg: parseOAuth2Config(c),
Expand All @@ -864,7 +863,7 @@ func runUpdateOauth(c *cli.Context) error {
return err
}

source, err := auth.GetSourceByID(c.Int64("id"))
source, err := auth_model.GetSourceByID(c.Int64("id"))
if err != nil {
return err
}
Expand Down Expand Up @@ -944,7 +943,7 @@ func runUpdateOauth(c *cli.Context) error {
oAuth2Config.CustomURLMapping = customURLMapping
source.Cfg = oAuth2Config

return auth.UpdateSource(source)
return auth_model.UpdateSource(source)
}

func parseSMTPConfig(c *cli.Context, conf *smtp.Source) error {
Expand Down Expand Up @@ -1015,8 +1014,8 @@ func runAddSMTP(c *cli.Context) error {
smtpConfig.Auth = "PLAIN"
}

return auth.CreateSource(&auth.Source{
Type: auth.SMTP,
return auth_model.CreateSource(&auth_model.Source{
Type: auth_model.SMTP,
Name: c.String("name"),
IsActive: active,
Cfg: &smtpConfig,
Expand All @@ -1035,7 +1034,7 @@ func runUpdateSMTP(c *cli.Context) error {
return err
}

source, err := auth.GetSourceByID(c.Int64("id"))
source, err := auth_model.GetSourceByID(c.Int64("id"))
if err != nil {
return err
}
Expand All @@ -1056,7 +1055,7 @@ func runUpdateSMTP(c *cli.Context) error {

source.Cfg = smtpConfig

return auth.UpdateSource(source)
return auth_model.UpdateSource(source)
}

func runListAuth(c *cli.Context) error {
Expand All @@ -1067,7 +1066,7 @@ func runListAuth(c *cli.Context) error {
return err
}

authSources, err := auth.Sources()
authSources, err := auth_model.Sources()
if err != nil {
return err
}
Expand Down Expand Up @@ -1105,7 +1104,7 @@ func runDeleteAuth(c *cli.Context) error {
return err
}

source, err := auth.GetSourceByID(c.Int64("id"))
source, err := auth_model.GetSourceByID(c.Int64("id"))
if err != nil {
return err
}
Expand Down
12 changes: 6 additions & 6 deletions integrations/api_notification_test.go
Expand Up @@ -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"
Expand All @@ -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)
Expand Down Expand Up @@ -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))
Expand All @@ -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)
Expand Down
5 changes: 2 additions & 3 deletions integrations/api_releases_test.go
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions integrations/api_token_test.go
Expand Up @@ -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"
Expand All @@ -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,
Expand All @@ -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",
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions integrations/api_user_heatmap_test.go
Expand Up @@ -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"
Expand All @@ -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)
}
6 changes: 3 additions & 3 deletions integrations/eventsource_test.go
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand All @@ -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)
Expand Down
15 changes: 7 additions & 8 deletions integrations/mirror_pull_test.go
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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)
}
3 changes: 1 addition & 2 deletions integrations/mirror_push_test.go
Expand Up @@ -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"
Expand All @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions integrations/privateactivity_test.go
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion integrations/pull_merge_test.go
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down