diff options
author | Robert Speicher <robert@gitlab.com> | 2017-01-13 21:10:16 +0000 |
---|---|---|
committer | Robert Speicher <robert@gitlab.com> | 2017-01-13 21:10:16 +0000 |
commit | 77756efc22af33dd1cdb16671e39192d5761eaf6 (patch) | |
tree | 5ac74e671f31fbc7c1b6e20831bfeedda48e7771 | |
parent | e8538f7a42f63996cadfb124e9947c862cd86cb2 (diff) | |
parent | 0bc48797c8559a1f9c042b74e2faadc820fc7257 (diff) | |
download | gitlab-ce-77756efc22af33dd1cdb16671e39192d5761eaf6.tar.gz |
Merge branch 'fix-build-sort-order' into 'master'
Resolve "Sort order for pipeline build lists doesn't properly handle numbers"
Closes #25428
See merge request !8277
-rw-r--r-- | app/models/commit_status.rb | 6 | ||||
-rw-r--r-- | app/views/projects/stage/_graph.html.haml | 2 | ||||
-rw-r--r-- | changelogs/unreleased/fix-build-sort-order.yml | 4 | ||||
-rw-r--r-- | spec/models/commit_status_spec.rb | 19 |
4 files changed, 30 insertions, 1 deletions
diff --git a/app/models/commit_status.rb b/app/models/commit_status.rb index 31cd381dcd2..9547c57b2ae 100644 --- a/app/models/commit_status.rb +++ b/app/models/commit_status.rb @@ -137,4 +137,10 @@ class CommitStatus < ActiveRecord::Base .new(self, current_user) .fabricate! end + + def sortable_name + name.split(/(\d+)/).map do |v| + v =~ /\d+/ ? v.to_i : v + end + end end diff --git a/app/views/projects/stage/_graph.html.haml b/app/views/projects/stage/_graph.html.haml index d9d392fa02f..4ee30b023ac 100644 --- a/app/views/projects/stage/_graph.html.haml +++ b/app/views/projects/stage/_graph.html.haml @@ -1,6 +1,6 @@ - stage = local_assigns.fetch(:stage) - statuses = stage.statuses.latest -- status_groups = statuses.sort_by(&:name).group_by(&:group_name) +- status_groups = statuses.sort_by(&:sortable_name).group_by(&:group_name) %li.stage-column .stage-name %a{ name: stage.name } diff --git a/changelogs/unreleased/fix-build-sort-order.yml b/changelogs/unreleased/fix-build-sort-order.yml new file mode 100644 index 00000000000..a6d6371f69a --- /dev/null +++ b/changelogs/unreleased/fix-build-sort-order.yml @@ -0,0 +1,4 @@ +--- +title: Sort numbers in build names more intelligently +merge_request: 8277 +author: diff --git a/spec/models/commit_status_spec.rb b/spec/models/commit_status_spec.rb index 701f3323c0f..64ea607eb95 100644 --- a/spec/models/commit_status_spec.rb +++ b/spec/models/commit_status_spec.rb @@ -243,4 +243,23 @@ describe CommitStatus, models: true do .to be_a Gitlab::Ci::Status::Success end end + + describe '#sortable_name' do + tests = { + 'karma' => ['karma'], + 'karma 0 20' => ['karma ', 0, ' ', 20], + 'karma 10 20' => ['karma ', 10, ' ', 20], + 'karma 50:100' => ['karma ', 50, ':', 100], + 'karma 1.10' => ['karma ', 1, '.', 10], + 'karma 1.5.1' => ['karma ', 1, '.', 5, '.', 1], + 'karma 1 a' => ['karma ', 1, ' a'] + } + + tests.each do |name, sortable_name| + it "'#{name}' sorts as '#{sortable_name}'" do + commit_status.name = name + expect(commit_status.sortable_name).to eq(sortable_name) + end + end + end end |