summaryrefslogtreecommitdiff
path: root/app/models/environment_status.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/environment_status.rb')
-rw-r--r--app/models/environment_status.rb27
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