summaryrefslogtreecommitdiff
path: root/app/models/ci/stage.rb
diff options
context:
space:
mode:
authorKamil Trzcinski <ayufan@ayufan.eu>2016-12-18 23:43:13 +0100
committerKamil Trzcinski <ayufan@ayufan.eu>2016-12-18 23:43:13 +0100
commitc1928f4fce2c1b6315723f8b4a2002eee094b477 (patch)
tree01c061f90c8513e45554953414cfbd0d6f007149 /app/models/ci/stage.rb
parent1e62a13968cc4351684f919630cd426e20fc022a (diff)
parent546fa165ff728bc2d25ed9b55b95dd1d48139d4a (diff)
downloadgitlab-ce-c1928f4fce2c1b6315723f8b4a2002eee094b477.tar.gz
Merge remote-tracking branch 'origin/master' into improve-pipeline-fixturesimprove-pipeline-fixtures
Diffstat (limited to 'app/models/ci/stage.rb')
-rw-r--r--app/models/ci/stage.rb39
1 files changed, 39 insertions, 0 deletions
diff --git a/app/models/ci/stage.rb b/app/models/ci/stage.rb
new file mode 100644
index 00000000000..7ef59445d77
--- /dev/null
+++ b/app/models/ci/stage.rb
@@ -0,0 +1,39 @@
+module Ci
+ # Currently this is artificial object, constructed dynamically
+ # We should migrate this object to actual database record in the future
+ class Stage
+ include StaticModel
+
+ attr_reader :pipeline, :name
+
+ delegate :project, to: :pipeline
+
+ def initialize(pipeline, name:, status: nil)
+ @pipeline = pipeline
+ @name = name
+ @status = status
+ end
+
+ def to_param
+ name
+ end
+
+ def status
+ @status ||= statuses.latest.status
+ end
+
+ def detailed_status(current_user)
+ Gitlab::Ci::Status::Stage::Factory
+ .new(self, current_user)
+ .fabricate!
+ end
+
+ def statuses
+ @statuses ||= pipeline.statuses.where(stage: name)
+ end
+
+ def builds
+ @builds ||= pipeline.builds.where(stage: name)
+ end
+ end
+end