summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorSean McGivern <sean@mcgivern.me.uk>2017-04-26 09:40:12 +0000
committerSean McGivern <sean@mcgivern.me.uk>2017-04-26 09:40:12 +0000
commit3ff8d8020e495df319f0b0921bc94b1c3470f6f0 (patch)
tree088b1e58e8eba3aad4ee45e19993897eb2cf5b4f /lib
parentf2da2df43a6901061a7e6b861c79025644d3b469 (diff)
parenta78eeefd6e76c956751a2a7f03efeaee28f83b46 (diff)
downloadgitlab-ce-3ff8d8020e495df319f0b0921bc94b1c3470f6f0.tar.gz
Merge branch '20378-natural-sort-issue-numbers' into 'master'
Change issues sentence to use natural sorting Closes #20378 See merge request !7110
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/issuable_sorter.rb29
1 files changed, 29 insertions, 0 deletions
diff --git a/lib/gitlab/issuable_sorter.rb b/lib/gitlab/issuable_sorter.rb
new file mode 100644
index 00000000000..d392214867a
--- /dev/null
+++ b/lib/gitlab/issuable_sorter.rb
@@ -0,0 +1,29 @@
+module Gitlab
+ module IssuableSorter
+ class << self
+ def sort(project, issuables, &sort_key)
+ grouped_items = issuables.group_by do |issuable|
+ if issuable.project.id == project.id
+ :project_ref
+ elsif issuable.project.namespace.id == project.namespace.id
+ :namespace_ref
+ else
+ :full_ref
+ end
+ end
+
+ natural_sort_issuables(grouped_items[:project_ref], project) +
+ natural_sort_issuables(grouped_items[:namespace_ref], project) +
+ natural_sort_issuables(grouped_items[:full_ref], project)
+ end
+
+ private
+
+ def natural_sort_issuables(issuables, project)
+ VersionSorter.sort(issuables || []) do |issuable|
+ issuable.to_reference(project)
+ end
+ end
+ end
+ end
+end