summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2016-06-15 10:22:20 +0200
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2016-06-15 10:22:20 +0200
commit6ff146340fea6d0df1b711933b0399fbf324e861 (patch)
tree3ea1be4c0b968ba336ecc044cc98ae647f0de781
parenta76cbe5292d20cd6fdac4e519b65df1ee3544371 (diff)
downloadgitlab-ce-6ff146340fea6d0df1b711933b0399fbf324e861.tar.gz
Improve creating builds by combining two loops
-rw-r--r--app/models/ci/pipeline.rb36
1 files changed, 16 insertions, 20 deletions
diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb
index fde03f21f9b..58c69251824 100644
--- a/app/models/ci/pipeline.rb
+++ b/app/models/ci/pipeline.rb
@@ -91,16 +91,11 @@ module Ci
trigger_requests.any?
end
- def build_builds(user, trigger_request = nil, status = 'success')
+ def build_builds(user, trigger_request = nil)
return unless config_processor
- ##
- # Note that `Array#any?` implements a short circuit evaluation, so we
- # build builds only for the first stage that has builds available.
- #
- config_processor.stages.any? do |stage|
- build_builds_for_stage(stage, user, status, trigger_request).present?
- end
+ build_builds_for_stages(config_processor.stages, user,
+ 'success', trigger_request)
end
def create_builds(user, trigger_request = nil)
@@ -122,17 +117,11 @@ module Ci
prior_builds = latest_builds.where.not(stage: next_stages)
prior_status = prior_builds.status
- ##
- # Create builds for next stages based.
- #
- # Note that there is a short circult evaluation here.
- #
- have_builds = next_stages.any? do |stage|
- build_builds_for_stage(stage, build.user, prior_status,
- build.trigger_request).present?
- end
+ # build builds for next stage that has builds available
+ # and save pipeline if we have builds
+ build_builds_for_stages(next_stages, build.user, prior_status,
+ build.trigger_request) && save
- save! if have_builds
end
def retried
@@ -179,8 +168,15 @@ module Ci
private
- def build_builds_for_stage(stage, user, status, trigger_request)
- CreateBuildsService.new(self).execute(stage, user, status, trigger_request)
+ def build_builds_for_stages(stages, user, status, trigger_request)
+ ##
+ # Note that `Array#any?` implements a short circuit evaluation, so we
+ # build builds only for the first stage that has builds available.
+ #
+ stages.any? do |stage|
+ CreateBuildsService.new(self)
+ .execute(stage, user, status, trigger_request).present?
+ end
end
def update_state