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