BigW Consortium Gitlab

stage.rb 1.09 KB
Newer Older
1
module Ci
2 3 4 5
  # Currently this is artificial object, constructed dynamically
  # We should migrate this object to actual database record in the future
  class Stage
    include StaticModel
6 7 8

    attr_reader :pipeline, :name

9 10
    delegate :project, to: :pipeline

11
    def initialize(pipeline, name:, status: nil, warnings: nil)
Kamil Trzcinski committed
12 13 14
      @pipeline = pipeline
      @name = name
      @status = status
15
      @warnings = warnings
16 17
    end

18 19 20 21
    def to_param
      name
    end

22 23 24 25
    def statuses_count
      @statuses_count ||= statuses.count
    end

26 27 28 29
    def status
      @status ||= statuses.latest.status
    end

30
    def detailed_status(current_user)
31 32 33
      Gitlab::Ci::Status::Stage::Factory
        .new(self, current_user)
        .fabricate!
Kamil Trzcinski committed
34 35
    end

36
    def statuses
Kamil Trzcinski committed
37
      @statuses ||= pipeline.statuses.where(stage: name)
38 39 40
    end

    def builds
Kamil Trzcinski committed
41
      @builds ||= pipeline.builds.where(stage: name)
42
    end
43 44 45 46 47 48

    def success?
      status.to_s == 'success'
    end

    def has_warnings?
49 50 51 52 53
      if @warnings.nil?
        statuses.latest.failed_but_allowed.any?
      else
        @warnings
      end
54
    end
55 56
  end
end