diff options
Diffstat (limited to 'lib/gitlab/ci/status/composite_status.rb')
-rw-r--r-- | lib/gitlab/ci/status/composite_status.rb | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/lib/gitlab/ci/status/composite_status.rb b/lib/gitlab/ci/status/composite_status.rb new file mode 100644 index 00000000000..227c32bb18a --- /dev/null +++ b/lib/gitlab/ci/status/composite_status.rb @@ -0,0 +1,75 @@ +# frozen_string_literal: true + +module Gitlab + module Ci + module Status + class CompositeStatus + def initialize(all_statuses) + @status_set = build_status_set(all_statuses) + end + + def status + case + when only?(:skipped, :warning) + :success + when only?(:skipped) + :skipped + when only?(:success) + :skipped + when only?(:created) + :created + when only?(:preparing) + :preparing + when only?(:success, :skipped) + :success + when only?(:success, :skipped, :canceled) + :canceled + when only?(:created, :skipped, :pending) + :pending + when include?(:running, :pending) + :running + when include?(:manual) + :manual + when include?(:scheduled) + :scheduled + when include?(:preparing) + :preparing + when include?(:created) + :created + when include? + :failed + end + end + + def warnings? + include?(:warning) + end + + private + + def include?(*names) + names.all? { |name| @status_set.include?(name) } + end + + def only?(*names) + @status_set.size == names.size && + names.all? { |name| @status_set.include?(name) } + end + + def build_status_set(all_statuses) + status_set = Set.new + + all_statuses.each do |status| + if status[:allow_failure] && HasStatus::WARNING_STATUSES.include?(status[:status]) + status_set.add(:warning) + else + status_set.add(status[:status].to_sym) + end + end + + status_set + end + end + end + end +end |