summaryrefslogtreecommitdiff
path: root/app/models/commit_status.rb
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2017-10-06 12:07:11 +0200
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2017-11-06 11:04:09 +0100
commite2828a60679495d716ed3824959794f4d5fbf5bb (patch)
tree077bd7c2a3e9b4d289f2ec5278fcd30be4603a3d /app/models/commit_status.rb
parent503f21367051c18412d6bdf3d4586eaddaf69087 (diff)
downloadgitlab-ce-e2828a60679495d716ed3824959794f4d5fbf5bb.tar.gz
Use existing pipeline stage if stage already exists
Diffstat (limited to 'app/models/commit_status.rb')
-rw-r--r--app/models/commit_status.rb14
1 files changed, 11 insertions, 3 deletions
diff --git a/app/models/commit_status.rb b/app/models/commit_status.rb
index 7f2295dd4da..12e187024dd 100644
--- a/app/models/commit_status.rb
+++ b/app/models/commit_status.rb
@@ -192,12 +192,20 @@ class CommitStatus < ActiveRecord::Base
private
def ensure_pipeline_stage!
- attributes = { name: stage, pipeline: pipeline, project: project }
-
- Ci::Stage.create!(attributes).tap do |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