diff options
| author | Kamil Trzcinski <ayufan@ayufan.eu> | 2016-12-05 14:17:42 +0100 |
|---|---|---|
| committer | Kamil Trzcinski <ayufan@ayufan.eu> | 2016-12-06 14:13:21 +0100 |
| commit | d865aedafc2282f898b4bd2fdfd3660c47203c37 (patch) | |
| tree | 7d0767215b56c61e07380e5d2985e2f7ed72b077 /app/models/ci | |
| parent | fa1105b10b4f5dbce46bd72eb6374fe7f8d51f56 (diff) | |
| download | gitlab-ce-d865aedafc2282f898b4bd2fdfd3660c47203c37.tar.gz | |
Introduce `Ci::Stage`, right now this is artificial object that is build dynamically.
Diffstat (limited to 'app/models/ci')
| -rw-r--r-- | app/models/ci/pipeline.rb | 24 | ||||
| -rw-r--r-- | app/models/ci/stage.rb | 23 |
2 files changed, 30 insertions, 17 deletions
diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb index 05303007625..b6b9a90a589 100644 --- a/app/models/ci/pipeline.rb +++ b/app/models/ci/pipeline.rb @@ -100,34 +100,24 @@ module Ci where.not(duration: nil).sum(:duration) end - def stages_query - statuses.group('stage').select(:stage) - .order('max(stage_idx)') + def stages_count + statuses.select(:stage).distinct.count end def stages - self.stages_query.pluck(:stage) - end - - def stages_with_statuses status_sql = statuses.latest.where('stage=sg.stage').status_sql - stages_with_statuses = CommitStatus.from(self.stages_query, :sg). + stages_query = statuses.group('stage').select(:stage) + .order('max(stage_idx)') + + stages_with_statuses = CommitStatus.from(stages_query, :sg). pluck('sg.stage', status_sql) stages_with_statuses.map do |stage| - OpenStruct.new( - name: stage.first, - status: stage.last, - pipeline: self - ) + Ci::Stage.new(self, stage.first, status: stage.last) end end - def stages_with_latest_statuses - statuses.latest.includes(project: :namespace).order(:stage_idx).group_by(&:stage) - end - def artifacts builds.latest.with_artifacts_not_expired end diff --git a/app/models/ci/stage.rb b/app/models/ci/stage.rb new file mode 100644 index 00000000000..f1cac09c4e9 --- /dev/null +++ b/app/models/ci/stage.rb @@ -0,0 +1,23 @@ +module Ci + class Stage < ActiveRecord::Base + include ActiveModel::Model + + attr_reader :pipeline, :name + + def initialize(pipeline, name: name, status: status = nil) + @pipeline, @name, @status = pipeline, name, status + end + + def status + @status ||= statuses.latest.status + end + + def statuses + pipeline.statuses.where(stage: stage) + end + + def builds + pipeline.builds.where(stage: stage) + end + end +end |
