diff options
author | Sean McGivern <sean@gitlab.com> | 2018-02-23 16:04:20 +0000 |
---|---|---|
committer | Sean McGivern <sean@gitlab.com> | 2018-03-01 10:41:02 +0000 |
commit | 2f7dffe5489f73eb8ba119184a2e73b3caa6097b (patch) | |
tree | 21466d69fe8d5cce93b468e459cb1eeebea4786a /app/finders | |
parent | 8c310424ca2e31ee84d2a404bc42c2e310fb722f (diff) | |
download | gitlab-ce-2f7dffe5489f73eb8ba119184a2e73b3caa6097b.tar.gz |
Add source and target branch filters to merge requests API
Diffstat (limited to 'app/finders')
-rw-r--r-- | app/finders/merge_requests_finder.rb | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/app/finders/merge_requests_finder.rb b/app/finders/merge_requests_finder.rb index d0687d28c21..068ae7f8c89 100644 --- a/app/finders/merge_requests_finder.rb +++ b/app/finders/merge_requests_finder.rb @@ -17,14 +17,42 @@ # sort: string # non_archived: boolean # my_reaction_emoji: string +# source_branch: string +# target_branch: string # class MergeRequestsFinder < IssuableFinder def klass MergeRequest end + def filter_items(_items) + items = by_source_branch(super) + + by_target_branch(items) + end + private + def source_branch + @source_branch ||= params[:source_branch].presence + end + + def by_source_branch(items) + return items unless source_branch + + items.where(source_branch: source_branch) + end + + def target_branch + @target_branch ||= params[:target_branch].presence + end + + def by_target_branch(items) + return items unless target_branch + + items.where(target_branch: target_branch) + end + def item_project_ids(items) items&.reorder(nil)&.select(:target_project_id) end |