Move login related structs and functions to models/login (#17093)

* Move login related structs and functions to models/login

* Fix test

* Fix lint

* Fix lint

* Fix lint of windows

* Fix lint

* Fix test

* Fix test

* Only load necessary fixtures when preparing unit tests envs

* Fix lint

* Fix test

* Fix test

* Fix error log

* Fix error log

* Fix error log

* remove unnecessary change

* fix error log

* merge main branch
This commit is contained in:
Lunny Xiao 2021-09-24 19:32:56 +08:00 committed by GitHub
parent 4a2655098f
commit 5842a55b31
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
142 changed files with 1050 additions and 907 deletions

View file

@ -12,6 +12,7 @@ import (
"time"
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/login"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/structs"
@ -338,8 +339,8 @@ func ToTopicResponse(topic *models.Topic) *api.TopicResponse {
}
}
// ToOAuth2Application convert from models.OAuth2Application to api.OAuth2Application
func ToOAuth2Application(app *models.OAuth2Application) *api.OAuth2Application {
// ToOAuth2Application convert from login.OAuth2Application to api.OAuth2Application
func ToOAuth2Application(app *login.OAuth2Application) *api.OAuth2Application {
return &api.OAuth2Application{
ID: app.ID,
Name: app.Name,

View file

@ -10,6 +10,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"
)
@ -114,7 +115,7 @@ func (graph *Graph) LoadAndProcessCommits(repository *models.Repository, gitRepo
_ = models.CalculateTrustStatus(c.Verification, repository, &keyMap)
statuses, err := models.GetLatestCommitStatus(repository.ID, c.Commit.ID.String(), models.ListOptions{})
statuses, err := models.GetLatestCommitStatus(repository.ID, c.Commit.ID.String(), db.ListOptions{})
if err != nil {
log.Error("GetLatestCommitStatus: %v", err)
} else {

View file

@ -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"
@ -241,7 +242,7 @@ func populateIssueIndexer(ctx context.Context) {
default:
}
repos, _, err := models.SearchRepositoryByName(&models.SearchRepoOptions{
ListOptions: models.ListOptions{Page: page, PageSize: models.RepositoryListDefaultPageSize},
ListOptions: db.ListOptions{Page: page, PageSize: models.RepositoryListDefaultPageSize},
OrderBy: models.SearchOrderByID,
Private: true,
Collaborate: util.OptionalBoolFalse,

View file

@ -69,12 +69,12 @@ func TestGiteaUploadRepo(t *testing.T) {
assert.NoError(t, err)
assert.Empty(t, milestones)
labels, err := models.GetLabelsByRepoID(repo.ID, "", models.ListOptions{})
labels, err := models.GetLabelsByRepoID(repo.ID, "", db.ListOptions{})
assert.NoError(t, err)
assert.Len(t, labels, 12)
releases, err := models.GetReleasesByRepoID(repo.ID, models.FindReleasesOptions{
ListOptions: models.ListOptions{
ListOptions: db.ListOptions{
PageSize: 10,
Page: 0,
},
@ -84,7 +84,7 @@ func TestGiteaUploadRepo(t *testing.T) {
assert.Len(t, releases, 8)
releases, err = models.GetReleasesByRepoID(repo.ID, models.FindReleasesOptions{
ListOptions: models.ListOptions{
ListOptions: db.ListOptions{
PageSize: 10,
Page: 0,
},

View file

@ -122,7 +122,7 @@ func DeleteUnadoptedRepository(doer, u *models.User, repoName string) error {
}
// ListUnadoptedRepositories lists all the unadopted repositories that match the provided query
func ListUnadoptedRepositories(query string, opts *models.ListOptions) ([]string, int, error) {
func ListUnadoptedRepositories(query string, opts *db.ListOptions) ([]string, int, error) {
globUser, _ := glob.Compile("*")
globRepo, _ := glob.Compile("*")
@ -165,10 +165,13 @@ func ListUnadoptedRepositories(query string, opts *models.ListOptions) ([]string
// Clean up old repoNamesToCheck
if len(repoNamesToCheck) > 0 {
repos, _, err := models.GetUserRepositories(&models.SearchRepoOptions{Actor: ctxUser, Private: true, ListOptions: models.ListOptions{
Page: 1,
PageSize: opts.PageSize,
}, LowerNames: repoNamesToCheck})
repos, _, err := models.GetUserRepositories(&models.SearchRepoOptions{
Actor: ctxUser,
Private: true,
ListOptions: db.ListOptions{
Page: 1,
PageSize: opts.PageSize,
}, LowerNames: repoNamesToCheck})
if err != nil {
return err
}
@ -219,10 +222,13 @@ func ListUnadoptedRepositories(query string, opts *models.ListOptions) ([]string
if count < end {
repoNamesToCheck = append(repoNamesToCheck, name)
if len(repoNamesToCheck) >= opts.PageSize {
repos, _, err := models.GetUserRepositories(&models.SearchRepoOptions{Actor: ctxUser, Private: true, ListOptions: models.ListOptions{
Page: 1,
PageSize: opts.PageSize,
}, LowerNames: repoNamesToCheck})
repos, _, err := models.GetUserRepositories(&models.SearchRepoOptions{
Actor: ctxUser,
Private: true,
ListOptions: db.ListOptions{
Page: 1,
PageSize: opts.PageSize,
}, LowerNames: repoNamesToCheck})
if err != nil {
return err
}
@ -254,10 +260,13 @@ func ListUnadoptedRepositories(query string, opts *models.ListOptions) ([]string
}
if len(repoNamesToCheck) > 0 {
repos, _, err := models.GetUserRepositories(&models.SearchRepoOptions{Actor: ctxUser, Private: true, ListOptions: models.ListOptions{
Page: 1,
PageSize: opts.PageSize,
}, LowerNames: repoNamesToCheck})
repos, _, err := models.GetUserRepositories(&models.SearchRepoOptions{
Actor: ctxUser,
Private: true,
ListOptions: db.ListOptions{
Page: 1,
PageSize: opts.PageSize,
}, LowerNames: repoNamesToCheck})
if err != nil {
return nil, 0, err
}

View file

@ -224,7 +224,11 @@ func CleanUpMigrateInfo(repo *models.Repository) (*models.Repository, error) {
// SyncReleasesWithTags synchronizes release table with repository tags
func SyncReleasesWithTags(repo *models.Repository, gitRepo *git.Repository) error {
existingRelTags := make(map[string]struct{})
opts := models.FindReleasesOptions{IncludeDrafts: true, IncludeTags: true, ListOptions: models.ListOptions{PageSize: 50}}
opts := models.FindReleasesOptions{
IncludeDrafts: true,
IncludeTags: true,
ListOptions: db.ListOptions{PageSize: 50},
}
for page := 1; ; page++ {
opts.Page = page
rels, err := models.GetReleasesByRepoID(repo.ID, opts)