diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-20 17:34:42 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-20 17:34:42 +0300 |
commit | 9f46488805e86b1bc341ea1620b866016c2ce5ed (patch) | |
tree | f9748c7e287041e37d6da49e0a29c9511dc34768 /lib/gitlab/ci/reports | |
parent | dfc92d081ea0332d69c8aca2f0e745cb48ae5e6d (diff) |
Add latest changes from gitlab-org/gitlab@13-0-stable-ee
Diffstat (limited to 'lib/gitlab/ci/reports')
-rw-r--r-- | lib/gitlab/ci/reports/accessibility_reports.rb | 46 | ||||
-rw-r--r-- | lib/gitlab/ci/reports/accessibility_reports_comparer.rb | 55 | ||||
-rw-r--r-- | lib/gitlab/ci/reports/terraform_reports.rb | 27 | ||||
-rw-r--r-- | lib/gitlab/ci/reports/test_reports.rb | 6 | ||||
-rw-r--r-- | lib/gitlab/ci/reports/test_suite.rb | 19 |
5 files changed, 150 insertions, 3 deletions
diff --git a/lib/gitlab/ci/reports/accessibility_reports.rb b/lib/gitlab/ci/reports/accessibility_reports.rb new file mode 100644 index 00000000000..1901ba3b102 --- /dev/null +++ b/lib/gitlab/ci/reports/accessibility_reports.rb @@ -0,0 +1,46 @@ +# frozen_string_literal: true + +module Gitlab + module Ci + module Reports + class AccessibilityReports + attr_reader :urls, :error_message + + def initialize + @urls = {} + @error_message = nil + end + + def add_url(url, data) + if url.empty? + set_error_message("Empty URL detected in gl-accessibility.json") + else + urls[url] = data + end + end + + def scans_count + @urls.size + end + + def passes_count + @urls.count { |url, errors| errors.empty? } + end + + # rubocop: disable CodeReuse/ActiveRecord + def errors_count + @urls.sum { |url, errors| errors.size } + end + # rubocop: enable CodeReuse/ActiveRecord + + def set_error_message(error) + @error_message = error + end + + def all_errors + @urls.values.flatten + end + end + end + end +end diff --git a/lib/gitlab/ci/reports/accessibility_reports_comparer.rb b/lib/gitlab/ci/reports/accessibility_reports_comparer.rb new file mode 100644 index 00000000000..fa6337166d5 --- /dev/null +++ b/lib/gitlab/ci/reports/accessibility_reports_comparer.rb @@ -0,0 +1,55 @@ +# frozen_string_literal: true + +module Gitlab + module Ci + module Reports + class AccessibilityReportsComparer + include Gitlab::Utils::StrongMemoize + + STATUS_SUCCESS = 'success' + STATUS_FAILED = 'failed' + + attr_reader :base_reports, :head_reports + + def initialize(base_reports, head_reports) + @base_reports = base_reports || AccessibilityReports.new + @head_reports = head_reports + end + + def status + head_reports.errors_count.positive? ? STATUS_FAILED : STATUS_SUCCESS + end + + def existing_errors + strong_memoize(:existing_errors) do + base_reports.all_errors + end + end + + def new_errors + strong_memoize(:new_errors) do + head_reports.all_errors - base_reports.all_errors + end + end + + def resolved_errors + strong_memoize(:resolved_errors) do + base_reports.all_errors - head_reports.all_errors + end + end + + def errors_count + head_reports.errors_count + end + + def resolved_count + resolved_errors.size + end + + def total_count + existing_errors.size + new_errors.size + end + end + end + end +end diff --git a/lib/gitlab/ci/reports/terraform_reports.rb b/lib/gitlab/ci/reports/terraform_reports.rb new file mode 100644 index 00000000000..f955d007daf --- /dev/null +++ b/lib/gitlab/ci/reports/terraform_reports.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +module Gitlab + module Ci + module Reports + class TerraformReports + attr_reader :plans + + def initialize + @plans = {} + end + + def pick(keys) + terraform_plans = plans.select do |key| + keys.include?(key) + end + + { plans: terraform_plans } + end + + def add_plan(name, plan) + plans[name] = plan + end + end + end + end +end diff --git a/lib/gitlab/ci/reports/test_reports.rb b/lib/gitlab/ci/reports/test_reports.rb index 72323c4343d..86ba725c71e 100644 --- a/lib/gitlab/ci/reports/test_reports.rb +++ b/lib/gitlab/ci/reports/test_reports.rb @@ -42,6 +42,12 @@ module Gitlab self end + def suite_errors + test_suites.each_with_object({}) do |(name, suite), errors| + errors[suite.name] = suite.suite_error if suite.suite_error + end + end + TestCase::STATUS_TYPES.each do |status_type| define_method("#{status_type}_count") do # rubocop: disable CodeReuse/ActiveRecord diff --git a/lib/gitlab/ci/reports/test_suite.rb b/lib/gitlab/ci/reports/test_suite.rb index cf43c5313c0..8bbf2e0f6cf 100644 --- a/lib/gitlab/ci/reports/test_suite.rb +++ b/lib/gitlab/ci/reports/test_suite.rb @@ -7,6 +7,7 @@ module Gitlab attr_reader :name attr_reader :test_cases attr_reader :total_time + attr_reader :suite_error def initialize(name = nil) @name = name @@ -25,12 +26,16 @@ module Gitlab # rubocop: disable CodeReuse/ActiveRecord def total_count + return 0 if suite_error + test_cases.values.sum(&:count) end # rubocop: enable CodeReuse/ActiveRecord def total_status - if failed_count > 0 || error_count > 0 + if suite_error + TestCase::STATUS_ERROR + elsif failed_count > 0 || error_count > 0 TestCase::STATUS_FAILED else TestCase::STATUS_SUCCESS @@ -49,14 +54,22 @@ module Gitlab TestCase::STATUS_TYPES.each do |status_type| define_method("#{status_type}") do - test_cases[status_type] || {} + return {} if suite_error || test_cases[status_type].nil? + + test_cases[status_type] end define_method("#{status_type}_count") do - test_cases[status_type]&.length.to_i + return 0 if suite_error || test_cases[status_type].nil? + + test_cases[status_type].length end end + def set_suite_error(msg) + @suite_error = msg + end + private def existing_key?(test_case) |