BigW Consortium Gitlab

Commit 07af37a2 by Grzegorz Bizon

Do not create pipeline objects when no builds

parent 53fe06ef
...@@ -20,26 +20,33 @@ module Ci ...@@ -20,26 +20,33 @@ module Ci
end end
end end
# don't create the same build twice
builds_attrs.reject! do |build_attrs|
@commit.builds.find_by(ref: @commit.ref, tag: @commit.tag,
trigger_request: trigger_request,
name: build_attrs[:name])
end
builds_attrs.map do |build_attrs| builds_attrs.map do |build_attrs|
# don't create the same build twice build_attrs.slice!(:name,
unless @commit.builds.find_by(ref: @commit.ref, tag: @commit.tag, :commands,
trigger_request: trigger_request, name: build_attrs[:name]) :tag_list,
build_attrs.slice!(:name, :options,
:commands, :allow_failure,
:tag_list, :stage,
:options, :stage_idx)
:allow_failure,
:stage,
:stage_idx)
build_attrs.merge!(ref: @commit.ref, build_attrs.merge!(ref: @commit.ref,
tag: @commit.tag, tag: @commit.tag,
trigger_request: trigger_request, trigger_request: trigger_request,
user: user, user: user,
project: @commit.project) project: @commit.project)
@commit.builds.create!(build_attrs) ##
end # We do not persist new builds here.
# Those will be persisted when @commit is saved.
#
@commit.builds.new(build_attrs)
end end
end end
end end
......
...@@ -25,16 +25,16 @@ class CreateCommitBuildsService ...@@ -25,16 +25,16 @@ class CreateCommitBuildsService
return false return false
end end
# Create a new ci_commit
commit.save!
# Skip creating builds for commits that have [ci skip] # Skip creating builds for commits that have [ci skip]
unless commit.skip_ci? unless commit.skip_ci?
# Create builds for commit # Create builds for commit and
commit.create_builds(user) # skip saving pipeline when there are no builds
return false unless commit.create_builds(user)
end end
commit.update_state! # Create a new ci_commit
commit.save!
commit commit
end end
end end
...@@ -9,7 +9,7 @@ describe Ci::CreateBuildsService, services: true do ...@@ -9,7 +9,7 @@ describe Ci::CreateBuildsService, services: true do
# #
subject do subject do
described_class.new(commit).execute(commit, nil, user, status) described_class.new(commit).execute('test', user, status, nil)
end end
context 'next builds available' do context 'next builds available' do
...@@ -17,6 +17,10 @@ describe Ci::CreateBuildsService, services: true do ...@@ -17,6 +17,10 @@ describe Ci::CreateBuildsService, services: true do
it { is_expected.to be_an_instance_of Array } it { is_expected.to be_an_instance_of Array }
it { is_expected.to all(be_an_instance_of Ci::Build) } it { is_expected.to all(be_an_instance_of Ci::Build) }
it 'does not persist created builds' do
expect(subject.first).not_to be_persisted
end
end end
context 'builds skipped' do context 'builds skipped' do
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment