Merge branch 'coverage-regex' into 'master'

Fix build coverage regex matching to allow captures.

Fixes #2644 

/cc @DouweM 

See merge request !2138
This commit is contained in:
Douwe Maan 2015-12-21 16:25:09 +00:00
commit 058f27ad2a
2 changed files with 8 additions and 1 deletions

View File

@ -170,7 +170,8 @@ module Ci
def extract_coverage(text, regex)
begin
matches = text.gsub(Regexp.new(regex)).to_a.last
matches = text.scan(Regexp.new(regex)).last
matches = matches.last if matches.kind_of?(Array)
coverage = matches.gsub(/\d+(\.\d+)?/).first
if coverage.present?

View File

@ -189,6 +189,12 @@ describe Ci::Build, models: true do
it { is_expected.to eq(98.29) }
end
context 'using a regex capture' do
subject { build.extract_coverage('TOTAL 9926 3489 65%', 'TOTAL\s+\d+\s+\d+\s+(\d{1,3}\%)') }
it { is_expected.to eq(65) }
end
end
describe :variables do