summaryrefslogtreecommitdiffstats
path: root/models/repo_list.go
diff options
context:
space:
mode:
Diffstat (limited to 'models/repo_list.go')
-rw-r--r--models/repo_list.go32
1 files changed, 25 insertions, 7 deletions
diff --git a/models/repo_list.go b/models/repo_list.go
index 7ceb88f088..1632e64eb9 100644
--- a/models/repo_list.go
+++ b/models/repo_list.go
@@ -163,6 +163,10 @@ type SearchRepoOptions struct {
TopicOnly bool
// include description in keyword search
IncludeDescription bool
+ // None -> include has milestones AND has no milestone
+ // True -> include just has milestones
+ // False -> include just has no milestone
+ HasMilestones util.OptionalBool
}
//SearchOrderBy is used to sort the result
@@ -294,6 +298,14 @@ func SearchRepositoryCondition(opts *SearchRepoOptions) builder.Cond {
if opts.Actor != nil && opts.Actor.IsRestricted {
cond = cond.And(accessibleRepositoryCondition(opts.Actor))
}
+
+ switch opts.HasMilestones {
+ case util.OptionalBoolTrue:
+ cond = cond.And(builder.Gt{"num_milestones": 0})
+ case util.OptionalBoolFalse:
+ cond = cond.And(builder.Eq{"num_milestones": 0}.Or(builder.IsNull{"num_milestones"}))
+ }
+
return cond
}
@@ -301,7 +313,11 @@ func SearchRepositoryCondition(opts *SearchRepoOptions) builder.Cond {
// it returns results in given range and number of total results.
func SearchRepository(opts *SearchRepoOptions) (RepositoryList, int64, error) {
cond := SearchRepositoryCondition(opts)
+ return SearchRepositoryByCondition(opts, cond, true)
+}
+// SearchRepositoryByCondition search repositories by condition
+func SearchRepositoryByCondition(opts *SearchRepoOptions, cond builder.Cond, loadAttributes bool) (RepositoryList, int64, error) {
if opts.Page <= 0 {
opts.Page = 1
}
@@ -326,16 +342,18 @@ func SearchRepository(opts *SearchRepoOptions) (RepositoryList, int64, error) {
}
repos := make(RepositoryList, 0, opts.PageSize)
- if err = sess.
- Where(cond).
- OrderBy(opts.OrderBy.String()).
- Limit(opts.PageSize, (opts.Page-1)*opts.PageSize).
- Find(&repos); err != nil {
+ sess.Where(cond).OrderBy(opts.OrderBy.String())
+ if opts.PageSize > 0 {
+ sess.Limit(opts.PageSize, (opts.Page-1)*opts.PageSize)
+ }
+ if err = sess.Find(&repos); err != nil {
return nil, 0, fmt.Errorf("Repo: %v", err)
}
- if err = repos.loadAttributes(sess); err != nil {
- return nil, 0, fmt.Errorf("LoadAttributes: %v", err)
+ if loadAttributes {
+ if err = repos.loadAttributes(sess); err != nil {
+ return nil, 0, fmt.Errorf("LoadAttributes: %v", err)
+ }
}
return repos, count, nil