Skip to content
This repository was archived by the owner on Jan 10, 2023. It is now read-only.

Commit bba4658

Browse files
authored
Remove rogue colors (#98)
1 parent 7c0ca1c commit bba4658

3 files changed

Lines changed: 24 additions & 27 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
### `0.2.9`
2+
- Remove `String` specific colors
3+
- Add support for Codebuild CI
4+
15
### `0.2.8`
26
- Remove `colorize` dependency
37

codecov.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Gem::Specification.new do |s|
1313
s.required_ruby_version = '>=2.4'
1414
s.summary = 'hosted code coverage ruby/rails reporter'
1515
s.test_files = ['test/test_codecov.rb']
16-
s.version = '0.2.8'
16+
s.version = '0.2.9'
1717

1818
s.add_dependency 'json'
1919
s.add_dependency 'simplecov'

lib/codecov.rb

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
require 'zlib'
88

99
class SimpleCov::Formatter::Codecov
10-
VERSION = '0.2.8'
10+
VERSION = '0.2.9'
1111

1212
### CIs
1313
RECOGNIZED_CIS = [
@@ -88,7 +88,7 @@ def detect_ci
8888
end
8989

9090
if !RECOGNIZED_CIS.include?(ci)
91-
puts ['x>'.red, 'No CI provider detected.'].join(' ')
91+
puts [red('x>'), 'No CI provider detected.'].join(' ')
9292
else
9393
puts "==> #{ci} detected"
9494
end
@@ -336,7 +336,7 @@ def create_report(report)
336336
end
337337

338338
def gzip_report(report)
339-
puts ['==>'.green, 'Gzipping contents'].join(' ')
339+
puts [green('==>'), 'Gzipping contents'].join(' ')
340340

341341
io = StringIO.new
342342
gzip = Zlib::GzipWriter.new(io)
@@ -362,7 +362,7 @@ def upload_to_codecov(ci, report)
362362
report['params'] = params
363363
report['query'] = query
364364

365-
puts ['==>'.green, 'Uploading reports'].join(' ')
365+
puts [green('==>'), 'Uploading reports'].join(' ')
366366
puts " url: #{url}"
367367
puts " query: #{query_without_token}"
368368

@@ -380,7 +380,7 @@ def upload_to_v4(url, report, query, query_without_token)
380380
https = Net::HTTP.new(uri.host, uri.port)
381381
https.use_ssl = !url.match(/^https/).nil?
382382

383-
puts ['-> '.green, 'Pinging Codecov'].join(' ')
383+
puts [green('-> '), 'Pinging Codecov'].join(' ')
384384
puts "#{url}#{uri.path}?#{query_without_token}"
385385

386386
req = Net::HTTP::Post.new(
@@ -393,13 +393,13 @@ def upload_to_v4(url, report, query, query_without_token)
393393
)
394394
response = retry_request(req, https)
395395
if !response&.code || response.code == '400'
396-
puts response&.body&.red
396+
puts red(response&.body)
397397
return false
398398
end
399399

400400
reports_url = response.body.lines[0]
401401
s3target = response.body.lines[1]
402-
puts ['-> '.green, 'Uploading to'].join(' ')
402+
puts [green('-> '), 'Uploading to'].join(' ')
403403
puts s3target
404404

405405
uri = URI(s3target)
@@ -424,8 +424,8 @@ def upload_to_v4(url, report, query, query_without_token)
424424
'message' => 'Coverage reports upload successfully'
425425
}.to_json
426426
else
427-
puts ['-> '.black, 'Could not upload reports via v4 API, defaulting to v2'].join(' ')
428-
puts res.body.red
427+
puts [black('-> '), 'Could not upload reports via v4 API, defaulting to v2'].join(' ')
428+
puts red(res.body)
429429
nil
430430
end
431431
end
@@ -435,7 +435,7 @@ def upload_to_v2(url, report, query, query_without_token)
435435
https = Net::HTTP.new(uri.host, uri.port)
436436
https.use_ssl = !url.match(/^https/).nil?
437437

438-
puts ['-> '.green, 'Uploading to Codecov'].join(' ')
438+
puts [green('-> '), 'Uploading to Codecov'].join(' ')
439439
puts "#{url}#{uri.path}?#{query_without_token}"
440440

441441
req = Net::HTTP::Post.new(
@@ -456,7 +456,7 @@ def handle_report_response(report)
456456
if report['result']['uploaded']
457457
puts " View reports at #{report['result']['url']}"
458458
else
459-
puts ' X> Failed to upload coverage reports'.red
459+
puts red(' X> Failed to upload coverage reports')
460460
end
461461
end
462462

@@ -511,7 +511,7 @@ def file_network
511511
'node_modules/'
512512
]
513513

514-
puts ['==>'.green, 'Appending file network'].join(' ')
514+
puts [green('==>'), 'Appending file network'].join(' ')
515515
network = []
516516
Dir['**/*'].keep_if do |file|
517517
if File.file?(file) && !file.end_with?(*invalid_file_types) && !file.include?(*invalid_directories)
@@ -597,24 +597,17 @@ def net_blockers(switch)
597597

598598
true
599599
end
600-
end
601-
602-
# https://stackoverflow.com/a/11482430/5769383
603-
class String
604-
# colorization
605-
def colorize(color_code)
606-
"\e[#{color_code}m#{self}\e[0m"
607-
end
608600

609-
def black
610-
colorize(30)
601+
# Convenience color methods
602+
def black(str)
603+
str.nil? ? '' : "\e[30m#{str}\e[0m"
611604
end
612605

613-
def red
614-
colorize(31)
606+
def red(str)
607+
str.nil? ? '' : "\e[31m#{str}\e[0m"
615608
end
616609

617-
def green
618-
colorize(32)
610+
def green(str)
611+
str.nil? ? '' : "\e[32m#{str}\e[0m"
619612
end
620613
end

0 commit comments

Comments
 (0)