add a :iids param to IssuableFinder
This commit is contained in:
parent
827a56a479
commit
7362fd6fdf
7 changed files with 23 additions and 27 deletions
|
@ -16,6 +16,7 @@
|
|||
# label_name: string
|
||||
# sort: string
|
||||
# non_archived: boolean
|
||||
# iids: integer[]
|
||||
#
|
||||
class IssuableFinder
|
||||
NONE = '0'
|
||||
|
@ -40,6 +41,7 @@ class IssuableFinder
|
|||
items = by_label(items)
|
||||
items = by_due_date(items)
|
||||
items = by_non_archived(items)
|
||||
items = by_iids(items)
|
||||
sort(items)
|
||||
end
|
||||
|
||||
|
@ -266,16 +268,11 @@ class IssuableFinder
|
|||
end
|
||||
|
||||
def by_search(items)
|
||||
if search
|
||||
items =
|
||||
if search =~ iid_pattern
|
||||
items.where(iid: $~[:iid])
|
||||
else
|
||||
items.full_search(search)
|
||||
end
|
||||
end
|
||||
search ? items.full_search(search) : items
|
||||
end
|
||||
|
||||
items
|
||||
def by_iids(items)
|
||||
params[:iids].present? ? items.where(iid: params[:iids]) : items
|
||||
end
|
||||
|
||||
def sort(items)
|
||||
|
|
|
@ -26,10 +26,6 @@ class IssuesFinder < IssuableFinder
|
|||
IssuesFinder.not_restricted_by_confidentiality(current_user)
|
||||
end
|
||||
|
||||
def iid_pattern
|
||||
@iid_pattern ||= %r{\A#{Regexp.escape(Issue.reference_prefix)}(?<iid>\d+)\z}
|
||||
end
|
||||
|
||||
def self.not_restricted_by_confidentiality(user)
|
||||
return Issue.where('issues.confidential IS NULL OR issues.confidential IS FALSE') if user.blank?
|
||||
|
||||
|
|
|
@ -20,14 +20,4 @@ class MergeRequestsFinder < IssuableFinder
|
|||
def klass
|
||||
MergeRequest
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def iid_pattern
|
||||
@iid_pattern ||= %r{\A[
|
||||
#{Regexp.escape(MergeRequest.reference_prefix)}
|
||||
#{Regexp.escape(Issue.reference_prefix)}
|
||||
](?<iid>\d+)\z
|
||||
}x
|
||||
end
|
||||
end
|
||||
|
|
4
changelogs/unreleased/26379-iid-param.yml
Normal file
4
changelogs/unreleased/26379-iid-param.yml
Normal file
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
title: add :iids param to IssuableFinder (resolve technical dept)
|
||||
merge_request: 9222
|
||||
author: mhasbini
|
|
@ -16,7 +16,8 @@ module API
|
|||
labels = args.delete(:labels)
|
||||
args[:label_name] = labels if match_all_labels
|
||||
|
||||
args[:search] = "#{Issue.reference_prefix}#{args.delete(:iid)}" if args.key?(:iid)
|
||||
# IssuesFinder expects iids
|
||||
args[:iids] = args.delete(:iid) if args.key?(:iid)
|
||||
|
||||
issues = IssuesFinder.new(current_user, args).execute.inc_notes_with_associations
|
||||
|
||||
|
|
|
@ -136,10 +136,10 @@ describe IssuesFinder do
|
|||
end
|
||||
end
|
||||
|
||||
context 'filtering by issue iid' do
|
||||
let(:params) { { search: issue3.to_reference } }
|
||||
context 'filtering by issues iids' do
|
||||
let(:params) { { iids: issue3.iid } }
|
||||
|
||||
it 'returns issue with iid match' do
|
||||
it 'returns issues with iids match' do
|
||||
expect(issues).to contain_exactly(issue3)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -38,5 +38,13 @@ describe MergeRequestsFinder do
|
|||
merge_requests = MergeRequestsFinder.new(user, params).execute
|
||||
expect(merge_requests.size).to eq(3)
|
||||
end
|
||||
|
||||
it 'filters by iid' do
|
||||
params = { project_id: project1.id, iids: merge_request1.iid }
|
||||
|
||||
merge_requests = MergeRequestsFinder.new(user, params).execute
|
||||
|
||||
expect(merge_requests).to contain_exactly(merge_request1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue