aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2020-03-29 13:27:06 +0800
committerGitHub <noreply@github.com>2020-03-29 02:27:06 -0300
commit61f603cd8a74f9e4d59801bca2c3d1e44cdba304 (patch)
tree2b16b6090dd5697e7a0dddcb9579beb90a607d23
parent48890ce5468f804a72e210e57e5b3800c9d34ffd (diff)
downloadgitea-61f603cd8a74f9e4d59801bca2c3d1e44cdba304.tar.gz
gitea-61f603cd8a74f9e4d59801bca2c3d1e44cdba304.zip
Create a new function to build search repository condition (#10858)
Co-authored-by: Lauris BH <lauris@nix.lv> Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com>
-rw-r--r--models/repo_list.go19
1 files changed, 13 insertions, 6 deletions
diff --git a/models/repo_list.go b/models/repo_list.go
index 6385de4b32..9c5597ee09 100644
--- a/models/repo_list.go
+++ b/models/repo_list.go
@@ -190,12 +190,8 @@ const (
SearchOrderByForksReverse SearchOrderBy = "num_forks DESC"
)
-// SearchRepository returns repositories based on search options,
-// it returns results in given range and number of total results.
-func SearchRepository(opts *SearchRepoOptions) (RepositoryList, int64, error) {
- if opts.Page <= 0 {
- opts.Page = 1
- }
+// SearchRepositoryCondition creates a query condition according search repository options
+func SearchRepositoryCondition(opts *SearchRepoOptions) builder.Cond {
var cond = builder.NewCond()
if opts.Private {
@@ -298,6 +294,17 @@ func SearchRepository(opts *SearchRepoOptions) (RepositoryList, int64, error) {
if opts.Actor != nil && opts.Actor.IsRestricted {
cond = cond.And(accessibleRepositoryCondition(opts.Actor))
}
+ return cond
+}
+
+// SearchRepository returns repositories based on search options,
+// it returns results in given range and number of total results.
+func SearchRepository(opts *SearchRepoOptions) (RepositoryList, int64, error) {
+ cond := SearchRepositoryCondition(opts)
+
+ if opts.Page <= 0 {
+ opts.Page = 1
+ }
if len(opts.OrderBy) == 0 {
opts.OrderBy = SearchOrderByAlphabetically