2020-07-28 23:09:34 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Projects
|
|
|
|
module Pipelines
|
|
|
|
class TestsController < Projects::Pipelines::ApplicationController
|
2022-06-21 17:19:12 +05:30
|
|
|
urgency :low, [:show, :summary]
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
before_action :authorize_read_build!
|
|
|
|
before_action :builds, only: [:show]
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
feature_category :code_testing
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
def summary
|
|
|
|
respond_to do |format|
|
|
|
|
format.json do
|
|
|
|
render json: TestReportSummarySerializer
|
|
|
|
.new(project: project, current_user: @current_user)
|
|
|
|
.represent(pipeline.test_report_summary)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
|
|
|
respond_to do |format|
|
|
|
|
format.json do
|
2022-07-23 23:45:48 +05:30
|
|
|
if pipeline.has_expired_test_reports?
|
2022-06-21 17:19:12 +05:30
|
|
|
render json: { errors: 'Test report artifacts have expired' }, status: :not_found
|
|
|
|
else
|
|
|
|
render json: TestSuiteSerializer
|
|
|
|
.new(project: project, current_user: @current_user)
|
|
|
|
.represent(test_suite, details: true)
|
|
|
|
end
|
2020-07-28 23:09:34 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def builds
|
2021-04-17 20:07:23 +05:30
|
|
|
@builds ||= pipeline.latest_builds.id_in(build_ids).presence || render_404
|
2020-07-28 23:09:34 +05:30
|
|
|
end
|
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
def build_ids
|
2020-07-28 23:09:34 +05:30
|
|
|
return [] unless params[:build_ids]
|
|
|
|
|
|
|
|
params[:build_ids].split(",")
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_suite
|
2022-05-07 20:08:51 +05:30
|
|
|
suite = builds.sum do |build|
|
2020-10-24 23:57:45 +05:30
|
|
|
build.collect_test_reports!(Gitlab::Ci::Reports::TestReports.new)
|
2022-05-07 20:08:51 +05:30
|
|
|
end
|
2021-03-11 19:13:27 +05:30
|
|
|
|
|
|
|
Gitlab::Ci::Reports::TestFailureHistory.new(suite.failed.values, project).load!
|
|
|
|
|
|
|
|
suite
|
2020-07-28 23:09:34 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|