diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index 4691b33ee9bd020f511c9de3f8a7f2d611bc3fb0..46a6b4c724a53b2bed87821c6712a58d2a1eef03 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -276,8 +276,8 @@ module Ci def update_coverage return unless project - return unless coverage_regex = self.coverage_regex - coverage = extract_coverage(trace, coverage_regex) + return unless regex = self.coverage_regex + coverage = extract_coverage(trace, regex) if coverage.is_a? Numeric update_attributes(coverage: coverage) @@ -522,7 +522,7 @@ module Ci end def coverage_regex - read_attribute(:coverage_regex) || build_attributes_from_config[:coverage] || project.build_coverage_regex + read_attribute(:coverage_regex) || project.build_coverage_regex end def when diff --git a/lib/ci/gitlab_ci_yaml_processor.rb b/lib/ci/gitlab_ci_yaml_processor.rb index 2f5ef4d36bd6c91c14873bef3ae419307a0d0f3d..649ee4d018b4db4e5e793151678274fba79c22e5 100644 --- a/lib/ci/gitlab_ci_yaml_processor.rb +++ b/lib/ci/gitlab_ci_yaml_processor.rb @@ -61,7 +61,7 @@ module Ci allow_failure: job[:allow_failure] || false, when: job[:when] || 'on_success', environment: job[:environment_name], - coverage_regex: job[:coverage_regex], + coverage_regex: job[:coverage], yaml_variables: yaml_variables(name), options: { image: job[:image], diff --git a/lib/gitlab/ci/config/node/regexp.rb b/lib/gitlab/ci/config/entry/coverage.rb similarity index 90% rename from lib/gitlab/ci/config/node/regexp.rb rename to lib/gitlab/ci/config/entry/coverage.rb index 7c5843eb8b6ac060109eacc0a1a191b3ce648fc8..88fc03db2d9d164e050941571dcd6b6ecc8e8e6e 100644 --- a/lib/gitlab/ci/config/node/regexp.rb +++ b/lib/gitlab/ci/config/entry/coverage.rb @@ -1,11 +1,11 @@ module Gitlab module Ci class Config - module Node + module Entry ## # Entry that represents a Regular Expression. # - class Regexp < Entry + class Coverage < Node include Validatable validations do diff --git a/lib/gitlab/ci/config/entry/job.rb b/lib/gitlab/ci/config/entry/job.rb index 3c7ef99cefc99ad2a6672e50cbd85182e31fa95f..bde6663344a0139c447223571b5b740ed2e5a11d 100644 --- a/lib/gitlab/ci/config/entry/job.rb +++ b/lib/gitlab/ci/config/entry/job.rb @@ -11,7 +11,7 @@ module Gitlab ALLOWED_KEYS = %i[tags script only except type image services allow_failure type stage when artifacts cache dependencies before_script - after_script variables environment coverage_regex] + after_script variables environment coverage] validations do validates :config, allowed_keys: ALLOWED_KEYS @@ -71,12 +71,12 @@ module Gitlab entry :environment, Entry::Environment, description: 'Environment configuration for this job.' - node :coverage_regex, Node::Regexp, + entry :coverage, Entry::Coverage, description: 'Coverage scanning regex configuration for this job.' helpers :before_script, :script, :stage, :type, :after_script, :cache, :image, :services, :only, :except, :variables, - :artifacts, :commands, :environment, :coverage_regex + :artifacts, :commands, :environment, :coverage attributes :script, :tags, :allow_failure, :when, :dependencies @@ -133,7 +133,7 @@ module Gitlab variables: variables_defined? ? variables_value : nil, environment: environment_defined? ? environment_value : nil, environment_name: environment_defined? ? environment_value[:name] : nil, - coverage_regex: coverage_regex_defined? ? coverage_regex_value : nil, + coverage: coverage_defined? ? coverage_value : nil, artifacts: artifacts_value, after_script: after_script_value } end diff --git a/lib/gitlab/ci/config/entry/legacy_validation_helpers.rb b/lib/gitlab/ci/config/entry/legacy_validation_helpers.rb index 34e7052befcd9619e5195ee354f809515ae06eda..98db4632dadffd8a39d1dd905776b4827a4a979b 100644 --- a/lib/gitlab/ci/config/entry/legacy_validation_helpers.rb +++ b/lib/gitlab/ci/config/entry/legacy_validation_helpers.rb @@ -29,7 +29,8 @@ module Gitlab end def validate_regexp(value) - !!::Regexp.new(value) + Regexp.new(value) + true rescue RegexpError false end