From fedcfea8952f42788081ad5ff391a01546b4fa44 Mon Sep 17 00:00:00 2001 From: gabrielburnworth Date: Thu, 8 Aug 2024 15:26:27 -0700 Subject: [PATCH] add override option to coverage task --- lib/tasks/coverage.rake | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/tasks/coverage.rake b/lib/tasks/coverage.rake index 4925f4d80..e3da5f8f2 100644 --- a/lib/tasks/coverage.rake +++ b/lib/tasks/coverage.rake @@ -11,9 +11,13 @@ BASE_BRANCHES = ["main", "staging"] CURRENT_COMMIT = ENV.fetch("CIRCLE_SHA1", "") CSS_SELECTOR = ".fraction" FRACTION_DELIM = "/" +REMOTE_COVERAGE_OVERRIDE = ENV.fetch('REMOTE_COVERAGE_OVERRIDE', '0').to_f # Fetch JSON over HTTP. Rails probably already has a helper for this :shrug: def open_json(url) + if REMOTE_COVERAGE_OVERRIDE > 0 + return {} + end begin JSON.parse(URI.parse(url).open.read) rescue *[OpenURI::HTTPError, SocketError] => exception @@ -272,6 +276,16 @@ namespace :coverage do if remote[:percent].nil? puts "Error getting coveralls data." + puts "Checking for override." + percent = REMOTE_COVERAGE_OVERRIDE + if percent > 0 + puts "Using override of #{percent}% for remote coverage value." + remote = { branch: "N/A", commit: "", percent: percent } + end + end + + if remote[:percent].nil? + puts "No override available." puts "Using 100 instead of nil for remote coverage value." remote = { branch: "N/A", commit: "", percent: 100 } end