Add minor improvements in create builds service

This commit is contained in:
Grzegorz Bizon
2016-06-03 11:34:36 +02:00
parent 1bcb61dd20
commit 0d19abf450
4 changed files with 8 additions and 10 deletions
+1 -1
View File
@@ -135,7 +135,7 @@ module Ci
@config_processor ||= begin
Ci::GitlabCiYamlProcessor.new(ci_yaml_file, project.path_with_namespace)
rescue Ci::GitlabCiYamlProcessor::ValidationError, Psych::SyntaxError => e
self.yaml_errors = (e.message)
self.yaml_errors = e.message
nil
rescue
self.yaml_errors = 'Undefined error'
+2 -7
View File
@@ -2,10 +2,11 @@ module Ci
class CreateBuildsService
def initialize(commit)
@commit = commit
@config = commit.config_processor
end
def execute(stage, user, status, trigger_request = nil)
builds_attrs = config_processor.builds_for_stage_and_ref(stage, @commit.ref, @commit.tag, trigger_request)
builds_attrs = @config.builds_for_stage_and_ref(stage, @commit.ref, @commit.tag, trigger_request)
# check when to create next build
builds_attrs = builds_attrs.select do |build_attrs|
@@ -41,11 +42,5 @@ module Ci
end
end
end
private
def config_processor
@config_processor ||= @commit.config_processor
end
end
end
+4 -1
View File
@@ -27,7 +27,10 @@ module Ci
end
def builds_for_stage_and_ref(stage, ref, tag = false, trigger_request = nil)
builds.select{|build| build[:stage] == stage && process?(build[:only], build[:except], ref, tag, trigger_request)}
builds.select do |build|
build[:stage] == stage &&
process?(build[:only], build[:except], ref, tag, trigger_request)
end
end
def builds
@@ -183,7 +183,7 @@ describe CreateCommitBuildsService, services: true do
ref: 'refs/heads/master',
before: '00000000',
after: '31das312',
commits: [{ message: 'some msg'}])
commits: [{ message: 'some msg'} ])
expect(result).to be false
expect(Ci::Build.all).to be_empty