diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2017-10-11 15:32:19 +0200 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2017-11-06 11:04:09 +0100 |
commit | 164b1df59025e9685e243dd89d943ff5b1122b44 (patch) | |
tree | a26685f9fa72e83320ff9d543f790afe449a076a /app/models/commit_status.rb | |
parent | e2828a60679495d716ed3824959794f4d5fbf5bb (diff) | |
download | gitlab-ce-164b1df59025e9685e243dd89d943ff5b1122b44.tar.gz |
Extract ensure stage service from commit status class
Diffstat (limited to 'app/models/commit_status.rb')
-rw-r--r-- | app/models/commit_status.rb | 30 |
1 files changed, 3 insertions, 27 deletions
diff --git a/app/models/commit_status.rb b/app/models/commit_status.rb index 12e187024dd..6b07dbdf3ea 100644 --- a/app/models/commit_status.rb +++ b/app/models/commit_status.rb @@ -50,13 +50,9 @@ class CommitStatus < ActiveRecord::Base # # 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 + before_create unless: :importing? do + Ci::EnsureStageService.new(project, user).execute(self) do |stage| + self.run_after_commit { StageUpdateWorker.perform_async(stage.id) } end end @@ -188,24 +184,4 @@ class CommitStatus < ActiveRecord::Base v =~ /\d+/ ? v.to_i : v end end - - private - - def ensure_pipeline_stage! - (find_stage || create_stage!).tap do |stage| - self.stage_id = stage.id - - yield stage - end - end - - def find_stage - pipeline.stages.find_by(name: stage) - end - - def create_stage! - Ci::Stage.create!(name: stage, - pipeline: pipeline, - project: project) - end end |