2020-06-19 14:08:39 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Projects
|
|
|
|
module Pipelines
|
2020-07-09 11:08:59 -04:00
|
|
|
class TestsController < Projects::Pipelines::ApplicationController
|
2020-06-19 14:08:39 -04:00
|
|
|
before_action :validate_feature_flag!
|
2020-07-09 11:08:59 -04:00
|
|
|
before_action :authorize_read_build!
|
|
|
|
before_action :builds, only: [:show]
|
2020-06-19 14:08:39 -04:00
|
|
|
|
|
|
|
def summary
|
|
|
|
respond_to do |format|
|
|
|
|
format.json do
|
2020-07-09 11:08:59 -04:00
|
|
|
render json: TestReportSummarySerializer
|
2020-06-19 14:08:39 -04:00
|
|
|
.new(project: project, current_user: @current_user)
|
|
|
|
.represent(pipeline.test_report_summary)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-07-09 11:08:59 -04:00
|
|
|
def show
|
|
|
|
respond_to do |format|
|
|
|
|
format.json do
|
|
|
|
render json: TestSuiteSerializer
|
|
|
|
.new(project: project, current_user: @current_user)
|
|
|
|
.represent(test_suite, details: true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-06-19 14:08:39 -04:00
|
|
|
private
|
|
|
|
|
|
|
|
def validate_feature_flag!
|
|
|
|
render_404 unless Feature.enabled?(:build_report_summary, project)
|
|
|
|
end
|
|
|
|
|
2020-07-09 11:08:59 -04:00
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
|
|
|
def builds
|
|
|
|
pipeline.latest_builds.where(id: build_params)
|
|
|
|
end
|
|
|
|
|
|
|
|
def build_params
|
|
|
|
return [] unless params[:build_ids]
|
|
|
|
|
|
|
|
params[:build_ids].split(",")
|
2020-06-19 14:08:39 -04:00
|
|
|
end
|
|
|
|
|
2020-07-09 11:08:59 -04:00
|
|
|
def test_suite
|
|
|
|
if builds.present?
|
|
|
|
builds.map do |build|
|
|
|
|
build.collect_test_reports!(Gitlab::Ci::Reports::TestReports.new)
|
|
|
|
end.sum
|
|
|
|
else
|
|
|
|
render_404
|
|
|
|
end
|
2020-06-19 14:08:39 -04:00
|
|
|
end
|
2020-07-09 11:08:59 -04:00
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2020-06-19 14:08:39 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|