Skip to content

Commit 61f603c

Browse files
lunnylafriksguillep2k
authored
Create a new function to build search repository condition (#10858)
Co-authored-by: Lauris BH <[email protected]> Co-authored-by: guillep2k <[email protected]>
1 parent 48890ce commit 61f603c

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

models/repo_list.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -190,12 +190,8 @@ const (
190190
SearchOrderByForksReverse SearchOrderBy = "num_forks DESC"
191191
)
192192

193-
// SearchRepository returns repositories based on search options,
194-
// it returns results in given range and number of total results.
195-
func SearchRepository(opts *SearchRepoOptions) (RepositoryList, int64, error) {
196-
if opts.Page <= 0 {
197-
opts.Page = 1
198-
}
193+
// SearchRepositoryCondition creates a query condition according search repository options
194+
func SearchRepositoryCondition(opts *SearchRepoOptions) builder.Cond {
199195
var cond = builder.NewCond()
200196

201197
if opts.Private {
@@ -298,6 +294,17 @@ func SearchRepository(opts *SearchRepoOptions) (RepositoryList, int64, error) {
298294
if opts.Actor != nil && opts.Actor.IsRestricted {
299295
cond = cond.And(accessibleRepositoryCondition(opts.Actor))
300296
}
297+
return cond
298+
}
299+
300+
// SearchRepository returns repositories based on search options,
301+
// it returns results in given range and number of total results.
302+
func SearchRepository(opts *SearchRepoOptions) (RepositoryList, int64, error) {
303+
cond := SearchRepositoryCondition(opts)
304+
305+
if opts.Page <= 0 {
306+
opts.Page = 1
307+
}
301308

302309
if len(opts.OrderBy) == 0 {
303310
opts.OrderBy = SearchOrderByAlphabetically

0 commit comments

Comments
 (0)