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

Commit

Permalink
Remove rogue colors (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasrockhu committed Aug 31, 2020
1 parent 7c0ca1c commit bba4658
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 27 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### `0.2.9`
- Remove `String` specific colors
- Add support for Codebuild CI

### `0.2.8`
- Remove `colorize` dependency

Expand Down
2 changes: 1 addition & 1 deletion codecov.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Gem::Specification.new do |s|
s.required_ruby_version = '>=2.4'
s.summary = 'hosted code coverage ruby/rails reporter'
s.test_files = ['test/test_codecov.rb']
s.version = '0.2.8'
s.version = '0.2.9'

s.add_dependency 'json'
s.add_dependency 'simplecov'
Expand Down
45 changes: 19 additions & 26 deletions lib/codecov.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
require 'zlib'

class SimpleCov::Formatter::Codecov
VERSION = '0.2.8'
VERSION = '0.2.9'

### CIs
RECOGNIZED_CIS = [
Expand Down Expand Up @@ -88,7 +88,7 @@ def detect_ci
end

if !RECOGNIZED_CIS.include?(ci)
puts ['x>'.red, 'No CI provider detected.'].join(' ')
puts [red('x>'), 'No CI provider detected.'].join(' ')
else
puts "==> #{ci} detected"
end
Expand Down Expand Up @@ -336,7 +336,7 @@ def create_report(report)
end

def gzip_report(report)
puts ['==>'.green, 'Gzipping contents'].join(' ')
puts [green('==>'), 'Gzipping contents'].join(' ')

io = StringIO.new
gzip = Zlib::GzipWriter.new(io)
Expand All @@ -362,7 +362,7 @@ def upload_to_codecov(ci, report)
report['params'] = params
report['query'] = query

puts ['==>'.green, 'Uploading reports'].join(' ')
puts [green('==>'), 'Uploading reports'].join(' ')
puts " url: #{url}"
puts " query: #{query_without_token}"

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

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

req = Net::HTTP::Post.new(
Expand All @@ -393,13 +393,13 @@ def upload_to_v4(url, report, query, query_without_token)
)
response = retry_request(req, https)
if !response&.code || response.code == '400'
puts response&.body&.red
puts red(response&.body)
return false
end

reports_url = response.body.lines[0]
s3target = response.body.lines[1]
puts ['-> '.green, 'Uploading to'].join(' ')
puts [green('-> '), 'Uploading to'].join(' ')
puts s3target

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

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

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

Expand Down Expand Up @@ -511,7 +511,7 @@ def file_network
'node_modules/'
]

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

true
end
end

# https://stackoverflow.com/a/11482430/5769383
class String
# colorization
def colorize(color_code)
"\e[#{color_code}m#{self}\e[0m"
end

def black
colorize(30)
# Convenience color methods
def black(str)
str.nil? ? '' : "\e[30m#{str}\e[0m"
end

def red
colorize(31)
def red(str)
str.nil? ? '' : "\e[31m#{str}\e[0m"
end

def green
colorize(32)
def green(str)
str.nil? ? '' : "\e[32m#{str}\e[0m"
end
end

0 comments on commit bba4658

Please sign in to comment.