From 05e0b6d014944d4826d34d71a72e86ece29034d8 Mon Sep 17 00:00:00 2001 From: Jared Szechy Date: Thu, 17 Dec 2015 09:59:14 -0500 Subject: Fix build coverage regex matching to allow captures. Fixes #2644 --- app/models/ci/build.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index 6d9cdb95295..a5ced9c8264 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -170,7 +170,7 @@ module Ci def extract_coverage(text, regex) begin - matches = text.gsub(Regexp.new(regex)).to_a.last + matches = regex.match(text).to_a.last coverage = matches.gsub(/\d+(\.\d+)?/).first if coverage.present? -- cgit v1.2.1 From 5a3237fd8dca49f073f0e50ab63fd18d40fc49d6 Mon Sep 17 00:00:00 2001 From: Jared Szechy Date: Sun, 20 Dec 2015 13:18:14 -0500 Subject: Fix build coverage regex. Added a spec for regex captures as well. Fixes #2644 --- app/models/ci/build.rb | 3 ++- spec/models/build_spec.rb | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index a5ced9c8264..470b97a3c0f 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -170,7 +170,8 @@ module Ci def extract_coverage(text, regex) begin - matches = regex.match(text).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? diff --git a/spec/models/build_spec.rb b/spec/models/build_spec.rb index 96b6f1dbca6..e3880cd9cfe 100644 --- a/spec/models/build_spec.rb +++ b/spec/models/build_spec.rb @@ -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 -- cgit v1.2.1