From a15fe2a1ac3f45556220b5fb4a22ea3c1aa0c5a3 Mon Sep 17 00:00:00 2001 From: Kamil Trzcinski Date: Tue, 7 Mar 2017 11:48:01 +0100 Subject: Sort builds in stage dropdown Order: failed pending running manual canceled success skipped created --- app/models/concerns/has_status.rb | 2 +- app/views/projects/pipelines/_stage.html.haml | 8 +++++--- .../unreleased/sort-builds-in-stage-dropdown.yml | 4 ++++ .../views/projects/pipelines/_stage.html.haml_spec.rb | 19 +++++++++++++++++++ 4 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 changelogs/unreleased/sort-builds-in-stage-dropdown.yml diff --git a/app/models/concerns/has_status.rb b/app/models/concerns/has_status.rb index b819947c9e6..5101cc7e687 100644 --- a/app/models/concerns/has_status.rb +++ b/app/models/concerns/has_status.rb @@ -7,7 +7,7 @@ module HasStatus STARTED_STATUSES = %w[running success failed skipped manual].freeze ACTIVE_STATUSES = %w[pending running].freeze COMPLETED_STATUSES = %w[success failed canceled skipped].freeze - ORDERED_STATUSES = %w[manual failed pending running canceled success skipped].freeze + ORDERED_STATUSES = %w[failed pending running manual canceled success skipped created].freeze class_methods do def status_sql diff --git a/app/views/projects/pipelines/_stage.html.haml b/app/views/projects/pipelines/_stage.html.haml index a0b14a7274a..3feb99cfcd7 100644 --- a/app/views/projects/pipelines/_stage.html.haml +++ b/app/views/projects/pipelines/_stage.html.haml @@ -1,3 +1,5 @@ -- @stage.statuses.latest.each do |status| - %li - = render 'ci/status/dropdown_graph_badge', subject: status +- grouped_statuses = @stage.statuses.latest_ordered.group_by(&:status) +- HasStatus::ORDERED_STATUSES.each do |ordered_status| + - grouped_statuses.fetch(ordered_status, []).each do |status| + %li + = render 'ci/status/dropdown_graph_badge', subject: status diff --git a/changelogs/unreleased/sort-builds-in-stage-dropdown.yml b/changelogs/unreleased/sort-builds-in-stage-dropdown.yml new file mode 100644 index 00000000000..646f25125b1 --- /dev/null +++ b/changelogs/unreleased/sort-builds-in-stage-dropdown.yml @@ -0,0 +1,4 @@ +--- +title: Sort builds in stage dropdown +merge_request: +author: diff --git a/spec/views/projects/pipelines/_stage.html.haml_spec.rb b/spec/views/projects/pipelines/_stage.html.haml_spec.rb index d25de8af5d2..b168630907a 100644 --- a/spec/views/projects/pipelines/_stage.html.haml_spec.rb +++ b/spec/views/projects/pipelines/_stage.html.haml_spec.rb @@ -50,4 +50,23 @@ describe 'projects/pipelines/_stage', :view do expect(rendered).to have_text 'test:build', count: 1 end end + + context 'when there are multiple builds' do + before do + HasStatus::AVAILABLE_STATUSES.each do |status| + create_build(status) + end + end + + it 'shows them in order' do + render + + expect(rendered).to have_text(HasStatus::ORDERED_STATUSES.join(" ")) + end + + def create_build(status) + create(:ci_build, name: status, status: status, + pipeline: pipeline, stage: stage.name) + end + end end -- cgit v1.2.1