2018-12-05 23:21:45 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
class Projects::DeploymentsController < Projects::ApplicationController
|
|
|
|
before_action :authorize_read_environment!
|
|
|
|
before_action :authorize_read_deployment!
|
|
|
|
|
2018-12-05 23:21:45 +05:30
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2017-08-17 22:00:37 +05:30
|
|
|
def index
|
|
|
|
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
|
2018-12-05 23:21:45 +05:30
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
def metrics
|
2019-09-30 21:07:59 +05:30
|
|
|
return render_404 unless deployment_metrics.has_metrics?
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
@metrics = deployment_metrics.metrics
|
2017-08-17 22:00:37 +05:30
|
|
|
if @metrics&.any?
|
|
|
|
render json: @metrics, status: :ok
|
|
|
|
else
|
|
|
|
head :no_content
|
|
|
|
end
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def additional_metrics
|
2019-09-30 21:07:59 +05:30
|
|
|
return render_404 unless deployment_metrics.has_metrics?
|
2017-09-10 17:25:29 +05:30
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.json do
|
2019-09-30 21:07:59 +05:30
|
|
|
metrics = deployment_metrics.additional_metrics
|
2017-09-10 17:25:29 +05:30
|
|
|
|
|
|
|
if metrics.any?
|
|
|
|
render json: metrics
|
|
|
|
else
|
|
|
|
head :no_content
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
def deployment_metrics
|
|
|
|
@deployment_metrics ||= DeploymentMetrics.new(deployment.project, deployment)
|
|
|
|
end
|
|
|
|
|
2018-12-05 23:21:45 +05:30
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2017-08-17 22:00:37 +05:30
|
|
|
def deployment
|
|
|
|
@deployment ||= environment.deployments.find_by(iid: params[:id])
|
|
|
|
end
|
2018-12-05 23:21:45 +05:30
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
def environment
|
|
|
|
@environment ||= project.environments.find(params[:environment_id])
|
|
|
|
end
|
|
|
|
end
|