From 792a6ca79cbf262039bd4a84d0729412bd41e208 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Mon, 15 Jun 2015 17:49:20 +0200 Subject: Prevent crash when push new branch with empty commits list Signed-off-by: Dmitriy Zaporozhets --- app/models/commit.rb | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/app/models/commit.rb b/app/models/commit.rb index f27a385..7cebf35 100644 --- a/app/models/commit.rb +++ b/app/models/commit.rb @@ -92,12 +92,12 @@ class Commit < ActiveRecord::Base end def create_builds - return if push_data[:commits].last[:message] =~ /(\[ci skip\])/ + return if skip_ci? config_processor.builds_for_ref(ref, tag).each do |build_attrs| builds.create!({ project: project, - name: build_attrs[:name], + name: build_attrs[:name], commands: build_attrs[:script], tag_list: build_attrs[:tags] }) @@ -119,12 +119,12 @@ class Commit < ActiveRecord::Base end def create_deploy_builds - return if push_data[:commits].last[:message] =~ /(\[ci skip\])/ - + return if skip_ci? + config_processor.deploy_builds_for_ref(ref, tag).each do |build_attrs| builds.create!({ project: project, - name: build_attrs[:name], + name: build_attrs[:name], commands: build_attrs[:script], tag_list: build_attrs[:tags], deploy: true @@ -195,4 +195,14 @@ class Commit < ActiveRecord::Base def config_processor @config_processor ||= GitlabCiYamlProcessor.new(push_data[:ci_yaml_file]) end + + def skip_ci? + commits = push_data[:commits] + + if commits.present? && commits.last[:message] =~ /(\[ci skip\])/ + true + else + false + end + end end -- cgit v1.2.1