diff options
author | Alessio Caiazza <acaiazza@gitlab.com> | 2018-10-09 18:17:40 +0200 |
---|---|---|
committer | Alessio Caiazza <acaiazza@gitlab.com> | 2018-10-18 16:12:16 +0200 |
commit | 4a9efc606f5cdd9cf3aa34991543eb2f77555914 (patch) | |
tree | 29bfd4a795c5a2f77f6b8d46804f2fc7e8a83bc6 /app/controllers/projects/merge_requests_controller.rb | |
parent | c09de611ea9d8cbff7a1696ee63262ef65972daa (diff) | |
download | gitlab-ce-4a9efc606f5cdd9cf3aa34991543eb2f77555914.tar.gz |
Move ci_environments_status to a model
GET :namespace/merge_requests/:id/ci_environments_status complexity
already reached a limit for a direct serialization from an hash
computed at within the controller function.
Here we introduce a virtual model EnvironmentStatus and its serializer.
Diffstat (limited to 'app/controllers/projects/merge_requests_controller.rb')
-rw-r--r-- | app/controllers/projects/merge_requests_controller.rb | 40 |
1 files changed, 4 insertions, 36 deletions
diff --git a/app/controllers/projects/merge_requests_controller.rb b/app/controllers/projects/merge_requests_controller.rb index 8bc3a81d771..f87337b67aa 100644 --- a/app/controllers/projects/merge_requests_controller.rb +++ b/app/controllers/projects/merge_requests_controller.rb @@ -198,43 +198,11 @@ class Projects::MergeRequestsController < Projects::MergeRequests::ApplicationCo end def ci_environments_status - environments = - begin - @merge_request.environments_for(current_user).map do |environment| - project = environment.project - deployment = environment.first_deployment_for(@merge_request.diff_head_sha) - - stop_url = - if can?(current_user, :stop_environment, environment) - stop_project_environment_path(project, environment) - end - - metrics_url = - if can?(current_user, :read_environment, environment) && environment.has_metrics? - metrics_project_environment_deployment_path(project, environment, deployment) - end - - metrics_monitoring_url = - if can?(current_user, :read_environment, environment) - environment_metrics_path(environment) - end - - { - id: environment.id, - name: environment.name, - url: project_environment_path(project, environment), - metrics_url: metrics_url, - metrics_monitoring_url: metrics_monitoring_url, - stop_url: stop_url, - external_url: environment.external_url, - external_url_formatted: environment.formatted_external_url, - deployed_at: deployment.try(:created_at), - deployed_at_formatted: deployment.try(:formatted_deployment_time) - } - end.compact - end + environments = @merge_request.environments_for(current_user).map do |environment| + EnvironmentStatus.new(environment, @merge_request) + end - render json: environments + render json: EnvironmentStatusSerializer.new(current_user: current_user).represent(environments) end def rebase |