diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2016-06-02 16:55:38 +0300 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2016-06-03 12:34:36 +0300 |
commit | 07af37a243ea0d6b5741754ea116044ee46614b3 (patch) | |
tree | d0fe16b71a7837fe9927c541cb9d3286845d235f | |
parent | 53fe06efde46acd2df62f818c421ecf3a0b971c9 (diff) |
Do not create pipeline objects when no builds
-rw-r--r-- | app/services/ci/create_builds_service.rb | 41 | ||||
-rw-r--r-- | app/services/create_commit_builds_service.rb | 10 | ||||
-rw-r--r-- | spec/services/ci/create_builds_service_spec.rb | 6 |
3 files changed, 34 insertions, 23 deletions
diff --git a/app/services/ci/create_builds_service.rb b/app/services/ci/create_builds_service.rb index 7fb2ad7e061..a02b0b8f9b3 100644 --- a/app/services/ci/create_builds_service.rb +++ b/app/services/ci/create_builds_service.rb @@ -20,26 +20,33 @@ module Ci 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| - # don't create the same build twice - unless @commit.builds.find_by(ref: @commit.ref, tag: @commit.tag, - trigger_request: trigger_request, name: build_attrs[:name]) - build_attrs.slice!(:name, - :commands, - :tag_list, - :options, - :allow_failure, - :stage, - :stage_idx) + build_attrs.slice!(:name, + :commands, + :tag_list, + :options, + :allow_failure, + :stage, + :stage_idx) - build_attrs.merge!(ref: @commit.ref, - tag: @commit.tag, - trigger_request: trigger_request, - user: user, - project: @commit.project) + build_attrs.merge!(ref: @commit.ref, + tag: @commit.tag, + trigger_request: trigger_request, + user: user, + 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 diff --git a/app/services/create_commit_builds_service.rb b/app/services/create_commit_builds_service.rb index ee84023e514..3f048157b3f 100644 --- a/app/services/create_commit_builds_service.rb +++ b/app/services/create_commit_builds_service.rb @@ -25,16 +25,16 @@ class CreateCommitBuildsService return false end - # Create a new ci_commit - commit.save! # Skip creating builds for commits that have [ci skip] unless commit.skip_ci? - # Create builds for commit - commit.create_builds(user) + # Create builds for commit and + # skip saving pipeline when there are no builds + return false unless commit.create_builds(user) end - commit.update_state! + # Create a new ci_commit + commit.save! commit end end diff --git a/spec/services/ci/create_builds_service_spec.rb b/spec/services/ci/create_builds_service_spec.rb index ecc3a88a262..8e737fd44f9 100644 --- a/spec/services/ci/create_builds_service_spec.rb +++ b/spec/services/ci/create_builds_service_spec.rb @@ -9,7 +9,7 @@ describe Ci::CreateBuildsService, services: true do # subject do - described_class.new(commit).execute(commit, nil, user, status) + described_class.new(commit).execute('test', user, status, nil) end context 'next builds available' do @@ -17,6 +17,10 @@ describe Ci::CreateBuildsService, services: true do it { is_expected.to be_an_instance_of Array } 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 context 'builds skipped' do |