diff options
author | mhasbini <mohammad.hasbini@gmail.com> | 2017-02-17 21:28:32 +0300 |
---|---|---|
committer | mhasbini <mohammad.hasbini@gmail.com> | 2017-02-17 21:28:32 +0300 |
commit | 7362fd6fdf4704314acbe9760a329ffe23337af0 (patch) | |
tree | 194114ab4f6776712d47a0da19d992c5d02e2df5 | |
parent | 827a56a47914f128a78deade463d589328d18fc1 (diff) |
add a :iids param to IssuableFinder
-rw-r--r-- | app/finders/issuable_finder.rb | 15 | ||||
-rw-r--r-- | app/finders/issues_finder.rb | 4 | ||||
-rw-r--r-- | app/finders/merge_requests_finder.rb | 10 | ||||
-rw-r--r-- | changelogs/unreleased/26379-iid-param.yml | 4 | ||||
-rw-r--r-- | lib/api/v3/issues.rb | 3 | ||||
-rw-r--r-- | spec/finders/issues_finder_spec.rb | 6 | ||||
-rw-r--r-- | spec/finders/merge_requests_finder_spec.rb | 8 |
7 files changed, 23 insertions, 27 deletions
diff --git a/app/finders/issuable_finder.rb b/app/finders/issuable_finder.rb index 1576fc80a6b..206c92fe82a 100644 --- a/app/finders/issuable_finder.rb +++ b/app/finders/issuable_finder.rb @@ -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) diff --git a/app/finders/issues_finder.rb b/app/finders/issues_finder.rb index 707eddd4d29..f542f72a386 100644 --- a/app/finders/issues_finder.rb +++ b/app/finders/issues_finder.rb @@ -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? diff --git a/app/finders/merge_requests_finder.rb b/app/finders/merge_requests_finder.rb index 8b82255445e..b76ca389f38 100644 --- a/app/finders/merge_requests_finder.rb +++ b/app/finders/merge_requests_finder.rb @@ -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 diff --git a/changelogs/unreleased/26379-iid-param.yml b/changelogs/unreleased/26379-iid-param.yml new file mode 100644 index 00000000000..ac743e68d6f --- /dev/null +++ b/changelogs/unreleased/26379-iid-param.yml @@ -0,0 +1,4 @@ +--- +title: add :iids param to IssuableFinder (resolve technical dept) +merge_request: 9222 +author: mhasbini diff --git a/lib/api/v3/issues.rb b/lib/api/v3/issues.rb index 081d45165e8..ba5b6fdbe52 100644 --- a/lib/api/v3/issues.rb +++ b/lib/api/v3/issues.rb @@ -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 diff --git a/spec/finders/issues_finder_spec.rb b/spec/finders/issues_finder_spec.rb index 12ab1d6dde8..2a008427478 100644 --- a/spec/finders/issues_finder_spec.rb +++ b/spec/finders/issues_finder_spec.rb @@ -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 diff --git a/spec/finders/merge_requests_finder_spec.rb b/spec/finders/merge_requests_finder_spec.rb index 3dcd7781e5b..21ef94ac5d1 100644 --- a/spec/finders/merge_requests_finder_spec.rb +++ b/spec/finders/merge_requests_finder_spec.rb @@ -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 |