diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2016-07-15 22:07:51 +0300 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2016-07-15 22:07:51 +0300 |
commit | 41bcbdd8c2412769a376cd37541ad6e65a1af1f2 (patch) | |
tree | 09a1a1ba53ef8dcfe17e6851c0937052a2f2f77a /lib | |
parent | 615c9730e7783e82287d2b65f58da6336d3d2410 (diff) |
Add metadata to new CI config and expose job name
Diffstat (limited to 'lib')
-rw-r--r-- | lib/ci/gitlab_ci_yaml_processor.rb | 4 | ||||
-rw-r--r-- | lib/gitlab/ci/config/node/configurable.rb | 3 | ||||
-rw-r--r-- | lib/gitlab/ci/config/node/entry.rb | 7 | ||||
-rw-r--r-- | lib/gitlab/ci/config/node/factory.rb | 10 | ||||
-rw-r--r-- | lib/gitlab/ci/config/node/global.rb | 5 | ||||
-rw-r--r-- | lib/gitlab/ci/config/node/job.rb | 20 | ||||
-rw-r--r-- | lib/gitlab/ci/config/node/jobs.rb | 9 |
7 files changed, 26 insertions, 32 deletions
diff --git a/lib/ci/gitlab_ci_yaml_processor.rb b/lib/ci/gitlab_ci_yaml_processor.rb index 3e4767cc9f6..0704e8f1683 100644 --- a/lib/ci/gitlab_ci_yaml_processor.rb +++ b/lib/ci/gitlab_ci_yaml_processor.rb @@ -82,7 +82,7 @@ module Ci stage: job[:stage], commands: [job[:before_script] || @before_script, job[:script]].flatten.compact.join("\n"), tag_list: job[:tags] || [], - name: name, + name: job[:name], only: job[:only], except: job[:except], allow_failure: job[:allow_failure] || false, @@ -113,7 +113,7 @@ module Ci def validate_job_keys!(name, job) job.keys.each do |key| - unless ALLOWED_JOB_KEYS.include? key + unless (ALLOWED_JOB_KEYS + %i[name]).include? key raise ValidationError, "#{name} job: unknown parameter #{key}" end end diff --git a/lib/gitlab/ci/config/node/configurable.rb b/lib/gitlab/ci/config/node/configurable.rb index b33d743e2c3..10b2db86d24 100644 --- a/lib/gitlab/ci/config/node/configurable.rb +++ b/lib/gitlab/ci/config/node/configurable.rb @@ -28,8 +28,7 @@ module Gitlab def create(key, factory) factory .value(@config[key]) - .parent(self) - .with(key: key) + .with(key: key, parent: self) factory.create! end diff --git a/lib/gitlab/ci/config/node/entry.rb b/lib/gitlab/ci/config/node/entry.rb index 9640103ea22..011c3be849e 100644 --- a/lib/gitlab/ci/config/node/entry.rb +++ b/lib/gitlab/ci/config/node/entry.rb @@ -11,13 +11,10 @@ module Gitlab attr_reader :config, :attributes attr_accessor :key, :parent, :description - def initialize(config, **attributes) + def initialize(config, **metadata) @config = config @entries = {} - - (@attributes = attributes).each do |attribute, value| - public_send("#{attribute}=", value) - end + @metadata = metadata @validator = self.class.validator.new(self) @validator.validate(:new) diff --git a/lib/gitlab/ci/config/node/factory.rb b/lib/gitlab/ci/config/node/factory.rb index b509c5edf59..707b052e6a8 100644 --- a/lib/gitlab/ci/config/node/factory.rb +++ b/lib/gitlab/ci/config/node/factory.rb @@ -10,6 +10,7 @@ module Gitlab def initialize(node) @node = node + @metadata = {} @attributes = {} end @@ -18,8 +19,8 @@ module Gitlab self end - def parent(parent) - @parent = parent + def metadata(metadata) + @metadata.merge!(metadata) self end @@ -30,7 +31,6 @@ module Gitlab def create! raise InvalidFactory unless defined?(@value) - raise InvalidFactory unless defined?(@parent) ## # We assume that unspecified entry is undefined. @@ -60,9 +60,9 @@ module Gitlab end def fabricate(node, value = nil) - node.new(value).tap do |entry| + node.new(value, @metadata).tap do |entry| entry.key = @attributes[:key] - entry.parent = @attributes[:parent] || @parent + entry.parent = @attributes[:parent] entry.description = @attributes[:description] end end diff --git a/lib/gitlab/ci/config/node/global.rb b/lib/gitlab/ci/config/node/global.rb index 4a958735599..bedacd904cc 100644 --- a/lib/gitlab/ci/config/node/global.rb +++ b/lib/gitlab/ci/config/node/global.rb @@ -54,9 +54,8 @@ module Gitlab def compose_jobs! factory = Node::Factory.new(Node::Jobs) .value(@config.except(*nodes.keys)) - .parent(self) - .with(key: :jobs, global: self) - .with(description: 'Jobs definition for this pipeline') + .with(key: :jobs, parent: self, + description: 'Jobs definition for this pipeline') @entries[:jobs] = factory.create! end diff --git a/lib/gitlab/ci/config/node/job.rb b/lib/gitlab/ci/config/node/job.rb index 483be2a21cc..9280412a638 100644 --- a/lib/gitlab/ci/config/node/job.rb +++ b/lib/gitlab/ci/config/node/job.rb @@ -10,11 +10,8 @@ module Gitlab validations do validates :config, presence: true - - with_options on: :processed do - validates :name, presence: true - validates :name, type: Symbol - end + validates :name, presence: true + validates :name, type: Symbol end node :before_script, Script, @@ -38,7 +35,7 @@ module Gitlab helpers :before_script, :script, :stage, :type, :after_script, :cache def name - @key + @metadata[:name] end def value @@ -48,11 +45,12 @@ module Gitlab private def to_hash - { before_script: before_script_value, - script: script_value, - stage: stage_value, - cache: cache_value, - after_script: after_script_value } + { name: name, + before_script: before_script, + script: script, + stage: stage, + cache: cache, + after_script: after_script } end def compose! diff --git a/lib/gitlab/ci/config/node/jobs.rb b/lib/gitlab/ci/config/node/jobs.rb index 3c1851b9fea..3cabcd6b763 100644 --- a/lib/gitlab/ci/config/node/jobs.rb +++ b/lib/gitlab/ci/config/node/jobs.rb @@ -31,14 +31,15 @@ module Gitlab private def create(name, config) - Node::Factory.new(node(name)) + Node::Factory.new(job_class(name)) .value(config || {}) - .parent(self) - .with(key: name, description: "#{name} job definition.") + .metadata(name: name) + .with(key: name, parent: self, + description: "#{name} job definition.") .create! end - def node(name) + def job_class(name) if name.to_s.start_with?('.') Node::HiddenJob else |