BigW Consortium Gitlab

Commit 0d19abf4 by Grzegorz Bizon

Add minor improvements in create builds service

parent 1bcb61dd
...@@ -135,7 +135,7 @@ module Ci ...@@ -135,7 +135,7 @@ module Ci
@config_processor ||= begin @config_processor ||= begin
Ci::GitlabCiYamlProcessor.new(ci_yaml_file, project.path_with_namespace) Ci::GitlabCiYamlProcessor.new(ci_yaml_file, project.path_with_namespace)
rescue Ci::GitlabCiYamlProcessor::ValidationError, Psych::SyntaxError => e rescue Ci::GitlabCiYamlProcessor::ValidationError, Psych::SyntaxError => e
self.yaml_errors = (e.message) self.yaml_errors = e.message
nil nil
rescue rescue
self.yaml_errors = 'Undefined error' self.yaml_errors = 'Undefined error'
......
...@@ -2,10 +2,11 @@ module Ci ...@@ -2,10 +2,11 @@ module Ci
class CreateBuildsService class CreateBuildsService
def initialize(commit) def initialize(commit)
@commit = commit @commit = commit
@config = commit.config_processor
end end
def execute(stage, user, status, trigger_request = nil) 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 # check when to create next build
builds_attrs = builds_attrs.select do |build_attrs| builds_attrs = builds_attrs.select do |build_attrs|
...@@ -41,11 +42,5 @@ module Ci ...@@ -41,11 +42,5 @@ module Ci
end end
end end
end end
private
def config_processor
@config_processor ||= @commit.config_processor
end
end end
end end
...@@ -27,7 +27,10 @@ module Ci ...@@ -27,7 +27,10 @@ module Ci
end end
def builds_for_stage_and_ref(stage, ref, tag = false, trigger_request = nil) 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 end
def builds def builds
......
...@@ -183,7 +183,7 @@ describe CreateCommitBuildsService, services: true do ...@@ -183,7 +183,7 @@ describe CreateCommitBuildsService, services: true do
ref: 'refs/heads/master', ref: 'refs/heads/master',
before: '00000000', before: '00000000',
after: '31das312', after: '31das312',
commits: [{ message: 'some msg'}]) commits: [{ message: 'some msg'} ])
expect(result).to be false expect(result).to be false
expect(Ci::Build.all).to be_empty expect(Ci::Build.all).to be_empty
......
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