Do not mutate incoming options to SearchRepositoryByName (#34553)

Similar to #34544, this PR changes the `opts` argument in
`SearchRepositoryByName()` to be passed by value instead of by pointer,
as its mutations do not escape the function scope and are not used
elsewhere. This simplifies reasoning about the function and avoids
unnecessary pointer usage.

This insight emerged during an initial attempt to refactor
`RenderUserSearch()`, which currently intermixes multiple concerns.

---------

Co-authored-by: Philip Peterson <philip-peterson@users.noreply.github.com>
pull/34580/head^2
Philip Peterson 2025-06-02 10:33:25 -07:00 committed by GitHub
parent f48c0135a6
commit c5e78fc7ad
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
25 changed files with 91 additions and 89 deletions

View File

@ -107,7 +107,7 @@ func runRepoSyncReleases(_ *cli.Context) error {
log.Trace("Synchronizing repository releases (this may take a while)") log.Trace("Synchronizing repository releases (this may take a while)")
for page := 1; ; page++ { for page := 1; ; page++ {
repos, count, err := repo_model.SearchRepositoryByName(ctx, &repo_model.SearchRepoOptions{ repos, count, err := repo_model.SearchRepositoryByName(ctx, repo_model.SearchRepoOptions{
ListOptions: db.ListOptions{ ListOptions: db.ListOptions{
PageSize: repo_model.RepositoryListDefaultPageSize, PageSize: repo_model.RepositoryListDefaultPageSize,
Page: page, Page: page,

View File

@ -487,7 +487,7 @@ func FindRecentlyPushedNewBranches(ctx context.Context, doer *user_model.User, o
ForkFrom: opts.BaseRepo.ID, ForkFrom: opts.BaseRepo.ID,
Archived: optional.Some(false), Archived: optional.Some(false),
} }
repoCond := repo_model.SearchRepositoryCondition(&repoOpts).And(repo_model.AccessibleRepositoryCondition(doer, unit.TypeCode)) repoCond := repo_model.SearchRepositoryCondition(repoOpts).And(repo_model.AccessibleRepositoryCondition(doer, unit.TypeCode))
if opts.Repo.ID == opts.BaseRepo.ID { if opts.Repo.ID == opts.BaseRepo.ID {
// should also include the base repo's branches // should also include the base repo's branches
repoCond = repoCond.Or(builder.Eq{"id": opts.BaseRepo.ID}) repoCond = repoCond.Or(builder.Eq{"id": opts.BaseRepo.ID})

View File

@ -359,7 +359,7 @@ func UserOrgPublicUnitRepoCond(userID, orgID int64) builder.Cond {
} }
// SearchRepositoryCondition creates a query condition according search repository options // SearchRepositoryCondition creates a query condition according search repository options
func SearchRepositoryCondition(opts *SearchRepoOptions) builder.Cond { func SearchRepositoryCondition(opts SearchRepoOptions) builder.Cond {
cond := builder.NewCond() cond := builder.NewCond()
if opts.Private { if opts.Private {
@ -551,18 +551,18 @@ func SearchRepositoryCondition(opts *SearchRepoOptions) builder.Cond {
// SearchRepository returns repositories based on search options, // SearchRepository returns repositories based on search options,
// it returns results in given range and number of total results. // it returns results in given range and number of total results.
func SearchRepository(ctx context.Context, opts *SearchRepoOptions) (RepositoryList, int64, error) { func SearchRepository(ctx context.Context, opts SearchRepoOptions) (RepositoryList, int64, error) {
cond := SearchRepositoryCondition(opts) cond := SearchRepositoryCondition(opts)
return SearchRepositoryByCondition(ctx, opts, cond, true) return SearchRepositoryByCondition(ctx, opts, cond, true)
} }
// CountRepository counts repositories based on search options, // CountRepository counts repositories based on search options,
func CountRepository(ctx context.Context, opts *SearchRepoOptions) (int64, error) { func CountRepository(ctx context.Context, opts SearchRepoOptions) (int64, error) {
return db.GetEngine(ctx).Where(SearchRepositoryCondition(opts)).Count(new(Repository)) return db.GetEngine(ctx).Where(SearchRepositoryCondition(opts)).Count(new(Repository))
} }
// SearchRepositoryByCondition search repositories by condition // SearchRepositoryByCondition search repositories by condition
func SearchRepositoryByCondition(ctx context.Context, opts *SearchRepoOptions, cond builder.Cond, loadAttributes bool) (RepositoryList, int64, error) { func SearchRepositoryByCondition(ctx context.Context, opts SearchRepoOptions, cond builder.Cond, loadAttributes bool) (RepositoryList, int64, error) {
sess, count, err := searchRepositoryByCondition(ctx, opts, cond) sess, count, err := searchRepositoryByCondition(ctx, opts, cond)
if err != nil { if err != nil {
return nil, 0, err return nil, 0, err
@ -590,23 +590,25 @@ func SearchRepositoryByCondition(ctx context.Context, opts *SearchRepoOptions, c
return repos, count, nil return repos, count, nil
} }
func searchRepositoryByCondition(ctx context.Context, opts *SearchRepoOptions, cond builder.Cond) (db.Engine, int64, error) { func searchRepositoryByCondition(ctx context.Context, opts SearchRepoOptions, cond builder.Cond) (db.Engine, int64, error) {
if opts.Page <= 0 { page := opts.Page
opts.Page = 1 if page <= 0 {
page = 1
} }
if len(opts.OrderBy) == 0 { orderBy := opts.OrderBy
opts.OrderBy = db.SearchOrderByAlphabetically if len(orderBy) == 0 {
orderBy = db.SearchOrderByAlphabetically
} }
args := make([]any, 0) args := make([]any, 0)
if opts.PriorityOwnerID > 0 { if opts.PriorityOwnerID > 0 {
opts.OrderBy = db.SearchOrderBy(fmt.Sprintf("CASE WHEN owner_id = ? THEN 0 ELSE owner_id END, %s", opts.OrderBy)) orderBy = db.SearchOrderBy(fmt.Sprintf("CASE WHEN owner_id = ? THEN 0 ELSE owner_id END, %s", orderBy))
args = append(args, opts.PriorityOwnerID) args = append(args, opts.PriorityOwnerID)
} else if strings.Count(opts.Keyword, "/") == 1 { } else if strings.Count(opts.Keyword, "/") == 1 {
// With "owner/repo" search times, prioritise results which match the owner field // With "owner/repo" search times, prioritise results which match the owner field
orgName := strings.Split(opts.Keyword, "/")[0] orgName := strings.Split(opts.Keyword, "/")[0]
opts.OrderBy = db.SearchOrderBy(fmt.Sprintf("CASE WHEN owner_name LIKE ? THEN 0 ELSE 1 END, %s", opts.OrderBy)) orderBy = db.SearchOrderBy(fmt.Sprintf("CASE WHEN owner_name LIKE ? THEN 0 ELSE 1 END, %s", orderBy))
args = append(args, orgName) args = append(args, orgName)
} }
@ -623,9 +625,9 @@ func searchRepositoryByCondition(ctx context.Context, opts *SearchRepoOptions, c
} }
} }
sess = sess.Where(cond).OrderBy(opts.OrderBy.String(), args...) sess = sess.Where(cond).OrderBy(orderBy.String(), args...)
if opts.PageSize > 0 { if opts.PageSize > 0 {
sess = sess.Limit(opts.PageSize, (opts.Page-1)*opts.PageSize) sess = sess.Limit(opts.PageSize, (page-1)*opts.PageSize)
} }
return sess, count, nil return sess, count, nil
} }
@ -689,14 +691,14 @@ func AccessibleRepositoryCondition(user *user_model.User, unitType unit.Type) bu
// SearchRepositoryByName takes keyword and part of repository name to search, // SearchRepositoryByName takes keyword and part of repository name to search,
// it returns results in given range and number of total results. // it returns results in given range and number of total results.
func SearchRepositoryByName(ctx context.Context, opts *SearchRepoOptions) (RepositoryList, int64, error) { func SearchRepositoryByName(ctx context.Context, opts SearchRepoOptions) (RepositoryList, int64, error) {
opts.IncludeDescription = false opts.IncludeDescription = false
return SearchRepository(ctx, opts) return SearchRepository(ctx, opts)
} }
// SearchRepositoryIDs takes keyword and part of repository name to search, // SearchRepositoryIDs takes keyword and part of repository name to search,
// it returns results in given range and number of total results. // it returns results in given range and number of total results.
func SearchRepositoryIDs(ctx context.Context, opts *SearchRepoOptions) ([]int64, int64, error) { func SearchRepositoryIDs(ctx context.Context, opts SearchRepoOptions) ([]int64, int64, error) {
opts.IncludeDescription = false opts.IncludeDescription = false
cond := SearchRepositoryCondition(opts) cond := SearchRepositoryCondition(opts)
@ -740,7 +742,7 @@ func FindUserCodeAccessibleOwnerRepoIDs(ctx context.Context, ownerID int64, user
} }
// GetUserRepositories returns a list of repositories of given user. // GetUserRepositories returns a list of repositories of given user.
func GetUserRepositories(ctx context.Context, opts *SearchRepoOptions) (RepositoryList, int64, error) { func GetUserRepositories(ctx context.Context, opts SearchRepoOptions) (RepositoryList, int64, error) {
if len(opts.OrderBy) == 0 { if len(opts.OrderBy) == 0 {
opts.OrderBy = "updated_unix DESC" opts.OrderBy = "updated_unix DESC"
} }
@ -767,5 +769,5 @@ func GetUserRepositories(ctx context.Context, opts *SearchRepoOptions) (Reposito
sess = sess.Where(cond).OrderBy(opts.OrderBy.String()) sess = sess.Where(cond).OrderBy(opts.OrderBy.String())
repos := make(RepositoryList, 0, opts.PageSize) repos := make(RepositoryList, 0, opts.PageSize)
return repos, count, db.SetSessionPagination(sess, opts).Find(&repos) return repos, count, db.SetSessionPagination(sess, &opts).Find(&repos)
} }

View File

@ -17,162 +17,162 @@ import (
func getTestCases() []struct { func getTestCases() []struct {
name string name string
opts *repo_model.SearchRepoOptions opts repo_model.SearchRepoOptions
count int count int
} { } {
testCases := []struct { testCases := []struct {
name string name string
opts *repo_model.SearchRepoOptions opts repo_model.SearchRepoOptions
count int count int
}{ }{
{ {
name: "PublicRepositoriesByName", name: "PublicRepositoriesByName",
opts: &repo_model.SearchRepoOptions{Keyword: "big_test_", ListOptions: db.ListOptions{PageSize: 10}, Collaborate: optional.Some(false)}, opts: repo_model.SearchRepoOptions{Keyword: "big_test_", ListOptions: db.ListOptions{PageSize: 10}, Collaborate: optional.Some(false)},
count: 7, count: 7,
}, },
{ {
name: "PublicAndPrivateRepositoriesByName", name: "PublicAndPrivateRepositoriesByName",
opts: &repo_model.SearchRepoOptions{Keyword: "big_test_", ListOptions: db.ListOptions{Page: 1, PageSize: 10}, Private: true, Collaborate: optional.Some(false)}, opts: repo_model.SearchRepoOptions{Keyword: "big_test_", ListOptions: db.ListOptions{Page: 1, PageSize: 10}, Private: true, Collaborate: optional.Some(false)},
count: 14, count: 14,
}, },
{ {
name: "PublicAndPrivateRepositoriesByNameWithPagesizeLimitFirstPage", name: "PublicAndPrivateRepositoriesByNameWithPagesizeLimitFirstPage",
opts: &repo_model.SearchRepoOptions{Keyword: "big_test_", ListOptions: db.ListOptions{Page: 1, PageSize: 5}, Private: true, Collaborate: optional.Some(false)}, opts: repo_model.SearchRepoOptions{Keyword: "big_test_", ListOptions: db.ListOptions{Page: 1, PageSize: 5}, Private: true, Collaborate: optional.Some(false)},
count: 14, count: 14,
}, },
{ {
name: "PublicAndPrivateRepositoriesByNameWithPagesizeLimitSecondPage", name: "PublicAndPrivateRepositoriesByNameWithPagesizeLimitSecondPage",
opts: &repo_model.SearchRepoOptions{Keyword: "big_test_", ListOptions: db.ListOptions{Page: 2, PageSize: 5}, Private: true, Collaborate: optional.Some(false)}, opts: repo_model.SearchRepoOptions{Keyword: "big_test_", ListOptions: db.ListOptions{Page: 2, PageSize: 5}, Private: true, Collaborate: optional.Some(false)},
count: 14, count: 14,
}, },
{ {
name: "PublicAndPrivateRepositoriesByNameWithPagesizeLimitThirdPage", name: "PublicAndPrivateRepositoriesByNameWithPagesizeLimitThirdPage",
opts: &repo_model.SearchRepoOptions{Keyword: "big_test_", ListOptions: db.ListOptions{Page: 3, PageSize: 5}, Private: true, Collaborate: optional.Some(false)}, opts: repo_model.SearchRepoOptions{Keyword: "big_test_", ListOptions: db.ListOptions{Page: 3, PageSize: 5}, Private: true, Collaborate: optional.Some(false)},
count: 14, count: 14,
}, },
{ {
name: "PublicAndPrivateRepositoriesByNameWithPagesizeLimitFourthPage", name: "PublicAndPrivateRepositoriesByNameWithPagesizeLimitFourthPage",
opts: &repo_model.SearchRepoOptions{Keyword: "big_test_", ListOptions: db.ListOptions{Page: 3, PageSize: 5}, Private: true, Collaborate: optional.Some(false)}, opts: repo_model.SearchRepoOptions{Keyword: "big_test_", ListOptions: db.ListOptions{Page: 3, PageSize: 5}, Private: true, Collaborate: optional.Some(false)},
count: 14, count: 14,
}, },
{ {
name: "PublicRepositoriesOfUser", name: "PublicRepositoriesOfUser",
opts: &repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 15, Collaborate: optional.Some(false)}, opts: repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 15, Collaborate: optional.Some(false)},
count: 2, count: 2,
}, },
{ {
name: "PublicRepositoriesOfUser2", name: "PublicRepositoriesOfUser2",
opts: &repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 18, Collaborate: optional.Some(false)}, opts: repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 18, Collaborate: optional.Some(false)},
count: 0, count: 0,
}, },
{ {
name: "PublicRepositoriesOfOrg3", name: "PublicRepositoriesOfOrg3",
opts: &repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 20, Collaborate: optional.Some(false)}, opts: repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 20, Collaborate: optional.Some(false)},
count: 2, count: 2,
}, },
{ {
name: "PublicAndPrivateRepositoriesOfUser", name: "PublicAndPrivateRepositoriesOfUser",
opts: &repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 15, Private: true, Collaborate: optional.Some(false)}, opts: repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 15, Private: true, Collaborate: optional.Some(false)},
count: 4, count: 4,
}, },
{ {
name: "PublicAndPrivateRepositoriesOfUser2", name: "PublicAndPrivateRepositoriesOfUser2",
opts: &repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 18, Private: true, Collaborate: optional.Some(false)}, opts: repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 18, Private: true, Collaborate: optional.Some(false)},
count: 0, count: 0,
}, },
{ {
name: "PublicAndPrivateRepositoriesOfOrg3", name: "PublicAndPrivateRepositoriesOfOrg3",
opts: &repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 20, Private: true, Collaborate: optional.Some(false)}, opts: repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 20, Private: true, Collaborate: optional.Some(false)},
count: 4, count: 4,
}, },
{ {
name: "PublicRepositoriesOfUserIncludingCollaborative", name: "PublicRepositoriesOfUserIncludingCollaborative",
opts: &repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 15}, opts: repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 15},
count: 5, count: 5,
}, },
{ {
name: "PublicRepositoriesOfUser2IncludingCollaborative", name: "PublicRepositoriesOfUser2IncludingCollaborative",
opts: &repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 18}, opts: repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 18},
count: 1, count: 1,
}, },
{ {
name: "PublicRepositoriesOfOrg3IncludingCollaborative", name: "PublicRepositoriesOfOrg3IncludingCollaborative",
opts: &repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 20}, opts: repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 20},
count: 3, count: 3,
}, },
{ {
name: "PublicAndPrivateRepositoriesOfUserIncludingCollaborative", name: "PublicAndPrivateRepositoriesOfUserIncludingCollaborative",
opts: &repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 15, Private: true}, opts: repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 15, Private: true},
count: 9, count: 9,
}, },
{ {
name: "PublicAndPrivateRepositoriesOfUser2IncludingCollaborative", name: "PublicAndPrivateRepositoriesOfUser2IncludingCollaborative",
opts: &repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 18, Private: true}, opts: repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 18, Private: true},
count: 4, count: 4,
}, },
{ {
name: "PublicAndPrivateRepositoriesOfOrg3IncludingCollaborative", name: "PublicAndPrivateRepositoriesOfOrg3IncludingCollaborative",
opts: &repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 20, Private: true}, opts: repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 20, Private: true},
count: 7, count: 7,
}, },
{ {
name: "PublicRepositoriesOfOrganization", name: "PublicRepositoriesOfOrganization",
opts: &repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 17, Collaborate: optional.Some(false)}, opts: repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 17, Collaborate: optional.Some(false)},
count: 1, count: 1,
}, },
{ {
name: "PublicAndPrivateRepositoriesOfOrganization", name: "PublicAndPrivateRepositoriesOfOrganization",
opts: &repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 17, Private: true, Collaborate: optional.Some(false)}, opts: repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 17, Private: true, Collaborate: optional.Some(false)},
count: 2, count: 2,
}, },
{ {
name: "AllPublic/PublicRepositoriesByName", name: "AllPublic/PublicRepositoriesByName",
opts: &repo_model.SearchRepoOptions{Keyword: "big_test_", ListOptions: db.ListOptions{PageSize: 10}, AllPublic: true, Collaborate: optional.Some(false)}, opts: repo_model.SearchRepoOptions{Keyword: "big_test_", ListOptions: db.ListOptions{PageSize: 10}, AllPublic: true, Collaborate: optional.Some(false)},
count: 7, count: 7,
}, },
{ {
name: "AllPublic/PublicAndPrivateRepositoriesByName", name: "AllPublic/PublicAndPrivateRepositoriesByName",
opts: &repo_model.SearchRepoOptions{Keyword: "big_test_", ListOptions: db.ListOptions{Page: 1, PageSize: 10}, Private: true, AllPublic: true, Collaborate: optional.Some(false)}, opts: repo_model.SearchRepoOptions{Keyword: "big_test_", ListOptions: db.ListOptions{Page: 1, PageSize: 10}, Private: true, AllPublic: true, Collaborate: optional.Some(false)},
count: 14, count: 14,
}, },
{ {
name: "AllPublic/PublicRepositoriesOfUserIncludingCollaborative", name: "AllPublic/PublicRepositoriesOfUserIncludingCollaborative",
opts: &repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 15, AllPublic: true, Template: optional.Some(false)}, opts: repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 15, AllPublic: true, Template: optional.Some(false)},
count: 34, count: 34,
}, },
{ {
name: "AllPublic/PublicAndPrivateRepositoriesOfUserIncludingCollaborative", name: "AllPublic/PublicAndPrivateRepositoriesOfUserIncludingCollaborative",
opts: &repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 15, Private: true, AllPublic: true, AllLimited: true, Template: optional.Some(false)}, opts: repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 15, Private: true, AllPublic: true, AllLimited: true, Template: optional.Some(false)},
count: 39, count: 39,
}, },
{ {
name: "AllPublic/PublicAndPrivateRepositoriesOfUserIncludingCollaborativeByName", name: "AllPublic/PublicAndPrivateRepositoriesOfUserIncludingCollaborativeByName",
opts: &repo_model.SearchRepoOptions{Keyword: "test", ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 15, Private: true, AllPublic: true}, opts: repo_model.SearchRepoOptions{Keyword: "test", ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 15, Private: true, AllPublic: true},
count: 15, count: 15,
}, },
{ {
name: "AllPublic/PublicAndPrivateRepositoriesOfUser2IncludingCollaborativeByName", name: "AllPublic/PublicAndPrivateRepositoriesOfUser2IncludingCollaborativeByName",
opts: &repo_model.SearchRepoOptions{Keyword: "test", ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 18, Private: true, AllPublic: true}, opts: repo_model.SearchRepoOptions{Keyword: "test", ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 18, Private: true, AllPublic: true},
count: 13, count: 13,
}, },
{ {
name: "AllPublic/PublicRepositoriesOfOrganization", name: "AllPublic/PublicRepositoriesOfOrganization",
opts: &repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 17, AllPublic: true, Collaborate: optional.Some(false), Template: optional.Some(false)}, opts: repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, OwnerID: 17, AllPublic: true, Collaborate: optional.Some(false), Template: optional.Some(false)},
count: 34, count: 34,
}, },
{ {
name: "AllTemplates", name: "AllTemplates",
opts: &repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, Template: optional.Some(true)}, opts: repo_model.SearchRepoOptions{ListOptions: db.ListOptions{Page: 1, PageSize: 10}, Template: optional.Some(true)},
count: 2, count: 2,
}, },
{ {
name: "OwnerSlashRepoSearch", name: "OwnerSlashRepoSearch",
opts: &repo_model.SearchRepoOptions{Keyword: "user/repo2", ListOptions: db.ListOptions{Page: 1, PageSize: 10}, Private: true, OwnerID: 0}, opts: repo_model.SearchRepoOptions{Keyword: "user/repo2", ListOptions: db.ListOptions{Page: 1, PageSize: 10}, Private: true, OwnerID: 0},
count: 2, count: 2,
}, },
{ {
name: "OwnerSlashSearch", name: "OwnerSlashSearch",
opts: &repo_model.SearchRepoOptions{Keyword: "user20/", ListOptions: db.ListOptions{Page: 1, PageSize: 10}, Private: true, OwnerID: 0}, opts: repo_model.SearchRepoOptions{Keyword: "user20/", ListOptions: db.ListOptions{Page: 1, PageSize: 10}, Private: true, OwnerID: 0},
count: 4, count: 4,
}, },
} }
@ -184,7 +184,7 @@ func TestSearchRepository(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase()) assert.NoError(t, unittest.PrepareTestDatabase())
// test search public repository on explore page // test search public repository on explore page
repos, count, err := repo_model.SearchRepositoryByName(db.DefaultContext, &repo_model.SearchRepoOptions{ repos, count, err := repo_model.SearchRepositoryByName(db.DefaultContext, repo_model.SearchRepoOptions{
ListOptions: db.ListOptions{ ListOptions: db.ListOptions{
Page: 1, Page: 1,
PageSize: 10, PageSize: 10,
@ -199,7 +199,7 @@ func TestSearchRepository(t *testing.T) {
} }
assert.Equal(t, int64(1), count) assert.Equal(t, int64(1), count)
repos, count, err = repo_model.SearchRepositoryByName(db.DefaultContext, &repo_model.SearchRepoOptions{ repos, count, err = repo_model.SearchRepositoryByName(db.DefaultContext, repo_model.SearchRepoOptions{
ListOptions: db.ListOptions{ ListOptions: db.ListOptions{
Page: 1, Page: 1,
PageSize: 10, PageSize: 10,
@ -213,7 +213,7 @@ func TestSearchRepository(t *testing.T) {
assert.Len(t, repos, 2) assert.Len(t, repos, 2)
// test search private repository on explore page // test search private repository on explore page
repos, count, err = repo_model.SearchRepositoryByName(db.DefaultContext, &repo_model.SearchRepoOptions{ repos, count, err = repo_model.SearchRepositoryByName(db.DefaultContext, repo_model.SearchRepoOptions{
ListOptions: db.ListOptions{ ListOptions: db.ListOptions{
Page: 1, Page: 1,
PageSize: 10, PageSize: 10,
@ -229,7 +229,7 @@ func TestSearchRepository(t *testing.T) {
} }
assert.Equal(t, int64(1), count) assert.Equal(t, int64(1), count)
repos, count, err = repo_model.SearchRepositoryByName(db.DefaultContext, &repo_model.SearchRepoOptions{ repos, count, err = repo_model.SearchRepositoryByName(db.DefaultContext, repo_model.SearchRepoOptions{
ListOptions: db.ListOptions{ ListOptions: db.ListOptions{
Page: 1, Page: 1,
PageSize: 10, PageSize: 10,
@ -244,14 +244,14 @@ func TestSearchRepository(t *testing.T) {
assert.Len(t, repos, 3) assert.Len(t, repos, 3)
// Test non existing owner // Test non existing owner
repos, count, err = repo_model.SearchRepositoryByName(db.DefaultContext, &repo_model.SearchRepoOptions{OwnerID: unittest.NonexistentID}) repos, count, err = repo_model.SearchRepositoryByName(db.DefaultContext, repo_model.SearchRepoOptions{OwnerID: unittest.NonexistentID})
assert.NoError(t, err) assert.NoError(t, err)
assert.Empty(t, repos) assert.Empty(t, repos)
assert.Equal(t, int64(0), count) assert.Equal(t, int64(0), count)
// Test search within description // Test search within description
repos, count, err = repo_model.SearchRepository(db.DefaultContext, &repo_model.SearchRepoOptions{ repos, count, err = repo_model.SearchRepository(db.DefaultContext, repo_model.SearchRepoOptions{
ListOptions: db.ListOptions{ ListOptions: db.ListOptions{
Page: 1, Page: 1,
PageSize: 10, PageSize: 10,
@ -268,7 +268,7 @@ func TestSearchRepository(t *testing.T) {
assert.Equal(t, int64(1), count) assert.Equal(t, int64(1), count)
// Test NOT search within description // Test NOT search within description
repos, count, err = repo_model.SearchRepository(db.DefaultContext, &repo_model.SearchRepoOptions{ repos, count, err = repo_model.SearchRepository(db.DefaultContext, repo_model.SearchRepoOptions{
ListOptions: db.ListOptions{ ListOptions: db.ListOptions{
Page: 1, Page: 1,
PageSize: 10, PageSize: 10,
@ -374,22 +374,22 @@ func TestSearchRepositoryByTopicName(t *testing.T) {
testCases := []struct { testCases := []struct {
name string name string
opts *repo_model.SearchRepoOptions opts repo_model.SearchRepoOptions
count int count int
}{ }{
{ {
name: "AllPublic/SearchPublicRepositoriesFromTopicAndName", name: "AllPublic/SearchPublicRepositoriesFromTopicAndName",
opts: &repo_model.SearchRepoOptions{OwnerID: 21, AllPublic: true, Keyword: "graphql"}, opts: repo_model.SearchRepoOptions{OwnerID: 21, AllPublic: true, Keyword: "graphql"},
count: 2, count: 2,
}, },
{ {
name: "AllPublic/OnlySearchPublicRepositoriesFromTopic", name: "AllPublic/OnlySearchPublicRepositoriesFromTopic",
opts: &repo_model.SearchRepoOptions{OwnerID: 21, AllPublic: true, Keyword: "graphql", TopicOnly: true}, opts: repo_model.SearchRepoOptions{OwnerID: 21, AllPublic: true, Keyword: "graphql", TopicOnly: true},
count: 1, count: 1,
}, },
{ {
name: "AllPublic/OnlySearchMultipleKeywordPublicRepositoriesFromTopic", name: "AllPublic/OnlySearchMultipleKeywordPublicRepositoriesFromTopic",
opts: &repo_model.SearchRepoOptions{OwnerID: 21, AllPublic: true, Keyword: "graphql,golang", TopicOnly: true}, opts: repo_model.SearchRepoOptions{OwnerID: 21, AllPublic: true, Keyword: "graphql,golang", TopicOnly: true},
count: 2, count: 2,
}, },
} }

View File

@ -217,7 +217,7 @@ func PopulateIssueIndexer(ctx context.Context) error {
return fmt.Errorf("shutdown before completion: %w", ctx.Err()) return fmt.Errorf("shutdown before completion: %w", ctx.Err())
default: default:
} }
repos, _, err := repo_model.SearchRepositoryByName(ctx, &repo_model.SearchRepoOptions{ repos, _, err := repo_model.SearchRepositoryByName(ctx, repo_model.SearchRepoOptions{
ListOptions: db_model.ListOptions{Page: page, PageSize: repo_model.RepositoryListDefaultPageSize}, ListOptions: db_model.ListOptions{Page: page, PageSize: repo_model.RepositoryListDefaultPageSize},
OrderBy: db_model.SearchOrderByID, OrderBy: db_model.SearchOrderByID,
Private: true, Private: true,

View File

@ -152,7 +152,7 @@ func SearchIssues(ctx *context.APIContext) {
) )
{ {
// find repos user can access (for issue search) // find repos user can access (for issue search)
opts := &repo_model.SearchRepoOptions{ opts := repo_model.SearchRepoOptions{
Private: false, Private: false,
AllPublic: true, AllPublic: true,
TopicOnly: false, TopicOnly: false,

View File

@ -134,7 +134,7 @@ func Search(ctx *context.APIContext) {
private = false private = false
} }
opts := &repo_model.SearchRepoOptions{ opts := repo_model.SearchRepoOptions{
ListOptions: utils.GetListOptions(ctx), ListOptions: utils.GetListOptions(ctx),
Actor: ctx.Doer, Actor: ctx.Doer,
Keyword: ctx.FormTrim("q"), Keyword: ctx.FormTrim("q"),

View File

@ -19,7 +19,7 @@ import (
func listUserRepos(ctx *context.APIContext, u *user_model.User, private bool) { func listUserRepos(ctx *context.APIContext, u *user_model.User, private bool) {
opts := utils.GetListOptions(ctx) opts := utils.GetListOptions(ctx)
repos, count, err := repo_model.GetUserRepositories(ctx, &repo_model.SearchRepoOptions{ repos, count, err := repo_model.GetUserRepositories(ctx, repo_model.SearchRepoOptions{
Actor: u, Actor: u,
Private: private, Private: private,
ListOptions: opts, ListOptions: opts,
@ -103,7 +103,7 @@ func ListMyRepos(ctx *context.APIContext) {
// "200": // "200":
// "$ref": "#/responses/RepositoryList" // "$ref": "#/responses/RepositoryList"
opts := &repo_model.SearchRepoOptions{ opts := repo_model.SearchRepoOptions{
ListOptions: utils.GetListOptions(ctx), ListOptions: utils.GetListOptions(ctx),
Actor: ctx.Doer, Actor: ctx.Doer,
OwnerID: ctx.Doer.ID, OwnerID: ctx.Doer.ID,

View File

@ -268,7 +268,7 @@ func ViewUser(ctx *context.Context) {
return return
} }
repos, count, err := repo_model.SearchRepository(ctx, &repo_model.SearchRepoOptions{ repos, count, err := repo_model.SearchRepository(ctx, repo_model.SearchRepoOptions{
ListOptions: db.ListOptionsAll, ListOptions: db.ListOptionsAll,
OwnerID: u.ID, OwnerID: u.ID,
OrderBy: db.SearchOrderByAlphabetically, OrderBy: db.SearchOrderByAlphabetically,

View File

@ -94,7 +94,7 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) {
private := ctx.FormOptionalBool("private") private := ctx.FormOptionalBool("private")
ctx.Data["IsPrivate"] = private ctx.Data["IsPrivate"] = private
repos, count, err = repo_model.SearchRepository(ctx, &repo_model.SearchRepoOptions{ repos, count, err = repo_model.SearchRepository(ctx, repo_model.SearchRepoOptions{
ListOptions: db.ListOptions{ ListOptions: db.ListOptions{
Page: page, Page: page,
PageSize: opts.PageSize, PageSize: opts.PageSize,

View File

@ -86,7 +86,7 @@ func HomeSitemap(ctx *context.Context) {
} }
} }
_, cnt, err := repo_model.SearchRepository(ctx, &repo_model.SearchRepoOptions{ _, cnt, err := repo_model.SearchRepository(ctx, repo_model.SearchRepoOptions{
ListOptions: db.ListOptions{ ListOptions: db.ListOptions{
PageSize: 1, PageSize: 1,
}, },

View File

@ -115,7 +115,7 @@ func home(ctx *context.Context, viewRepositories bool) {
ctx.Data["PageIsViewOverview"] = isViewOverview ctx.Data["PageIsViewOverview"] = isViewOverview
ctx.Data["ShowOrgProfileReadmeSelector"] = isViewOverview && prepareResult.ProfilePublicReadmeBlob != nil && prepareResult.ProfilePrivateReadmeBlob != nil ctx.Data["ShowOrgProfileReadmeSelector"] = isViewOverview && prepareResult.ProfilePublicReadmeBlob != nil && prepareResult.ProfilePrivateReadmeBlob != nil
repos, count, err := repo_model.SearchRepository(ctx, &repo_model.SearchRepoOptions{ repos, count, err := repo_model.SearchRepository(ctx, repo_model.SearchRepoOptions{
ListOptions: db.ListOptions{ ListOptions: db.ListOptions{
PageSize: setting.UI.User.RepoPagingNum, PageSize: setting.UI.User.RepoPagingNum,
Page: page, Page: page,

View File

@ -120,7 +120,7 @@ func SettingsPost(ctx *context.Context) {
// update forks visibility // update forks visibility
if visibilityChanged { if visibilityChanged {
repos, _, err := repo_model.GetUserRepositories(ctx, &repo_model.SearchRepoOptions{ repos, _, err := repo_model.GetUserRepositories(ctx, repo_model.SearchRepoOptions{
Actor: org.AsUser(), Private: true, ListOptions: db.ListOptions{Page: 1, PageSize: org.NumRepos}, Actor: org.AsUser(), Private: true, ListOptions: db.ListOptions{Page: 1, PageSize: org.NumRepos},
}) })
if err != nil { if err != nil {

View File

@ -61,7 +61,7 @@ func SearchIssues(ctx *context.Context) {
) )
{ {
// find repos user can access (for issue search) // find repos user can access (for issue search)
opts := &repo_model.SearchRepoOptions{ opts := repo_model.SearchRepoOptions{
Private: false, Private: false,
AllPublic: true, AllPublic: true,
TopicOnly: false, TopicOnly: false,

View File

@ -461,7 +461,7 @@ func SearchRepo(ctx *context.Context) {
if page <= 0 { if page <= 0 {
page = 1 page = 1
} }
opts := &repo_model.SearchRepoOptions{ opts := repo_model.SearchRepoOptions{
ListOptions: db.ListOptions{ ListOptions: db.ListOptions{
Page: page, Page: page,
PageSize: convert.ToCorrectPageSize(ctx.FormInt("limit")), PageSize: convert.ToCorrectPageSize(ctx.FormInt("limit")),

View File

@ -165,7 +165,7 @@ func RenderUserOrgHeader(ctx *context.Context) (result *PrepareOwnerHeaderResult
} }
func loadHeaderCount(ctx *context.Context) error { func loadHeaderCount(ctx *context.Context) error {
repoCount, err := repo_model.CountRepository(ctx, &repo_model.SearchRepoOptions{ repoCount, err := repo_model.CountRepository(ctx, repo_model.SearchRepoOptions{
Actor: ctx.Doer, Actor: ctx.Doer,
OwnerID: ctx.ContextUser.ID, OwnerID: ctx.ContextUser.ID,
Private: ctx.IsSigned, Private: ctx.IsSigned,

View File

@ -176,7 +176,7 @@ func Milestones(ctx *context.Context) {
} }
var ( var (
userRepoCond = repo_model.SearchRepositoryCondition(&repoOpts) // all repo condition user could visit userRepoCond = repo_model.SearchRepositoryCondition(repoOpts) // all repo condition user could visit
repoCond = userRepoCond repoCond = userRepoCond
repoIDs []int64 repoIDs []int64
@ -242,7 +242,7 @@ func Milestones(ctx *context.Context) {
return return
} }
showRepos, _, err := repo_model.SearchRepositoryByCondition(ctx, &repoOpts, userRepoCond, false) showRepos, _, err := repo_model.SearchRepositoryByCondition(ctx, repoOpts, userRepoCond, false)
if err != nil { if err != nil {
ctx.ServerError("SearchRepositoryByCondition", err) ctx.ServerError("SearchRepositoryByCondition", err)
return return
@ -461,7 +461,7 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) {
// As team: // As team:
// - Team org's owns the repository. // - Team org's owns the repository.
// - Team has read permission to repository. // - Team has read permission to repository.
repoOpts := &repo_model.SearchRepoOptions{ repoOpts := repo_model.SearchRepoOptions{
Actor: ctx.Doer, Actor: ctx.Doer,
OwnerID: ctxUser.ID, OwnerID: ctxUser.ID,
Private: true, Private: true,

View File

@ -28,7 +28,7 @@ func TestArchivedIssues(t *testing.T) {
ctx.Req.Form.Set("state", "open") ctx.Req.Form.Set("state", "open")
// Assume: User 30 has access to two Repos with Issues, one of the Repos being archived. // Assume: User 30 has access to two Repos with Issues, one of the Repos being archived.
repos, _, _ := repo_model.GetUserRepositories(db.DefaultContext, &repo_model.SearchRepoOptions{Actor: ctx.Doer}) repos, _, _ := repo_model.GetUserRepositories(db.DefaultContext, repo_model.SearchRepoOptions{Actor: ctx.Doer})
assert.Len(t, repos, 3) assert.Len(t, repos, 3)
IsArchived := make(map[int64]bool) IsArchived := make(map[int64]bool)
NumIssues := make(map[int64]int) NumIssues := make(map[int64]int)

View File

@ -390,7 +390,7 @@ func NotificationWatching(ctx *context.Context) {
private := ctx.FormOptionalBool("private") private := ctx.FormOptionalBool("private")
ctx.Data["IsPrivate"] = private ctx.Data["IsPrivate"] = private
repos, count, err := repo_model.SearchRepository(ctx, &repo_model.SearchRepoOptions{ repos, count, err := repo_model.SearchRepository(ctx, repo_model.SearchRepoOptions{
ListOptions: db.ListOptions{ ListOptions: db.ListOptions{
PageSize: setting.UI.User.RepoPagingNum, PageSize: setting.UI.User.RepoPagingNum,
Page: page, Page: page,

View File

@ -407,7 +407,7 @@ func PackageSettings(ctx *context.Context) {
ctx.Data["IsPackagesPage"] = true ctx.Data["IsPackagesPage"] = true
ctx.Data["PackageDescriptor"] = pd ctx.Data["PackageDescriptor"] = pd
repos, _, _ := repo_model.GetUserRepositories(ctx, &repo_model.SearchRepoOptions{ repos, _, _ := repo_model.GetUserRepositories(ctx, repo_model.SearchRepoOptions{
Actor: pd.Owner, Actor: pd.Owner,
Private: true, Private: true,
}) })

View File

@ -197,7 +197,7 @@ func prepareUserProfileTabData(ctx *context.Context, showPrivate bool, profileDb
total = int(count) total = int(count)
case "stars": case "stars":
ctx.Data["PageIsProfileStarList"] = true ctx.Data["PageIsProfileStarList"] = true
repos, count, err = repo_model.SearchRepository(ctx, &repo_model.SearchRepoOptions{ repos, count, err = repo_model.SearchRepository(ctx, repo_model.SearchRepoOptions{
ListOptions: db.ListOptions{ ListOptions: db.ListOptions{
PageSize: pagingNum, PageSize: pagingNum,
Page: page, Page: page,
@ -224,7 +224,7 @@ func prepareUserProfileTabData(ctx *context.Context, showPrivate bool, profileDb
total = int(count) total = int(count)
case "watching": case "watching":
repos, count, err = repo_model.SearchRepository(ctx, &repo_model.SearchRepoOptions{ repos, count, err = repo_model.SearchRepository(ctx, repo_model.SearchRepoOptions{
ListOptions: db.ListOptions{ ListOptions: db.ListOptions{
PageSize: pagingNum, PageSize: pagingNum,
Page: page, Page: page,
@ -279,7 +279,7 @@ func prepareUserProfileTabData(ctx *context.Context, showPrivate bool, profileDb
ctx.Data["Cards"] = orgs ctx.Data["Cards"] = orgs
total = int(count) total = int(count)
default: // default to "repositories" default: // default to "repositories"
repos, count, err = repo_model.SearchRepository(ctx, &repo_model.SearchRepoOptions{ repos, count, err = repo_model.SearchRepository(ctx, repo_model.SearchRepoOptions{
ListOptions: db.ListOptions{ ListOptions: db.ListOptions{
PageSize: pagingNum, PageSize: pagingNum,
Page: page, Page: page,

View File

@ -284,7 +284,7 @@ func Repos(ctx *context.Context) {
return return
} }
userRepos, _, err := repo_model.GetUserRepositories(ctx, &repo_model.SearchRepoOptions{ userRepos, _, err := repo_model.GetUserRepositories(ctx, repo_model.SearchRepoOptions{
Actor: ctxUser, Actor: ctxUser,
Private: true, Private: true,
ListOptions: db.ListOptions{ ListOptions: db.ListOptions{
@ -309,7 +309,7 @@ func Repos(ctx *context.Context) {
ctx.Data["Dirs"] = repoNames ctx.Data["Dirs"] = repoNames
ctx.Data["ReposMap"] = repos ctx.Data["ReposMap"] = repos
} else { } else {
repos, count64, err := repo_model.GetUserRepositories(ctx, &repo_model.SearchRepoOptions{Actor: ctxUser, Private: true, ListOptions: opts}) repos, count64, err := repo_model.GetUserRepositories(ctx, repo_model.SearchRepoOptions{Actor: ctxUser, Private: true, ListOptions: opts})
if err != nil { if err != nil {
ctx.ServerError("GetUserRepositories", err) ctx.ServerError("GetUserRepositories", err)
return return

View File

@ -19,7 +19,7 @@ func disableMirrorActionsUnit(ctx context.Context, logger log.Logger, autofix bo
var reposToFix []*repo_model.Repository var reposToFix []*repo_model.Repository
for page := 1; ; page++ { for page := 1; ; page++ {
repos, _, err := repo_model.SearchRepository(ctx, &repo_model.SearchRepoOptions{ repos, _, err := repo_model.SearchRepository(ctx, repo_model.SearchRepoOptions{
ListOptions: db.ListOptions{ ListOptions: db.ListOptions{
PageSize: repo_model.RepositoryListDefaultPageSize, PageSize: repo_model.RepositoryListDefaultPageSize,
Page: page, Page: page,

View File

@ -260,7 +260,7 @@ func checkUnadoptedRepositories(ctx context.Context, userName string, repoNamesT
} }
return err return err
} }
repos, _, err := repo_model.GetUserRepositories(ctx, &repo_model.SearchRepoOptions{ repos, _, err := repo_model.GetUserRepositories(ctx, repo_model.SearchRepoOptions{
Actor: ctxUser, Actor: ctxUser,
Private: true, Private: true,
ListOptions: db.ListOptions{ ListOptions: db.ListOptions{

View File

@ -375,7 +375,7 @@ func DeleteRepositoryDirectly(ctx context.Context, doer *user_model.User, repoID
// DeleteOwnerRepositoriesDirectly calls DeleteRepositoryDirectly for all repos of the given owner // DeleteOwnerRepositoriesDirectly calls DeleteRepositoryDirectly for all repos of the given owner
func DeleteOwnerRepositoriesDirectly(ctx context.Context, owner *user_model.User) error { func DeleteOwnerRepositoriesDirectly(ctx context.Context, owner *user_model.User) error {
for { for {
repos, _, err := repo_model.GetUserRepositories(ctx, &repo_model.SearchRepoOptions{ repos, _, err := repo_model.GetUserRepositories(ctx, repo_model.SearchRepoOptions{
ListOptions: db.ListOptions{ ListOptions: db.ListOptions{
PageSize: repo_model.RepositoryListDefaultPageSize, PageSize: repo_model.RepositoryListDefaultPageSize,
Page: 1, Page: 1,