Skip to content

Commit 1d8543e

Browse files
lunny6543
andauthored
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 <[email protected]>
1 parent 4a4bfaf commit 1d8543e

File tree

154 files changed

+1763
-1738
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

154 files changed

+1763
-1738
lines changed

Diff for: cmd/admin.go

+17-18
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@ import (
1313
"strings"
1414
"text/tabwriter"
1515

16-
"code.gitea.io/gitea/models"
1716
asymkey_model "code.gitea.io/gitea/models/asymkey"
18-
"code.gitea.io/gitea/models/auth"
17+
auth_model "code.gitea.io/gitea/models/auth"
1918
"code.gitea.io/gitea/models/db"
2019
repo_model "code.gitea.io/gitea/models/repo"
2120
user_model "code.gitea.io/gitea/models/user"
@@ -593,12 +592,12 @@ func runCreateUser(c *cli.Context) error {
593592
}
594593

595594
if c.Bool("access-token") {
596-
t := &models.AccessToken{
595+
t := &auth_model.AccessToken{
597596
Name: "gitea-admin",
598597
UID: u.ID,
599598
}
600599

601-
if err := models.NewAccessToken(t); err != nil {
600+
if err := auth_model.NewAccessToken(t); err != nil {
602601
return err
603602
}
604603

@@ -700,12 +699,12 @@ func runGenerateAccessToken(c *cli.Context) error {
700699
return err
701700
}
702701

703-
t := &models.AccessToken{
702+
t := &auth_model.AccessToken{
704703
Name: c.String("token-name"),
705704
UID: user.ID,
706705
}
707706

708-
if err := models.NewAccessToken(t); err != nil {
707+
if err := auth_model.NewAccessToken(t); err != nil {
709708
return err
710709
}
711710

@@ -779,9 +778,9 @@ func runRepoSyncReleases(_ *cli.Context) error {
779778
}
780779

781780
func getReleaseCount(id int64) (int64, error) {
782-
return models.GetReleaseCountByRepoID(
781+
return repo_model.GetReleaseCountByRepoID(
783782
id,
784-
models.FindReleasesOptions{
783+
repo_model.FindReleasesOptions{
785784
IncludeTags: true,
786785
},
787786
)
@@ -844,8 +843,8 @@ func runAddOauth(c *cli.Context) error {
844843
return err
845844
}
846845

847-
return auth.CreateSource(&auth.Source{
848-
Type: auth.OAuth2,
846+
return auth_model.CreateSource(&auth_model.Source{
847+
Type: auth_model.OAuth2,
849848
Name: c.String("name"),
850849
IsActive: true,
851850
Cfg: parseOAuth2Config(c),
@@ -864,7 +863,7 @@ func runUpdateOauth(c *cli.Context) error {
864863
return err
865864
}
866865

867-
source, err := auth.GetSourceByID(c.Int64("id"))
866+
source, err := auth_model.GetSourceByID(c.Int64("id"))
868867
if err != nil {
869868
return err
870869
}
@@ -944,7 +943,7 @@ func runUpdateOauth(c *cli.Context) error {
944943
oAuth2Config.CustomURLMapping = customURLMapping
945944
source.Cfg = oAuth2Config
946945

947-
return auth.UpdateSource(source)
946+
return auth_model.UpdateSource(source)
948947
}
949948

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

1018-
return auth.CreateSource(&auth.Source{
1019-
Type: auth.SMTP,
1017+
return auth_model.CreateSource(&auth_model.Source{
1018+
Type: auth_model.SMTP,
10201019
Name: c.String("name"),
10211020
IsActive: active,
10221021
Cfg: &smtpConfig,
@@ -1035,7 +1034,7 @@ func runUpdateSMTP(c *cli.Context) error {
10351034
return err
10361035
}
10371036

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

10571056
source.Cfg = smtpConfig
10581057

1059-
return auth.UpdateSource(source)
1058+
return auth_model.UpdateSource(source)
10601059
}
10611060

10621061
func runListAuth(c *cli.Context) error {
@@ -1067,7 +1066,7 @@ func runListAuth(c *cli.Context) error {
10671066
return err
10681067
}
10691068

1070-
authSources, err := auth.Sources()
1069+
authSources, err := auth_model.Sources()
10711070
if err != nil {
10721071
return err
10731072
}
@@ -1105,7 +1104,7 @@ func runDeleteAuth(c *cli.Context) error {
11051104
return err
11061105
}
11071106

1108-
source, err := auth.GetSourceByID(c.Int64("id"))
1107+
source, err := auth_model.GetSourceByID(c.Int64("id"))
11091108
if err != nil {
11101109
return err
11111110
}

Diff for: integrations/api_notification_test.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"net/http"
1010
"testing"
1111

12-
"code.gitea.io/gitea/models"
12+
activities_model "code.gitea.io/gitea/models/activities"
1313
repo_model "code.gitea.io/gitea/models/repo"
1414
"code.gitea.io/gitea/models/unittest"
1515
user_model "code.gitea.io/gitea/models/user"
@@ -23,7 +23,7 @@ func TestAPINotification(t *testing.T) {
2323

2424
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
2525
repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
26-
thread5 := unittest.AssertExistsAndLoadBean(t, &models.Notification{ID: 5})
26+
thread5 := unittest.AssertExistsAndLoadBean(t, &activities_model.Notification{ID: 5})
2727
assert.NoError(t, thread5.LoadAttributes())
2828
session := loginUser(t, user2.Name)
2929
token := getTokenForLoggedInUser(t, session)
@@ -126,9 +126,9 @@ func TestAPINotification(t *testing.T) {
126126
req = NewRequest(t, "PATCH", fmt.Sprintf("/api/v1/notifications/threads/%d?token=%s", thread5.ID, token))
127127
session.MakeRequest(t, req, http.StatusResetContent)
128128

129-
assert.Equal(t, models.NotificationStatusUnread, thread5.Status)
130-
thread5 = unittest.AssertExistsAndLoadBean(t, &models.Notification{ID: 5})
131-
assert.Equal(t, models.NotificationStatusRead, thread5.Status)
129+
assert.Equal(t, activities_model.NotificationStatusUnread, thread5.Status)
130+
thread5 = unittest.AssertExistsAndLoadBean(t, &activities_model.Notification{ID: 5})
131+
assert.Equal(t, activities_model.NotificationStatusRead, thread5.Status)
132132

133133
// -- check notifications --
134134
req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/notifications/new?token=%s", token))
@@ -141,7 +141,7 @@ func TestAPINotificationPUT(t *testing.T) {
141141
defer prepareTestEnv(t)()
142142

143143
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
144-
thread5 := unittest.AssertExistsAndLoadBean(t, &models.Notification{ID: 5})
144+
thread5 := unittest.AssertExistsAndLoadBean(t, &activities_model.Notification{ID: 5})
145145
assert.NoError(t, thread5.LoadAttributes())
146146
session := loginUser(t, user2.Name)
147147
token := getTokenForLoggedInUser(t, session)

Diff for: integrations/api_releases_test.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"net/url"
1111
"testing"
1212

13-
"code.gitea.io/gitea/models"
1413
repo_model "code.gitea.io/gitea/models/repo"
1514
"code.gitea.io/gitea/models/unittest"
1615
user_model "code.gitea.io/gitea/models/user"
@@ -84,7 +83,7 @@ func createNewReleaseUsingAPI(t *testing.T, session *TestSession, token string,
8483

8584
var newRelease api.Release
8685
DecodeJSON(t, resp, &newRelease)
87-
rel := &models.Release{
86+
rel := &repo_model.Release{
8887
ID: newRelease.ID,
8988
TagName: newRelease.TagName,
9089
Title: newRelease.Title,
@@ -138,7 +137,7 @@ func TestAPICreateAndUpdateRelease(t *testing.T) {
138137
resp = session.MakeRequest(t, req, http.StatusOK)
139138

140139
DecodeJSON(t, resp, &newRelease)
141-
rel := &models.Release{
140+
rel := &repo_model.Release{
142141
ID: newRelease.ID,
143142
TagName: newRelease.TagName,
144143
Title: newRelease.Title,

Diff for: integrations/api_token_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"net/http"
99
"testing"
1010

11-
"code.gitea.io/gitea/models"
11+
auth_model "code.gitea.io/gitea/models/auth"
1212
"code.gitea.io/gitea/models/unittest"
1313
user_model "code.gitea.io/gitea/models/user"
1414
api "code.gitea.io/gitea/modules/structs"
@@ -27,7 +27,7 @@ func TestAPICreateAndDeleteToken(t *testing.T) {
2727

2828
var newAccessToken api.AccessToken
2929
DecodeJSON(t, resp, &newAccessToken)
30-
unittest.AssertExistsAndLoadBean(t, &models.AccessToken{
30+
unittest.AssertExistsAndLoadBean(t, &auth_model.AccessToken{
3131
ID: newAccessToken.ID,
3232
Name: newAccessToken.Name,
3333
Token: newAccessToken.Token,
@@ -38,7 +38,7 @@ func TestAPICreateAndDeleteToken(t *testing.T) {
3838
req = AddBasicAuthHeader(req, user.Name)
3939
MakeRequest(t, req, http.StatusNoContent)
4040

41-
unittest.AssertNotExistsBean(t, &models.AccessToken{ID: newAccessToken.ID})
41+
unittest.AssertNotExistsBean(t, &auth_model.AccessToken{ID: newAccessToken.ID})
4242

4343
req = NewRequestWithJSON(t, "POST", "/api/v1/users/user1/tokens", map[string]string{
4444
"name": "test-key-2",
@@ -51,7 +51,7 @@ func TestAPICreateAndDeleteToken(t *testing.T) {
5151
req = AddBasicAuthHeader(req, user.Name)
5252
MakeRequest(t, req, http.StatusNoContent)
5353

54-
unittest.AssertNotExistsBean(t, &models.AccessToken{ID: newAccessToken.ID})
54+
unittest.AssertNotExistsBean(t, &auth_model.AccessToken{ID: newAccessToken.ID})
5555
}
5656

5757
// TestAPIDeleteMissingToken ensures that error is thrown when token not found

Diff for: integrations/api_user_heatmap_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"testing"
1111
"time"
1212

13-
"code.gitea.io/gitea/models"
13+
activities_model "code.gitea.io/gitea/models/activities"
1414
"code.gitea.io/gitea/modules/timeutil"
1515

1616
"github.com/stretchr/testify/assert"
@@ -29,10 +29,10 @@ func TestUserHeatmap(t *testing.T) {
2929
urlStr := fmt.Sprintf("/api/v1/users/%s/heatmap?token=%s", normalUsername, token)
3030
req := NewRequest(t, "GET", urlStr)
3131
resp := MakeRequest(t, req, http.StatusOK)
32-
var heatmap []*models.UserHeatmapData
32+
var heatmap []*activities_model.UserHeatmapData
3333
DecodeJSON(t, resp, &heatmap)
34-
var dummyheatmap []*models.UserHeatmapData
35-
dummyheatmap = append(dummyheatmap, &models.UserHeatmapData{Timestamp: 1603227600, Contributions: 1})
34+
var dummyheatmap []*activities_model.UserHeatmapData
35+
dummyheatmap = append(dummyheatmap, &activities_model.UserHeatmapData{Timestamp: 1603227600, Contributions: 1})
3636

3737
assert.Equal(t, dummyheatmap, heatmap)
3838
}

Diff for: integrations/eventsource_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"testing"
1111
"time"
1212

13-
"code.gitea.io/gitea/models"
13+
activities_model "code.gitea.io/gitea/models/activities"
1414
repo_model "code.gitea.io/gitea/models/repo"
1515
"code.gitea.io/gitea/models/unittest"
1616
user_model "code.gitea.io/gitea/models/user"
@@ -42,7 +42,7 @@ func TestEventSourceManagerRun(t *testing.T) {
4242
if !ok {
4343
return false
4444
}
45-
data, ok := event.Data.(models.UserIDCount)
45+
data, ok := event.Data.(activities_model.UserIDCount)
4646
if !ok {
4747
return false
4848
}
@@ -55,7 +55,7 @@ func TestEventSourceManagerRun(t *testing.T) {
5555

5656
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
5757
repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
58-
thread5 := unittest.AssertExistsAndLoadBean(t, &models.Notification{ID: 5})
58+
thread5 := unittest.AssertExistsAndLoadBean(t, &activities_model.Notification{ID: 5})
5959
assert.NoError(t, thread5.LoadAttributes())
6060
session := loginUser(t, user2.Name)
6161
token := getTokenForLoggedInUser(t, session)

Diff for: integrations/mirror_pull_test.go

+7-8
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"context"
99
"testing"
1010

11-
"code.gitea.io/gitea/models"
1211
repo_model "code.gitea.io/gitea/models/repo"
1312
"code.gitea.io/gitea/models/unittest"
1413
user_model "code.gitea.io/gitea/models/user"
@@ -38,7 +37,7 @@ func TestMirrorPull(t *testing.T) {
3837
Releases: false,
3938
}
4039

41-
mirrorRepo, err := repository.CreateRepository(user, user, models.CreateRepoOptions{
40+
mirrorRepo, err := repository.CreateRepository(user, user, repository.CreateRepoOptions{
4241
Name: opts.RepoName,
4342
Description: opts.Description,
4443
IsPrivate: opts.Private,
@@ -57,11 +56,11 @@ func TestMirrorPull(t *testing.T) {
5756
assert.NoError(t, err)
5857
defer gitRepo.Close()
5958

60-
findOptions := models.FindReleasesOptions{IncludeDrafts: true, IncludeTags: true}
61-
initCount, err := models.GetReleaseCountByRepoID(mirror.ID, findOptions)
59+
findOptions := repo_model.FindReleasesOptions{IncludeDrafts: true, IncludeTags: true}
60+
initCount, err := repo_model.GetReleaseCountByRepoID(mirror.ID, findOptions)
6261
assert.NoError(t, err)
6362

64-
assert.NoError(t, release_service.CreateRelease(gitRepo, &models.Release{
63+
assert.NoError(t, release_service.CreateRelease(gitRepo, &repo_model.Release{
6564
RepoID: repo.ID,
6665
Repo: repo,
6766
PublisherID: user.ID,
@@ -81,18 +80,18 @@ func TestMirrorPull(t *testing.T) {
8180
ok := mirror_service.SyncPullMirror(ctx, mirror.ID)
8281
assert.True(t, ok)
8382

84-
count, err := models.GetReleaseCountByRepoID(mirror.ID, findOptions)
83+
count, err := repo_model.GetReleaseCountByRepoID(mirror.ID, findOptions)
8584
assert.NoError(t, err)
8685
assert.EqualValues(t, initCount+1, count)
8786

88-
release, err := models.GetRelease(repo.ID, "v0.2")
87+
release, err := repo_model.GetRelease(repo.ID, "v0.2")
8988
assert.NoError(t, err)
9089
assert.NoError(t, release_service.DeleteReleaseByID(ctx, release.ID, user, true))
9190

9291
ok = mirror_service.SyncPullMirror(ctx, mirror.ID)
9392
assert.True(t, ok)
9493

95-
count, err = models.GetReleaseCountByRepoID(mirror.ID, findOptions)
94+
count, err = repo_model.GetReleaseCountByRepoID(mirror.ID, findOptions)
9695
assert.NoError(t, err)
9796
assert.EqualValues(t, initCount, count)
9897
}

Diff for: integrations/mirror_push_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
"strconv"
1313
"testing"
1414

15-
"code.gitea.io/gitea/models"
1615
"code.gitea.io/gitea/models/db"
1716
repo_model "code.gitea.io/gitea/models/repo"
1817
"code.gitea.io/gitea/models/unittest"
@@ -39,7 +38,7 @@ func testMirrorPush(t *testing.T, u *url.URL) {
3938
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
4039
srcRepo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
4140

42-
mirrorRepo, err := repository.CreateRepository(user, user, models.CreateRepoOptions{
41+
mirrorRepo, err := repository.CreateRepository(user, user, repository.CreateRepoOptions{
4342
Name: "test-push-mirror",
4443
})
4544
assert.NoError(t, err)

Diff for: integrations/privateactivity_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"net/http"
1010
"testing"
1111

12-
"code.gitea.io/gitea/models"
12+
activities_model "code.gitea.io/gitea/models/activities"
1313
repo_model "code.gitea.io/gitea/models/repo"
1414
"code.gitea.io/gitea/models/unittest"
1515
user_model "code.gitea.io/gitea/models/user"
@@ -117,7 +117,7 @@ func testPrivateActivityHelperHasHeatmapContentFromPublic(t *testing.T) bool {
117117
req := NewRequestf(t, "GET", "/api/v1/users/%s/heatmap", privateActivityTestUser)
118118
resp := MakeRequest(t, req, http.StatusOK)
119119

120-
var items []*models.UserHeatmapData
120+
var items []*activities_model.UserHeatmapData
121121
DecodeJSON(t, resp, &items)
122122

123123
return len(items) != 0
@@ -129,7 +129,7 @@ func testPrivateActivityHelperHasHeatmapContentFromSession(t *testing.T, session
129129
req := NewRequestf(t, "GET", "/api/v1/users/%s/heatmap?token=%s", privateActivityTestUser, token)
130130
resp := session.MakeRequest(t, req, http.StatusOK)
131131

132-
var items []*models.UserHeatmapData
132+
var items []*activities_model.UserHeatmapData
133133
DecodeJSON(t, resp, &items)
134134

135135
return len(items) != 0

Diff for: integrations/pull_merge_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
user_model "code.gitea.io/gitea/models/user"
2626
"code.gitea.io/gitea/models/webhook"
2727
"code.gitea.io/gitea/modules/git"
28+
repo_module "code.gitea.io/gitea/modules/repository"
2829
api "code.gitea.io/gitea/modules/structs"
2930
"code.gitea.io/gitea/modules/test"
3031
"code.gitea.io/gitea/modules/translation"
@@ -355,7 +356,7 @@ func TestConflictChecking(t *testing.T) {
355356
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
356357

357358
// Create new clean repo to test conflict checking.
358-
baseRepo, err := repo_service.CreateRepository(user, user, models.CreateRepoOptions{
359+
baseRepo, err := repo_service.CreateRepository(user, user, repo_module.CreateRepoOptions{
359360
Name: "conflict-checking",
360361
Description: "Tempo repo",
361362
AutoInit: true,

0 commit comments

Comments
 (0)