Skip to content

Commit

Permalink
Backport the changes of Coveralls-Community fork
Browse files Browse the repository at this point in the history
Coveralls-Community must be released as a new gem.

Meanwhile this commit allow to release a new version of coveralls_reborn
with SimpleCov 0.17.0 support

Ref: https://github.com/Coveralls-Community/coveralls-ruby
  • Loading branch information
tagliala committed Jul 16, 2019
1 parent f6a768e commit d555fec
Show file tree
Hide file tree
Showing 23 changed files with 469 additions and 427 deletions.
23 changes: 9 additions & 14 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
require: rubocop-rspec

AllCops:
TargetRubyVersion: 2.2
TargetRubyVersion: 2.3
Exclude:
- 'spec/coveralls/fixtures/**/*'
- 'vendor/bundle/**/*'

Lint/HandleExceptions:
Enabled: false
Layout/AlignHash:
EnforcedColonStyle: table
EnforcedHashRocketStyle: table

Metrics/AbcSize:
Max: 37
Max: 39.29

Metrics/CyclomaticComplexity:
Max: 18
Max: 19

Metrics/PerceivedComplexity:
Max: 19
Max: 20

Metrics/BlockLength:
Exclude:
Expand All @@ -33,10 +34,6 @@ Metrics/ModuleLength:
- 'lib/coveralls/configuration.rb'
- 'spec/**/*'

Naming/AccessorMethodName:
Exclude:
- 'lib/coveralls/configuration.rb'

RSpec/ExampleLength:
Max: 8

Expand All @@ -52,7 +49,5 @@ RSpec/NestedGroups:
Style/Documentation:
Enabled: false

# TODO: Remove when targeting Ruby 2.3 because it is already enabled.
Style/FrozenStringLiteralComment:
Enabled: true
EnforcedStyle: always
Style/IfUnlessModifier:
Enabled: false
14 changes: 6 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ language: ruby

cache: bundler

sudo: false

before_install:
- gem update --system
- gem install bundler
Expand All @@ -16,15 +14,15 @@ env:
- JRUBY_OPTS="--dev --debug"

rvm:
- 2.2.10
- 2.3.7
- 2.4.4
- 2.5.1
- 2.3.8
- 2.4.6
- 2.5.5
- 2.6.3
- ruby-head
- jruby-9.2.0.0
- jruby-9.2.7.0

matrix:
allow_failures:
- rvm: ruby-head
- rvm: jruby-9.2.0.0
- rvm: jruby-9.2.7.0
fast_finish: true
18 changes: 0 additions & 18 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,3 @@
# Changelog

### Please see Github Releases section for current releases.

## 0.7.0 (September 18, 2013)

[Full Changelog](https://github.com/lemurheavy/coveralls-ruby/compare/v0.6.4...v0.7.0)

Added:
* output silencing (Thanks @elizabrock)
* ruby warning fixes (Thanks @steveklabnik and @Nucc)

## 0.6.4 (April 2, 2013)

[Full Changelog](https://github.com/lemurheavy/coveralls-ruby/compare/v0.6.3...v0.6.4)

Enhancements:

* Support [Jenkins CI](http://jenkins-ci.org/)
* Support VCR versions <= 2
* Add SimpleCov filter 'vendor' by default.
17 changes: 6 additions & 11 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,16 @@ platforms :jruby do
gem 'jruby-openssl', '~> 0.10.1'
end

platforms :rbx do
gem 'rubinius-developer_tools', '~> 2.0'
gem 'rubysl', '~> 2.2'
end

group :development do
gem 'rake', '~> 12.3'
gem 'rspec', '~> 3.7'
gem 'rubocop', '~> 0.60.0'
gem 'rubocop-rspec', '~> 1.30'
gem 'rspec', '~> 3.8'
gem 'rubocop', '~> 0.73.0'
gem 'rubocop-rspec', '~> 1.33'
gem 'truthy', '~> 1.0'
gem 'vcr', '~> 4.0'
gem 'webmock', '~> 3.4'
gem 'vcr', '~> 5.0'
gem 'webmock', '~> 3.5'
end

group :test do
gem 'pry', '~> 0.11.3'
gem 'pry', '~> 0.12.2'
end
10 changes: 6 additions & 4 deletions coveralls-ruby.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@ Gem::Specification.new do |gem|
gem.name = 'coveralls_reborn'
gem.require_paths = ['lib']
gem.version = Coveralls::VERSION

gem.required_ruby_version = '>= 2.2'
gem.metadata = {
'source_code_uri' => 'https://github.com/tagliala/coveralls-ruby-reborn'
}
gem.required_ruby_version = '>= 2.3'

gem.add_dependency 'json', '~> 2.1'
gem.add_dependency 'simplecov', '~> 0.16.1'
gem.add_dependency 'simplecov', '~> 0.17.0'
gem.add_dependency 'term-ansicolor', '~> 1.6'
gem.add_dependency 'thor', '~> 0.20.0'
gem.add_dependency 'tins', '~> 1.16'

gem.add_development_dependency 'bundler', '~> 1.16'
gem.add_development_dependency 'bundler', '>= 1.16', '< 3'
end
7 changes: 5 additions & 2 deletions lib/coveralls.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ def setup!
begin
require 'simplecov'
@adapter = :simplecov if defined?(::SimpleCov)
rescue StandardError
rescue StandardError => e
# TODO: Add error action
puts e.message
end
end

Expand All @@ -58,7 +60,7 @@ def setup!
end

def start!(simplecov_setting = 'test_frameworks', &block)
return if @adapter != :simplecov
return unless @adapter == :simplecov

::SimpleCov.add_filter 'vendor'

Expand All @@ -82,6 +84,7 @@ def should_run?
# Fail early if we're not on a CI
unless will_run?
Coveralls::Output.puts('[Coveralls] Outside the CI environment, not sending data.', color: 'yellow')

return false
end

Expand Down
64 changes: 35 additions & 29 deletions lib/coveralls/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,43 +12,41 @@ class API
else
API_HOST = ENV['COVERALLS_DEVELOPMENT'] ? 'localhost:3000' : 'coveralls.io'
API_PROTOCOL = ENV['COVERALLS_DEVELOPMENT'] ? 'http' : 'https'
API_DOMAIN = "#{API_PROTOCOL}://#{API_HOST}".freeze
API_DOMAIN = "#{API_PROTOCOL}://#{API_HOST}"
end

API_BASE = "#{API_DOMAIN}/api/v1".freeze
API_BASE = "#{API_DOMAIN}/api/v1"

def self.post_json(endpoint, hash)
disable_net_blockers!

uri = endpoint_to_uri(endpoint)

Coveralls::Output.puts(JSON.pretty_generate(hash).to_s, color: 'green') if ENV['COVERALLS_DEBUG']
Coveralls::Output.puts("[Coveralls] Submitting to #{API_BASE}", color: 'cyan')
class << self
def post_json(endpoint, hash)
disable_net_blockers!

client = build_client(uri)
request = build_request(uri.path, hash)
uri = endpoint_to_uri(endpoint)

response = client.request(request)
Coveralls::Output.puts(JSON.pretty_generate(hash).to_s, color: 'green') if ENV['COVERALLS_DEBUG']
Coveralls::Output.puts("[Coveralls] Submitting to #{API_BASE}", color: 'cyan')

response_hash = JSON.parse(response.body.to_str)
client = build_client(uri)
request = build_request(uri.path, hash)
response = client.request(request)
response_hash = JSON.parse(response.body.to_str)

if response_hash['message']
Coveralls::Output.puts("[Coveralls] #{response_hash['message']}", color: 'cyan')
end
if response_hash['message']
Coveralls::Output.puts("[Coveralls] #{response_hash['message']}", color: 'cyan')
end

if response_hash['url']
Coveralls::Output.puts("[Coveralls] #{Coveralls::Output.format(response_hash['url'], color: 'underline')}", color: 'cyan')
end
if response_hash['url']
Coveralls::Output.puts("[Coveralls] #{Coveralls::Output.format(response_hash['url'], color: 'underline')}", color: 'cyan')
end

case response
when Net::HTTPServiceUnavailable
Coveralls::Output.puts('[Coveralls] API timeout occured, but data should still be processed', color: 'red')
when Net::HTTPInternalServerError
Coveralls::Output.puts("[Coveralls] API internal error occured, we're on it!", color: 'red')
case response
when Net::HTTPServiceUnavailable
Coveralls::Output.puts('[Coveralls] API timeout occured, but data should still be processed', color: 'red')
when Net::HTTPInternalServerError
Coveralls::Output.puts("[Coveralls] API internal error occured, we're on it!", color: 'red')
end
end
end

class << self
private

def disable_net_blockers!
Expand All @@ -57,7 +55,9 @@ def disable_net_blockers!

allow = WebMock::Config.instance.allow || []
WebMock::Config.instance.allow = [*allow].push API_HOST
rescue LoadError
rescue StandardError => e
# TODO: Add error action
puts e.message
end

begin
Expand All @@ -66,7 +66,9 @@ def disable_net_blockers!
VCR.send(VCR.version.major < 2 ? :config : :configure) do |c|
c.ignore_hosts API_HOST
end
rescue LoadError
rescue StandardError
# TODO: Add error action
puts error.message
end
end

Expand Down Expand Up @@ -111,20 +113,24 @@ def build_request_body(hash, boundary)

def hash_to_file(hash)
file = nil
Tempfile.open(['coveralls-upload', 'json']) do |f|

Tempfile.open(%w[coveralls-upload json]) do |f|
f.write(JSON.dump(hash))
file = f
end

File.new(file.path, 'rb')
end

def apified_hash(hash)
config = Coveralls::Configuration.configuration

if ENV['COVERALLS_DEBUG'] || Coveralls.testing
Coveralls::Output.puts '[Coveralls] Submitting with config:', color: 'yellow'
output = JSON.pretty_generate(config).gsub(/"repo_token": ?"(.*?)"/, '"repo_token": "[secure]"')
Coveralls::Output.puts output, color: 'yellow'
end

hash.merge(config)
end
end
Expand Down
13 changes: 11 additions & 2 deletions lib/coveralls/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,29 @@ class CommandLine < Thor
desc 'push', 'Runs your test suite and pushes the coverage results to Coveralls.'
def push
return unless ensure_can_run_locally!

ENV['COVERALLS_RUN_LOCALLY'] = 'true'
cmds = ['bundle exec rake']

if File.exist?('.travis.yml')
cmds = begin
YAML.load_file('.travis.yml')['script'] || cmds
rescue StandardError
cmds
end
end

cmds.each { |cmd| system cmd }

ENV['COVERALLS_RUN_LOCALLY'] = nil
end

desc 'report', 'Runs your test suite locally and displays coverage statistics.'
def report
ENV['COVERALLS_NOISY'] = 'true'

exec 'bundle exec rake'

ENV['COVERALLS_NOISY'] = nil
end

Expand All @@ -49,8 +55,11 @@ def version

private

def config
Coveralls::Configuration.configuration
end

def open_token_based_url(url)
config = Coveralls::Configuration.configuration
if config[:repo_token]
url = url.gsub('%@', config[:repo_token])
`open #{url}`
Expand All @@ -60,13 +69,13 @@ def open_token_based_url(url)
end

def ensure_can_run_locally!
config = Coveralls::Configuration.configuration
if config[:repo_token].nil?
Coveralls::Output.puts 'Coveralls cannot run locally because no repo_secret_token is set in .coveralls.yml', color: 'red'
Coveralls::Output.puts 'Please try again when you get your act together.', color: 'red'

return false
end

true
end
end
Expand Down

0 comments on commit d555fec

Please sign in to comment.