2018-09-25 23:45:43 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-03-27 05:22:43 -04:00
|
|
|
class Projects::DeploymentsController < Projects::ApplicationController
|
|
|
|
before_action :authorize_read_deployment!
|
|
|
|
|
2020-10-08 14:08:32 -04:00
|
|
|
feature_category :continuous_delivery
|
|
|
|
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2017-03-27 05:22:43 -04:00
|
|
|
def index
|
2017-03-28 08:56:30 -04:00
|
|
|
deployments = environment.deployments.reorder(created_at: :desc)
|
|
|
|
deployments = deployments.where('created_at > ?', params[:after].to_time) if params[:after]&.to_time
|
2017-03-27 05:22:43 -04:00
|
|
|
|
2017-05-10 14:21:31 -04:00
|
|
|
render json: { deployments: DeploymentSerializer.new(project: project)
|
2017-04-24 16:34:36 -04:00
|
|
|
.represent_concise(deployments) }
|
2017-03-27 05:22:43 -04:00
|
|
|
end
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2017-03-27 05:22:43 -04:00
|
|
|
|
2017-05-09 00:15:34 -04:00
|
|
|
def metrics
|
2019-07-01 05:40:59 -04:00
|
|
|
return render_404 unless deployment_metrics.has_metrics?
|
2017-11-14 04:02:39 -05:00
|
|
|
|
2019-07-01 05:40:59 -04:00
|
|
|
@metrics = deployment_metrics.metrics
|
2017-05-09 00:15:34 -04:00
|
|
|
if @metrics&.any?
|
|
|
|
render json: @metrics, status: :ok
|
|
|
|
else
|
|
|
|
head :no_content
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-05-25 11:39:43 -04:00
|
|
|
def additional_metrics
|
2019-07-01 05:40:59 -04:00
|
|
|
return render_404 unless deployment_metrics.has_metrics?
|
2017-06-06 08:40:03 -04:00
|
|
|
|
2017-06-20 09:53:05 -04:00
|
|
|
respond_to do |format|
|
|
|
|
format.json do
|
2019-07-01 05:40:59 -04:00
|
|
|
metrics = deployment_metrics.additional_metrics
|
2017-06-20 09:53:05 -04:00
|
|
|
|
|
|
|
if metrics.any?
|
|
|
|
render json: metrics
|
|
|
|
else
|
|
|
|
head :no_content
|
|
|
|
end
|
|
|
|
end
|
2017-05-25 11:39:43 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-03-27 05:22:43 -04:00
|
|
|
private
|
|
|
|
|
2019-07-01 05:40:59 -04:00
|
|
|
def deployment_metrics
|
|
|
|
@deployment_metrics ||= DeploymentMetrics.new(deployment.project, deployment)
|
|
|
|
end
|
|
|
|
|
2017-05-09 00:15:34 -04:00
|
|
|
def deployment
|
2019-10-16 14:08:01 -04:00
|
|
|
@deployment ||= environment.deployments.find_successful_deployment!(params[:id])
|
2017-05-09 00:15:34 -04:00
|
|
|
end
|
|
|
|
|
2017-03-27 05:22:43 -04:00
|
|
|
def environment
|
|
|
|
@environment ||= project.environments.find(params[:environment_id])
|
|
|
|
end
|
|
|
|
end
|