summaryrefslogtreecommitdiff
path: root/app/models/commit_status.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/commit_status.rb')
-rw-r--r--app/models/commit_status.rb28
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