gitlab-org--gitlab-foss/app/controllers/projects/deployments_controller.rb

57 lines
1.4 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
class Projects::DeploymentsController < Projects::ApplicationController
before_action :authorize_read_deployment!
# rubocop: disable CodeReuse/ActiveRecord
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
render json: { deployments: DeploymentSerializer.new(project: project)
.represent_concise(deployments) }
end
# rubocop: enable CodeReuse/ActiveRecord
2017-05-09 00:15:34 -04:00
def metrics
return render_404 unless deployment_metrics.has_metrics?
@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
return render_404 unless deployment_metrics.has_metrics?
respond_to do |format|
format.json do
metrics = deployment_metrics.additional_metrics
if metrics.any?
render json: metrics
else
head :no_content
end
end
2017-05-25 11:39:43 -04:00
end
end
private
def deployment_metrics
@deployment_metrics ||= DeploymentMetrics.new(deployment.project, deployment)
end
2017-05-09 00:15:34 -04:00
def deployment
@deployment ||= environment.deployments.find_successful_deployment!(params[:id])
2017-05-09 00:15:34 -04:00
end
def environment
@environment ||= project.environments.find(params[:environment_id])
end
end