Skip to content

Commit

Permalink
Outsource the picking of workflow failures to show
Browse files Browse the repository at this point in the history
This way we can actually write test cases for the picking

Fixes #8851
  • Loading branch information
coolo authored and Dany Marcoux committed Dec 12, 2019
1 parent 445eff2 commit 539cc89
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 14 deletions.
14 changes: 14 additions & 0 deletions src/api/app/helpers/webui/webui_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -341,5 +341,19 @@ def gravatar_icon(email, size)
def home_title
@configuration ? @configuration['title'] : 'Open Build Service'
end

def pick_max_problems(remaining_checks, remaining_build_problems, max_shown)
show_checks = [max_shown, remaining_checks.length].min
show_builds = [max_shown - show_checks, remaining_build_problems.length].min
# always prefer one build fail
if show_builds == 0 && remaining_build_problems.present?
show_builds += 1
show_checks -= 1
end

checks = remaining_checks.shift(show_checks)
build_problems = remaining_build_problems.shift(show_builds)
return checks, build_problems, remaining_checks, remaining_build_problems
end
end
# rubocop:enable Metrics/ModuleLength
25 changes: 11 additions & 14 deletions src/api/app/views/webui/staging/workflows/_problems.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,27 @@
max_shown = 5
project_class = staging_project.name.tr(':.', '_')
item_project_class = 'hidden-item-' + project_class
checks_problems = staging_project.checks.failed
build_problems = merge_broken_packages(staging_project.broken_packages)
total_problems = checks_problems.length + build_problems.length
checks, build_problems, remaining_checks, remaining_build_problems =
pick_max_problems(staging_project.checks.failed.to_a, build_problems, max_shown)

- if total_problems == 0
- if checks.empty? && build_problems.empty?
.text-center
%i.fas.fa-check-circle.text-success
- else
:ruby
rendered_checks_problems = [max_shown - 1, checks_problems.length].min
rendered_build_problems = max_shown - rendered_checks_problems
%ul.list-group.list-group-flush
- checks_problems[0..(rendered_checks_problems - 1)].each do |check|
- checks.each do |check|
= render partial: 'status_problems', locals: { check: check }
- build_problems[0..(rendered_build_problems - 1)].each do |name, states|
- build_problems.each do |name, states|
= render partial: 'build_problems', locals: { name: name, states: states, staging_project: staging_project }
- if total_problems > max_shown
- number = total_problems - max_shown
- remain_count = remaining_checks.length + remaining_build_problems.length
- if remain_count > 0
%span.collapse{ 'id': item_project_class }
- checks_problems[rendered_checks_problems..-1].each do |check|
- remaining_checks.each do |check|
= render partial: 'status_problems', locals: { check: check }
- build_problems[rendered_build_problems..-1].each do |name, states|
- remaining_build_problems.each do |name, states|
= render partial: 'build_problems', locals: { name: name, states: states, staging_project: staging_project }
%li.list-group-item.table-list-group-item
%a{ 'data-toggle': 'collapse', href: "##{item_project_class}", 'aria-expanded': 'false' }
%span.expander See #{number} more
%span.collapser See #{number} less
%span.expander See #{remain_count} more
%span.collapser See #{remain_count} less
33 changes: 33 additions & 0 deletions src/api/spec/helpers/webui/webui_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -248,4 +248,37 @@
it { expect(toggle_sliced_text(big_text)).to match(/(.+)#{sliced_text}(.+)\[\+\](.+)#{big_text}(.+)\[\-\](.+)/) }
end
end

describe '#pick_max_problems' do
let(:max_shown) { 5 }
subject { pick_max_problems(checks, builds, max_shown) }

context 'with no failed checks' do
let(:checks) { [] }

context 'with no fails' do
let(:builds) { [] }
it { is_expected.to eq([[], [], [], []]) }
end

context 'with 7 fails' do
let(:builds) { [1, 2, 3, 4, 5, 6, 7] }
it { is_expected.to eq([[], [1, 2, 3, 4, 5], [], [6, 7]]) }
end
end

context 'with 7 checks' do
let(:checks) { [1, 2, 3, 4, 5, 6, 7] }

context 'with no fails' do
let(:builds) { [] }
it { is_expected.to eq([[1, 2, 3, 4, 5], [], [6, 7], []]) }
end

context 'with 7 fails' do
let(:builds) { [1, 2, 3, 4, 5, 6, 7] }
it { is_expected.to eq([[1, 2, 3, 4], [1], [5, 6, 7], [2, 3, 4, 5, 6, 7]]) }
end
end
end
end

0 comments on commit 539cc89

Please sign in to comment.