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
|
2017-04-24 19:34:21 +00:00
|
|
|
before_action :authorize_read_environment!
|
2017-03-27 09:22:43 +00:00
|
|
|
before_action :authorize_read_deployment!
|
|
|
|
|
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
|
2017-05-12 16:16:22 +00:00
|
|
|
return render_404 unless deployment.has_metrics?
|
2017-11-14 09:02:39 +00:00
|
|
|
|
2017-04-26 20:09:03 +00:00
|
|
|
@metrics = deployment.metrics
|
2017-05-09 04:15:34 +00:00
|
|
|
if @metrics&.any?
|
|
|
|
render json: @metrics, status: :ok
|
|
|
|
else
|
|
|
|
head :no_content
|
|
|
|
end
|
2017-05-12 16:16:22 +00:00
|
|
|
rescue NotImplementedError
|
|
|
|
render_404
|
2017-05-09 04:15:34 +00:00
|
|
|
end
|
|
|
|
|
2017-05-25 15:39:43 +00:00
|
|
|
def additional_metrics
|
2018-02-23 20:33:33 +00:00
|
|
|
return render_404 unless deployment.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
|
|
|
|
metrics = deployment.additional_metrics
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2018-08-27 15:31:01 +00:00
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2017-05-09 04:15:34 +00:00
|
|
|
def deployment
|
|
|
|
@deployment ||= environment.deployments.find_by(iid: params[:id])
|
|
|
|
end
|
2018-08-27 15:31:01 +00:00
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2017-05-09 04:15:34 +00:00
|
|
|
|
2017-03-27 09:22:43 +00:00
|
|
|
def environment
|
|
|
|
@environment ||= project.environments.find(params[:environment_id])
|
|
|
|
end
|
|
|
|
end
|