debian-mirror-gitlab/app/services/ci/build_report_result_service.rb

57 lines
1.4 KiB
Ruby
Raw Normal View History

2020-06-23 00:09:42 +05:30
# frozen_string_literal: true
module Ci
class BuildReportResultService
2021-01-03 14:25:43 +05:30
include Gitlab::Utils::UsageData
EVENT_NAME = 'i_testing_test_case_parsed'
2020-06-23 00:09:42 +05:30
def execute(build)
return unless build.has_test_reports?
2021-01-03 14:25:43 +05:30
test_suite = generate_test_suite_report(build)
track_test_cases(build, test_suite)
2020-06-23 00:09:42 +05:30
build.report_results.create!(
project_id: build.project_id,
2021-01-03 14:25:43 +05:30
data: tests_params(test_suite)
2020-06-23 00:09:42 +05:30
)
end
private
def generate_test_suite_report(build)
build.collect_test_reports!(Gitlab::Ci::Reports::TestReports.new)
end
2021-01-03 14:25:43 +05:30
def tests_params(test_suite)
2020-06-23 00:09:42 +05:30
{
tests: {
name: test_suite.name,
duration: test_suite.total_time,
failed: test_suite.failed_count,
errored: test_suite.error_count,
skipped: test_suite.skipped_count,
success: test_suite.success_count
}
}
end
2021-01-03 14:25:43 +05:30
def track_test_cases(build, test_suite)
return if Feature.disabled?(:track_unique_test_cases_parsed, build.project)
track_usage_event(EVENT_NAME, test_case_hashes(build, test_suite))
end
def test_case_hashes(build, test_suite)
[].tap do |hashes|
test_suite.each_test_case do |test_case|
key = "#{build.project_id}-#{test_case.key}"
hashes << Digest::SHA256.hexdigest(key)
end
end
end
2020-06-23 00:09:42 +05:30
end
end