Commit 6323cd72 authored by Leandro Camargo's avatar Leandro Camargo

Comply to more requirements and requests made in the code review

parent f1e920ed
...@@ -522,7 +522,7 @@ module Ci ...@@ -522,7 +522,7 @@ module Ci
end end
def coverage_regex def coverage_regex
read_attribute(:coverage_regex) || project.build_coverage_regex super || project.build_coverage_regex
end end
def when def when
......
...@@ -286,11 +286,13 @@ build outputs. Setting this up globally will make all the jobs to use this ...@@ -286,11 +286,13 @@ build outputs. Setting this up globally will make all the jobs to use this
setting for output filtering and extracting the coverage information from your setting for output filtering and extracting the coverage information from your
builds. builds.
Regular expressions are used by default. So using surrounding `/` is optional, given it'll always be read as a regular expression. Don't forget to escape special characters whenever you want to match them in the regular expression. Regular expressions are used by default. So using surrounding `/` is optional,
given it'll always be read as a regular expression. Don't forget to escape
special characters whenever you want to match them literally.
A simple example: A simple example:
```yaml ```yaml
coverage: \(\d+\.\d+\) covered\. coverage: /\(\d+\.\d+\) covered\./
``` ```
## Jobs ## Jobs
...@@ -1014,19 +1016,19 @@ job: ...@@ -1014,19 +1016,19 @@ job:
This entry is pretty much the same as described in the global context in This entry is pretty much the same as described in the global context in
[`coverage`](#coverage). The only difference is that, by setting it inside [`coverage`](#coverage). The only difference is that, by setting it inside
the job level, whatever is set in there will take precedence over what has the job level, whatever is set in there will take precedence over what has
been defined in the global level. A quick example of one overwritting the been defined in the global level. A quick example of one overriding the
other would be: other would be:
```yaml ```yaml
coverage: \(\d+\.\d+\) covered\. coverage: /\(\d+\.\d+\) covered\./
job1: job1:
coverage: Code coverage: \d+\.\d+ coverage: /Code coverage: \d+\.\d+/
``` ```
In the example above, considering the context of the job `job1`, the coverage In the example above, considering the context of the job `job1`, the coverage
regex that would be used is `Code coverage: \d+\.\d+` instead of regex that would be used is `/Code coverage: \d+\.\d+/` instead of
`\(\d+\.\d+\) covered\.`. `/\(\d+\.\d+\) covered\./`.
## Git Strategy ## Git Strategy
......
...@@ -13,7 +13,7 @@ module Gitlab ...@@ -13,7 +13,7 @@ module Gitlab
end end
def value def value
if @config.start_with?('/') && @config.end_with?('/') if @config.first == '/' && @config.last == '/'
@config[1...-1] @config[1...-1]
else else
@config @config
......
...@@ -29,8 +29,7 @@ module Gitlab ...@@ -29,8 +29,7 @@ module Gitlab
end end
def validate_regexp(value) def validate_regexp(value)
Regexp.new(value) !value.nil? && Regexp.new(value.to_s) && true
true
rescue RegexpError, TypeError rescue RegexpError, TypeError
false false
end end
...@@ -39,7 +38,7 @@ module Gitlab ...@@ -39,7 +38,7 @@ module Gitlab
return true if value.is_a?(Symbol) return true if value.is_a?(Symbol)
return false unless value.is_a?(String) return false unless value.is_a?(String)
if value.start_with?('/') && value.end_with?('/') if value.first == '/' && value.last == '/'
validate_regexp(value[1...-1]) validate_regexp(value[1...-1])
else else
true true
......
...@@ -12,14 +12,19 @@ module Ci ...@@ -12,14 +12,19 @@ module Ci
let(:config) { YAML.dump(config_base) } let(:config) { YAML.dump(config_base) }
context 'when config has coverage set at the global scope' do context 'when config has coverage set at the global scope' do
before { config_base.update(coverage: '\(\d+\.\d+\) covered') } before do
config_base.update(coverage: '\(\d+\.\d+\) covered')
end
context "and 'rspec' job doesn't have coverage set" do context "and 'rspec' job doesn't have coverage set" do
it { is_expected.to include(coverage_regex: '\(\d+\.\d+\) covered') } it { is_expected.to include(coverage_regex: '\(\d+\.\d+\) covered') }
end end
context 'but \'rspec\' job also has coverage set' do context 'but \'rspec\' job also has coverage set' do
before { config_base[:rspec][:coverage] = '/Code coverage: \d+\.\d+/' } before do
config_base[:rspec][:coverage] = '/Code coverage: \d+\.\d+/'
end
it { is_expected.to include(coverage_regex: 'Code coverage: \d+\.\d+') } it { is_expected.to include(coverage_regex: 'Code coverage: \d+\.\d+') }
end end
end end
......
...@@ -228,14 +228,19 @@ describe Ci::Build, :models do ...@@ -228,14 +228,19 @@ describe Ci::Build, :models do
let(:build_regex) { 'Code coverage: \d+\.\d+' } let(:build_regex) { 'Code coverage: \d+\.\d+' }
context 'when project has build_coverage_regex set' do context 'when project has build_coverage_regex set' do
before { project.build_coverage_regex = project_regex } before do
project.build_coverage_regex = project_regex
end
context 'and coverage_regex attribute is not set' do context 'and coverage_regex attribute is not set' do
it { is_expected.to eq(project_regex) } it { is_expected.to eq(project_regex) }
end end
context 'but coverage_regex attribute is also set' do context 'but coverage_regex attribute is also set' do
before { build.coverage_regex = build_regex } before do
build.coverage_regex = build_regex
end
it { is_expected.to eq(build_regex) } it { is_expected.to eq(build_regex) }
end end
end end
...@@ -250,7 +255,7 @@ describe Ci::Build, :models do ...@@ -250,7 +255,7 @@ describe Ci::Build, :models do
build.coverage_regex = '\(\d+.\d+\%\) covered' build.coverage_regex = '\(\d+.\d+\%\) covered'
allow(build).to receive(:trace) { 'Coverage 1033 / 1051 LOC (98.29%) covered' } allow(build).to receive(:trace) { 'Coverage 1033 / 1051 LOC (98.29%) covered' }
allow(build).to receive(:coverage_regex).and_call_original allow(build).to receive(:coverage_regex).and_call_original
allow(build).to receive(:update_attributes).with(coverage: 98.29) { true } expect(build).to receive(:update_attributes).with(coverage: 98.29) { true }
expect(build.update_coverage).to be true expect(build.update_coverage).to be true
end end
end end
......
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