diff options
Diffstat (limited to 'models/repo')
-rw-r--r-- | models/repo/repo_list.go | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/models/repo/repo_list.go b/models/repo/repo_list.go index 1fa469fcfe..ee72dc6ee7 100644 --- a/models/repo/repo_list.go +++ b/models/repo/repo_list.go @@ -163,6 +163,10 @@ type SearchRepoOptions struct { HasMilestones util.OptionalBool // LowerNames represents valid lower names to restrict to LowerNames []string + // When specified true, apply some filters over the conditions: + // - Don't show forks, when opts.Fork is OptionalBoolNone. + // - Do not display repositories that don't have a description, an icon and topics. + OnlyShowRelevant bool } // SearchOrderBy is used to sort the result @@ -463,8 +467,12 @@ func SearchRepositoryCondition(opts *SearchRepoOptions) builder.Cond { Where(builder.Eq{"language": opts.Language}).And(builder.Eq{"is_primary": true}))) } - if opts.Fork != util.OptionalBoolNone { - cond = cond.And(builder.Eq{"is_fork": opts.Fork == util.OptionalBoolTrue}) + if opts.Fork != util.OptionalBoolNone || opts.OnlyShowRelevant { + if opts.OnlyShowRelevant && opts.Fork == util.OptionalBoolNone { + cond = cond.And(builder.Eq{"is_fork": false}) + } else { + cond = cond.And(builder.Eq{"is_fork": opts.Fork == util.OptionalBoolTrue}) + } } if opts.Mirror != util.OptionalBoolNone { @@ -486,6 +494,25 @@ func SearchRepositoryCondition(opts *SearchRepoOptions) builder.Cond { cond = cond.And(builder.Eq{"num_milestones": 0}.Or(builder.IsNull{"num_milestones"})) } + if opts.OnlyShowRelevant { + // Only show a repo that either has a topic or description. + subQueryCond := builder.NewCond() + + // Topic checking. Topics is non-null. + subQueryCond = subQueryCond.Or(builder.And(builder.Neq{"topics": "null"}, builder.Neq{"topics": "[]"})) + + // Description checking. Description not empty. + subQueryCond = subQueryCond.Or(builder.Neq{"description": ""}) + + // Repo has a avatar. + subQueryCond = subQueryCond.Or(builder.Neq{"avatar": ""}) + + // Always hide repo's that are empty. + subQueryCond = subQueryCond.And(builder.Eq{"is_empty": false}) + + cond = cond.And(subQueryCond) + } + return cond } |