Skip to content
Snippets Groups Projects
Commit c7014683 authored by Grzegorz Bizon's avatar Grzegorz Bizon
Browse files

Improve naming convention in ci configuration module

parent b44237f5
No related branches found
No related tags found
No related merge requests found
Showing
with 79 additions and 79 deletions
Loading
Loading
@@ -2,7 +2,7 @@ module Ci
class GitlabCiYamlProcessor
class ValidationError < StandardError; end
 
include Gitlab::Ci::Config::Node::LegacyValidationHelpers
include Gitlab::Ci::Config::Entry::LegacyValidationHelpers
 
attr_reader :path, :cache, :stages, :jobs
 
Loading
Loading
Loading
Loading
@@ -13,7 +13,7 @@ module Gitlab
def initialize(config)
@config = Loader.new(config).load!
 
@global = Node::Global.new(@config)
@global = Entry::Global.new(@config)
@global.compose!
end
 
Loading
Loading
module Gitlab
module Ci
class Config
module Node
module Entry
##
# Entry that represents a configuration of job artifacts.
#
class Artifacts < Entry
class Artifacts < Node
include Validatable
include Attributable
 
Loading
Loading
module Gitlab
module Ci
class Config
module Node
module Entry
module Attributable
extend ActiveSupport::Concern
 
Loading
Loading
module Gitlab
module Ci
class Config
module Node
module Entry
##
# Entry that represents a boolean value.
#
class Boolean < Entry
class Boolean < Node
include Validatable
 
validations do
Loading
Loading
module Gitlab
module Ci
class Config
module Node
module Entry
##
# Entry that represents a cache configuration
#
class Cache < Entry
class Cache < Node
include Configurable
 
ALLOWED_KEYS = %i[key untracked paths]
Loading
Loading
@@ -14,13 +14,13 @@ module Gitlab
validates :config, allowed_keys: ALLOWED_KEYS
end
 
node :key, Node::Key,
node :key, Entry::Key,
description: 'Cache key used to define a cache affinity.'
 
node :untracked, Node::Boolean,
node :untracked, Entry::Boolean,
description: 'Cache all untracked files.'
 
node :paths, Node::Paths,
node :paths, Entry::Paths,
description: 'Specify which paths should be cached across builds.'
end
end
Loading
Loading
module Gitlab
module Ci
class Config
module Node
module Entry
##
# Entry that represents a job script.
#
class Commands < Entry
class Commands < Node
include Validatable
 
validations do
Loading
Loading
module Gitlab
module Ci
class Config
module Node
module Entry
##
# This mixin is responsible for adding DSL, which purpose is to
# simplifly process of adding child nodes.
Loading
Loading
@@ -49,7 +49,7 @@ module Gitlab
private # rubocop:disable Lint/UselessAccessModifier
 
def node(key, node, metadata)
factory = Node::Factory.new(node)
factory = Entry::Factory.new(node)
.with(description: metadata[:description])
 
(@nodes ||= {}).merge!(key.to_sym => factory)
Loading
Loading
module Gitlab
module Ci
class Config
module Node
module Entry
##
# Entry that represents an environment.
#
class Environment < Entry
class Environment < Node
include Validatable
 
ALLOWED_KEYS = %i[name url action on_stop]
Loading
Loading
module Gitlab
module Ci
class Config
module Node
module Entry
##
# Factory class responsible for fabricating node entry objects.
# Factory class responsible for fabricating entry objects.
#
class Factory
class InvalidFactory < StandardError; end
 
def initialize(node)
@node = node
def initialize(entry)
@entry = entry
@metadata = {}
@attributes = {}
end
Loading
Loading
@@ -37,11 +37,11 @@ module Gitlab
# See issue #18775.
#
if @value.nil?
Node::Unspecified.new(
Entry::Unspecified.new(
fabricate_unspecified
)
else
fabricate(@node, @value)
fabricate(@entry, @value)
end
end
 
Loading
Loading
@@ -49,21 +49,21 @@ module Gitlab
 
def fabricate_unspecified
##
# If node has a default value we fabricate concrete node
# If entry has a default value we fabricate concrete node
# with default value.
#
if @node.default.nil?
fabricate(Node::Undefined)
if @entry.default.nil?
fabricate(Entry::Undefined)
else
fabricate(@node, @node.default)
fabricate(@entry, @entry.default)
end
end
 
def fabricate(node, value = nil)
node.new(value, @metadata).tap do |entry|
entry.key = @attributes[:key]
entry.parent = @attributes[:parent]
entry.description = @attributes[:description]
def fabricate(entry, value = nil)
entry.new(value, @metadata).tap do |node|
node.key = @attributes[:key]
node.parent = @attributes[:parent]
node.description = @attributes[:description]
end
end
end
Loading
Loading
module Gitlab
module Ci
class Config
module Node
module Entry
##
# This class represents a global entry - root node for entire
# This class represents a global entry - root Entry for entire
# GitLab CI Configuration file.
#
class Global < Entry
class Global < Node
include Configurable
 
node :before_script, Node::Script,
node :before_script, Entry::Script,
description: 'Script that will be executed before each job.'
 
node :image, Node::Image,
node :image, Entry::Image,
description: 'Docker image that will be used to execute jobs.'
 
node :services, Node::Services,
node :services, Entry::Services,
description: 'Docker images that will be linked to the container.'
 
node :after_script, Node::Script,
node :after_script, Entry::Script,
description: 'Script that will be executed after each job.'
 
node :variables, Node::Variables,
node :variables, Entry::Variables,
description: 'Environment variables that will be used.'
 
node :stages, Node::Stages,
node :stages, Entry::Stages,
description: 'Configuration of stages for this pipeline.'
 
node :types, Node::Stages,
node :types, Entry::Stages,
description: 'Deprecated: stages for this pipeline.'
 
node :cache, Node::Cache,
node :cache, Entry::Cache,
description: 'Configure caching between build jobs.'
 
helpers :before_script, :image, :services, :after_script,
Loading
Loading
@@ -46,7 +46,7 @@ module Gitlab
private
 
def compose_jobs!
factory = Node::Factory.new(Node::Jobs)
factory = Entry::Factory.new(Entry::Jobs)
.value(@config.except(*self.class.nodes.keys))
.with(key: :jobs, parent: self,
description: 'Jobs definition for this pipeline')
Loading
Loading
module Gitlab
module Ci
class Config
module Node
module Entry
##
# Entry that represents a hidden CI/CD job.
# Entry that represents a hidden CI/CD key.
#
class Hidden < Entry
class Hidden < Node
include Validatable
 
validations do
Loading
Loading
module Gitlab
module Ci
class Config
module Node
module Entry
##
# Entry that represents a Docker image.
#
class Image < Entry
class Image < Node
include Validatable
 
validations do
Loading
Loading
module Gitlab
module Ci
class Config
module Node
module Entry
##
# Entry that represents a concrete CI/CD job.
#
class Job < Entry
class Job < Node
include Configurable
include Attributable
 
Loading
Loading
@@ -34,43 +34,43 @@ module Gitlab
end
end
 
node :before_script, Node::Script,
node :before_script, Entry::Script,
description: 'Global before script overridden in this job.'
 
node :script, Node::Commands,
node :script, Entry::Commands,
description: 'Commands that will be executed in this job.'
 
node :stage, Node::Stage,
node :stage, Entry::Stage,
description: 'Pipeline stage this job will be executed into.'
 
node :type, Node::Stage,
node :type, Entry::Stage,
description: 'Deprecated: stage this job will be executed into.'
 
node :after_script, Node::Script,
node :after_script, Entry::Script,
description: 'Commands that will be executed when finishing job.'
 
node :cache, Node::Cache,
node :cache, Entry::Cache,
description: 'Cache definition for this job.'
 
node :image, Node::Image,
node :image, Entry::Image,
description: 'Image that will be used to execute this job.'
 
node :services, Node::Services,
node :services, Entry::Services,
description: 'Services that will be used to execute this job.'
 
node :only, Node::Trigger,
node :only, Entry::Trigger,
description: 'Refs policy this job will be executed for.'
 
node :except, Node::Trigger,
node :except, Entry::Trigger,
description: 'Refs policy this job will be executed for.'
 
node :variables, Node::Variables,
node :variables, Entry::Variables,
description: 'Environment variables available for this job.'
 
node :artifacts, Node::Artifacts,
node :artifacts, Entry::Artifacts,
description: 'Artifacts configuration for this job.'
 
node :environment, Node::Environment,
node :environment, Entry::Environment,
description: 'Environment configuration for this job.'
 
helpers :before_script, :script, :stage, :type, :after_script,
Loading
Loading
module Gitlab
module Ci
class Config
module Node
module Entry
##
# Entry that represents a set of jobs.
#
class Jobs < Entry
class Jobs < Node
include Validatable
 
validations do
Loading
Loading
@@ -29,9 +29,9 @@ module Gitlab
def compose!(deps = nil)
super do
@config.each do |name, config|
node = hidden?(name) ? Node::Hidden : Node::Job
node = hidden?(name) ? Entry::Hidden : Entry::Job
 
factory = Node::Factory.new(node)
factory = Entry::Factory.new(node)
.value(config || {})
.metadata(name: name)
.with(key: name, parent: self,
Loading
Loading
module Gitlab
module Ci
class Config
module Node
module Entry
##
# Entry that represents a key.
#
class Key < Entry
class Key < Node
include Validatable
 
validations do
Loading
Loading
module Gitlab
module Ci
class Config
module Node
module Entry
module LegacyValidationHelpers
private
 
Loading
Loading
module Gitlab
module Ci
class Config
module Node
module Entry
##
# Base abstract class for each configuration entry node.
#
class Entry
class Node
class InvalidError < StandardError; end
 
attr_reader :config, :metadata
Loading
Loading
@@ -21,7 +21,7 @@ module Gitlab
end
 
def [](key)
@entries[key] || Node::Undefined.new
@entries[key] || Entry::Undefined.new
end
 
def compose!(deps = nil)
Loading
Loading
module Gitlab
module Ci
class Config
module Node
module Entry
##
# Entry that represents an array of paths.
#
class Paths < Entry
class Paths < Node
include Validatable
 
validations do
Loading
Loading
module Gitlab
module Ci
class Config
module Node
module Entry
##
# Entry that represents a script.
#
class Script < Entry
class Script < Node
include Validatable
 
validations do
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment