summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean McGivern <sean@mcgivern.me.uk>2018-02-13 14:39:09 +0000
committerSean McGivern <sean@mcgivern.me.uk>2018-02-13 14:39:09 +0000
commit16908f9718820dd651faa61396fedb997d10eadd (patch)
tree0137c0898875262caa4f541883f84970ce20a22c
parentde67c5972084847c1517d1cf9e347cdb39a1a1ae (diff)
parent9abbe3cc860f5838df76405e59830efdacb07047 (diff)
downloadgitlab-ce-16908f9718820dd651faa61396fedb997d10eadd.tar.gz
Merge branch '26466-natural-sort-mrs' into 'master'
Group MR numbers on issue show page by project and namespace Closes #26466 See merge request gitlab-org/gitlab-ce!8494
-rw-r--r--app/controllers/projects/issues_controller.rb3
-rw-r--r--app/services/issues/fetch_referenced_merge_requests_service.rb12
-rw-r--r--changelogs/unreleased/26466-natural-sort-mrs.yml4
-rw-r--r--spec/services/issues/fetch_referenced_merge_requests_service_spec.rb35
4 files changed, 52 insertions, 2 deletions
diff --git a/app/controllers/projects/issues_controller.rb b/app/controllers/projects/issues_controller.rb
index 515cb08f1fc..33fced99132 100644
--- a/app/controllers/projects/issues_controller.rb
+++ b/app/controllers/projects/issues_controller.rb
@@ -122,8 +122,7 @@ class Projects::IssuesController < Projects::ApplicationController
end
def referenced_merge_requests
- @merge_requests = @issue.referenced_merge_requests(current_user)
- @closed_by_merge_requests = @issue.closed_by_merge_requests(current_user)
+ @merge_requests, @closed_by_merge_requests = ::Issues::FetchReferencedMergeRequestsService.new(project, current_user).execute(issue)
respond_to do |format|
format.json do
diff --git a/app/services/issues/fetch_referenced_merge_requests_service.rb b/app/services/issues/fetch_referenced_merge_requests_service.rb
new file mode 100644
index 00000000000..39c8ded9df4
--- /dev/null
+++ b/app/services/issues/fetch_referenced_merge_requests_service.rb
@@ -0,0 +1,12 @@
+module Issues
+ class FetchReferencedMergeRequestsService < Issues::BaseService
+ def execute(issue)
+ referenced_merge_requests = issue.referenced_merge_requests(current_user)
+ referenced_merge_requests = Gitlab::IssuableSorter.sort(project, referenced_merge_requests) { |i| i.iid.to_s }
+ closed_by_merge_requests = issue.closed_by_merge_requests(current_user)
+ closed_by_merge_requests = Gitlab::IssuableSorter.sort(project, closed_by_merge_requests) { |i| i.iid.to_s }
+
+ [referenced_merge_requests, closed_by_merge_requests]
+ end
+ end
+end
diff --git a/changelogs/unreleased/26466-natural-sort-mrs.yml b/changelogs/unreleased/26466-natural-sort-mrs.yml
new file mode 100644
index 00000000000..e3bf9834f24
--- /dev/null
+++ b/changelogs/unreleased/26466-natural-sort-mrs.yml
@@ -0,0 +1,4 @@
+---
+title: Group MRs on issue page by project and namespace.
+merge_request: 8494
+author: Jeff Stubler
diff --git a/spec/services/issues/fetch_referenced_merge_requests_service_spec.rb b/spec/services/issues/fetch_referenced_merge_requests_service_spec.rb
new file mode 100644
index 00000000000..4e58179f45f
--- /dev/null
+++ b/spec/services/issues/fetch_referenced_merge_requests_service_spec.rb
@@ -0,0 +1,35 @@
+require 'spec_helper.rb'
+
+describe Issues::FetchReferencedMergeRequestsService do
+ let(:project) { create(:project) }
+ let(:issue) { create(:issue, project: project) }
+ let(:other_project) { create(:project) }
+
+ let(:mr) { create(:merge_request, source_project: project, target_project: project, id: 2)}
+ let(:other_mr) { create(:merge_request, source_project: other_project, target_project: other_project, id: 1)}
+
+ let(:user) { create(:user) }
+ let(:service) { described_class.new(project, user) }
+
+ context 'with mentioned merge requests' do
+ it 'returns a list of sorted merge requests' do
+ allow(issue).to receive(:referenced_merge_requests).with(user).and_return([other_mr, mr])
+
+ mrs, closed_by_mrs = service.execute(issue)
+
+ expect(mrs).to match_array([mr, other_mr])
+ expect(closed_by_mrs).to match_array([])
+ end
+ end
+
+ context 'with closed-by merge requests' do
+ it 'returns a list of sorted merge requests' do
+ allow(issue).to receive(:closed_by_merge_requests).with(user).and_return([other_mr, mr])
+
+ mrs, closed_by_mrs = service.execute(issue)
+
+ expect(mrs).to match_array([])
+ expect(closed_by_mrs).to match_array([mr, other_mr])
+ end
+ end
+end