diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2017-10-06 11:45:23 +0200 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2017-11-06 11:04:09 +0100 |
commit | 503f21367051c18412d6bdf3d4586eaddaf69087 (patch) | |
tree | 489c5a40f3660969dc729e6da2f44a410f301126 /app | |
parent | 823a9d351b49a6be8c12cfe06edb4aa6ec08fe95 (diff) | |
download | gitlab-ce-503f21367051c18412d6bdf3d4586eaddaf69087.tar.gz |
Make sure that every job has a stage assigned
Diffstat (limited to 'app')
-rw-r--r-- | app/models/commit_status.rb | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/app/models/commit_status.rb b/app/models/commit_status.rb index f3888528940..7f2295dd4da 100644 --- a/app/models/commit_status.rb +++ b/app/models/commit_status.rb @@ -14,7 +14,6 @@ class CommitStatus < ActiveRecord::Base delegate :sha, :short_sha, to: :pipeline validates :pipeline, presence: true, unless: :importing? - validates :name, presence: true, unless: :importing? alias_attribute :author, :user @@ -46,6 +45,21 @@ class CommitStatus < ActiveRecord::Base runner_system_failure: 4 } + ## + # We still create some CommitStatuses outside of CreatePipelineService. + # + # These are pages deployments and external statuses. + # + before_create do |status| + next if status.stage_id.present? || importing? + + ensure_pipeline_stage! do |stage| + status.run_after_commit do + StageUpdateWorker.perform_async(stage.id) + end + end + end + state_machine :status do event :process do transition [:skipped, :manual] => :created @@ -174,4 +188,16 @@ class CommitStatus < ActiveRecord::Base v =~ /\d+/ ? v.to_i : v end end + + private + + def ensure_pipeline_stage! + attributes = { name: stage, pipeline: pipeline, project: project } + + Ci::Stage.create!(attributes).tap do |stage| + self.stage_id = stage.id + + yield stage + end + end end |