From d47aef58cd88fb813390c904bd24525e24d41483 Mon Sep 17 00:00:00 2001 From: Kamil Trzcinski Date: Mon, 5 Dec 2016 14:28:02 +0100 Subject: [PATCH] Add Ci::Status::Stage --- app/models/ci/stage.rb | 2 ++ lib/gitlab/ci/status/stage/common.rb | 24 +++++++++++++++++ lib/gitlab/ci/status/stage/factory.rb | 39 +++++++++++++++++++++++++++ 3 files changed, 65 insertions(+) create mode 100644 lib/gitlab/ci/status/stage/common.rb create mode 100644 lib/gitlab/ci/status/stage/factory.rb diff --git a/app/models/ci/stage.rb b/app/models/ci/stage.rb index 8f7727aebaa..2e7f15a16d7 100644 --- a/app/models/ci/stage.rb +++ b/app/models/ci/stage.rb @@ -6,6 +6,8 @@ module Ci attr_reader :pipeline, :name + delegate :project, to: :pipeline + def initialize(pipeline, name: name, status: nil) @pipeline, @name, @status = pipeline, name, status end diff --git a/lib/gitlab/ci/status/stage/common.rb b/lib/gitlab/ci/status/stage/common.rb new file mode 100644 index 00000000000..a1513024c6c --- /dev/null +++ b/lib/gitlab/ci/status/stage/common.rb @@ -0,0 +1,24 @@ +module Gitlab + module Ci + module Status + module Stage + module Common + def has_details? + true + end + + def details_path + namespace_project_pipeline_path(@subject.project.namespace, + @subject.project, + @subject, + anchor: subject.name) + end + + def has_action? + false + end + end + end + end + end +end diff --git a/lib/gitlab/ci/status/stage/factory.rb b/lib/gitlab/ci/status/stage/factory.rb new file mode 100644 index 00000000000..2e485ee22a9 --- /dev/null +++ b/lib/gitlab/ci/status/stage/factory.rb @@ -0,0 +1,39 @@ +module Gitlab + module Ci + module Status + module Stage + class Factory + EXTENDED_STATUSES = [] + + def initialize(stage) + @stage = stage + @status = stage.status || :created + end + + def fabricate! + if extended_status + extended_status.new(core_status) + else + core_status + end + end + + private + + def core_status + Gitlab::Ci::Status + .const_get(@status.capitalize) + .new(@stage) + .extend(Status::Pipeline::Common) + end + + def extended_status + @extended ||= EXTENDED_STATUSES.find do |status| + status.matches?(@stage) + end + end + end + end + end + end +end