Skip to content
Snippets Groups Projects
Commit e2828a60 authored by Grzegorz Bizon's avatar Grzegorz Bizon
Browse files

Use existing pipeline stage if stage already exists

parent 503f2136
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -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
Loading
Loading
@@ -499,6 +499,29 @@ describe CommitStatus do
end
end
 
context 'when commit status does not have stage but it exists' do
let!(:stage) do
create(:ci_stage_entity, project: project,
pipeline: pipeline,
name: 'test')
end
let(:commit_status) do
create(:commit_status, project: project,
pipeline: pipeline,
name: 'rspec',
stage: 'test',
status: :success)
end
it 'uses existing stage' do
expect { commit_status }.not_to change { Ci::Stage.count }
expect(commit_status.stage_id).to eq stage.id
expect(stage.reload.status).to eq commit_status.status
end
end
context 'when commit status is being imported' do
let(:commit_status) do
create(:commit_status, name: 'rspec', stage: 'test', importing: true)
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment