diff options
author | Rémy Coutable <remy@rymai.me> | 2018-03-01 11:47:42 +0000 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2018-03-01 11:47:42 +0000 |
commit | 4bc0900089e79430c61be0758062b0fddd078139 (patch) | |
tree | 4ca88f89ecf92d3e5603a41400e0e5f99fc2e4e4 /app/finders | |
parent | 7adab068abd58301b5b93c80803cf1e2af5a6a58 (diff) | |
parent | 2f7dffe5489f73eb8ba119184a2e73b3caa6097b (diff) | |
download | gitlab-ce-4bc0900089e79430c61be0758062b0fddd078139.tar.gz |
Merge branch 'merge-requests-api-filter-by-branch' into 'master'
Add source and target branch filters to merge requests API
Closes #42492
See merge request gitlab-org/gitlab-ce!17355
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 |