diff options
author | Chantal Rollison <afspirit04@gmail.com> | 2018-10-03 11:15:00 +0300 |
---|---|---|
committer | Tim Zallmann <tzallmann@gitlab.com> | 2018-10-03 11:15:00 +0300 |
commit | 38f3d59fd0b2dd4eef5c94512ea6216a0e5d56b5 (patch) | |
tree | ce34ad0daceb0e9aed942cfbb84425b39b66ae08 /app/finders | |
parent | 82ece8ad4584278ce437270470b54ff9b42c653b (diff) |
#13650 added wip search functionality and tests
Diffstat (limited to 'app/finders')
-rw-r--r-- | app/finders/merge_requests_finder.rb | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/app/finders/merge_requests_finder.rb b/app/finders/merge_requests_finder.rb index b698a3c7b09..50c051c3aa1 100644 --- a/app/finders/merge_requests_finder.rb +++ b/app/finders/merge_requests_finder.rb @@ -27,13 +27,17 @@ # updated_before: datetime # class MergeRequestsFinder < IssuableFinder + def self.scalar_params + @scalar_params ||= super + [:wip] + end + def klass MergeRequest end def filter_items(_items) items = by_source_branch(super) - + items = by_wip(items) by_target_branch(items) end @@ -61,5 +65,24 @@ class MergeRequestsFinder < IssuableFinder items.where(target_branch: target_branch) end - # rubocop: enable CodeReuse/ActiveRecord + + def item_project_ids(items) + items&.reorder(nil)&.select(:target_project_id) + end + + def by_wip(items) + if params[:wip] == 'yes' + items.where(wip_match(items.arel_table)) + elsif params[:wip] == 'no' + items.where.not(wip_match(items.arel_table)) + else + items + end + end + + def wip_match(table) + table[:title].matches('WIP:%') + .or(table[:title].matches('WIP %')) + .or(table[:title].matches('[WIP]%')) + end end |