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/models/environment_status.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/models/environment_status.rb')
-rw-r--r-- | app/models/environment_status.rb | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/app/models/environment_status.rb b/app/models/environment_status.rb new file mode 100644 index 00000000000..cae0d396089 --- /dev/null +++ b/app/models/environment_status.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +class EnvironmentStatus + include Gitlab::Utils::StrongMemoize + + attr_reader :environment, :merge_request + + delegate :id, to: :environment + delegate :name, to: :environment + delegate :project, to: :environment + delegate :deployed_at, to: :deployment, allow_nil: true + + def initialize(environment, merge_request) + @environment = environment + @merge_request = merge_request + end + + def deployment + strong_memoize(:deployment) do + environment.first_deployment_for(merge_request.diff_head_sha) + end + end + + def deployed_at + deployment&.created_at + end +end |