coveralls_reborn 0.12.0 → 0.13.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 936da9c61b12d3eb6f44af3a7147c7756cf068b4f67b192d6bf25717df16e0e6
4
- data.tar.gz: d0448b8d9e76892d80b2701d9b7d0177f53c78063b0dccc34c15f5f8e9e84966
3
+ metadata.gz: 9117713ae1bd1618f1f221371ac7e33bd3a74ce0e4eb34eb31c1d9ce9705bb89
4
+ data.tar.gz: 2bdbfdcc24ee97f440bb78db7bfde7c264dfa119431ce23a2d2e4f6e85fdef9b
5
5
  SHA512:
6
- metadata.gz: befce5978bca1d185780ad8d9da2640f737e2eb6e1f9617f5c49b1b248509bfb583295c80cdf9801b6285434a76c9ad1b14c25d76860379b5ec1548b02a05084
7
- data.tar.gz: 3206c1967e489dac0ed79a311bd3d97a6dedac13bbb629f3252805a1ade2509de176b4fa71bbe4f583542b030a6e5ccbbeb559dd23acea5225df1caacf0d4dbb
6
+ metadata.gz: 35e4e7549fbf0cfbcaddae16be3132c1635b7685459fcfe43bb2c514d47eaaf360d85c1d0136d5b0e57f225e0b9646e63593964557fc3d0343da32b0b163e7c4
7
+ data.tar.gz: e946c80a479c811bb08bb9fca90f6050cab64dff18c665415694ce8d90d46e0fbc3b51512752551fcfc8302eb0e44f56920009fbb15f0e207ea2194c67cb0ca7
@@ -1,22 +1,23 @@
1
1
  require: rubocop-rspec
2
2
 
3
3
  AllCops:
4
- TargetRubyVersion: 2.2
4
+ TargetRubyVersion: 2.3
5
5
  Exclude:
6
6
  - 'spec/coveralls/fixtures/**/*'
7
7
  - 'vendor/bundle/**/*'
8
8
 
9
- Lint/HandleExceptions:
10
- Enabled: false
9
+ Layout/AlignHash:
10
+ EnforcedColonStyle: table
11
+ EnforcedHashRocketStyle: table
11
12
 
12
13
  Metrics/AbcSize:
13
- Max: 37
14
+ Max: 39.29
14
15
 
15
16
  Metrics/CyclomaticComplexity:
16
- Max: 18
17
+ Max: 19
17
18
 
18
19
  Metrics/PerceivedComplexity:
19
- Max: 19
20
+ Max: 20
20
21
 
21
22
  Metrics/BlockLength:
22
23
  Exclude:
@@ -33,10 +34,6 @@ Metrics/ModuleLength:
33
34
  - 'lib/coveralls/configuration.rb'
34
35
  - 'spec/**/*'
35
36
 
36
- Naming/AccessorMethodName:
37
- Exclude:
38
- - 'lib/coveralls/configuration.rb'
39
-
40
37
  RSpec/ExampleLength:
41
38
  Max: 8
42
39
 
@@ -52,7 +49,5 @@ RSpec/NestedGroups:
52
49
  Style/Documentation:
53
50
  Enabled: false
54
51
 
55
- # TODO: Remove when targeting Ruby 2.3 because it is already enabled.
56
- Style/FrozenStringLiteralComment:
57
- Enabled: true
58
- EnforcedStyle: always
52
+ Style/IfUnlessModifier:
53
+ Enabled: false
@@ -2,8 +2,6 @@ language: ruby
2
2
 
3
3
  cache: bundler
4
4
 
5
- sudo: false
6
-
7
5
  before_install:
8
6
  - gem update --system
9
7
  - gem install bundler
@@ -16,15 +14,15 @@ env:
16
14
  - JRUBY_OPTS="--dev --debug"
17
15
 
18
16
  rvm:
19
- - 2.2.10
20
- - 2.3.7
21
- - 2.4.4
22
- - 2.5.1
17
+ - 2.3.8
18
+ - 2.4.6
19
+ - 2.5.5
20
+ - 2.6.3
23
21
  - ruby-head
24
- - jruby-9.2.0.0
22
+ - jruby-9.2.7.0
25
23
 
26
24
  matrix:
27
25
  allow_failures:
28
26
  - rvm: ruby-head
29
- - rvm: jruby-9.2.0.0
27
+ - rvm: jruby-9.2.7.0
30
28
  fast_finish: true
@@ -1,21 +1,3 @@
1
1
  # Changelog
2
2
 
3
3
  ### Please see Github Releases section for current releases.
4
-
5
- ## 0.7.0 (September 18, 2013)
6
-
7
- [Full Changelog](https://github.com/lemurheavy/coveralls-ruby/compare/v0.6.4...v0.7.0)
8
-
9
- Added:
10
- * output silencing (Thanks @elizabrock)
11
- * ruby warning fixes (Thanks @steveklabnik and @Nucc)
12
-
13
- ## 0.6.4 (April 2, 2013)
14
-
15
- [Full Changelog](https://github.com/lemurheavy/coveralls-ruby/compare/v0.6.3...v0.6.4)
16
-
17
- Enhancements:
18
-
19
- * Support [Jenkins CI](http://jenkins-ci.org/)
20
- * Support VCR versions <= 2
21
- * Add SimpleCov filter 'vendor' by default.
data/Gemfile CHANGED
@@ -9,21 +9,16 @@ platforms :jruby do
9
9
  gem 'jruby-openssl', '~> 0.10.1'
10
10
  end
11
11
 
12
- platforms :rbx do
13
- gem 'rubinius-developer_tools', '~> 2.0'
14
- gem 'rubysl', '~> 2.2'
15
- end
16
-
17
12
  group :development do
18
13
  gem 'rake', '~> 12.3'
19
- gem 'rspec', '~> 3.7'
20
- gem 'rubocop', '~> 0.58.2'
21
- gem 'rubocop-rspec', '~> 1.27'
14
+ gem 'rspec', '~> 3.8'
15
+ gem 'rubocop', '~> 0.73.0'
16
+ gem 'rubocop-rspec', '~> 1.33'
22
17
  gem 'truthy', '~> 1.0'
23
- gem 'vcr', '~> 4.0'
24
- gem 'webmock', '~> 3.4'
18
+ gem 'vcr', '~> 5.0'
19
+ gem 'webmock', '~> 3.5'
25
20
  end
26
21
 
27
22
  group :test do
28
- gem 'pry', '~> 0.11.3'
23
+ gem 'pry', '~> 0.12.2'
29
24
  end
data/README.md CHANGED
@@ -7,5 +7,5 @@ An up-to-date fork of [lemurheavy/coveralls-ruby](https://github.com/lemurheavy/
7
7
  Add to your `Gemfile`:
8
8
 
9
9
  ```rb
10
- gem 'coveralls_reborn', '~> 0.12.0', require: false
10
+ gem 'coveralls_reborn', '~> 0.13.0', require: false
11
11
  ```
@@ -18,14 +18,16 @@ Gem::Specification.new do |gem|
18
18
  gem.name = 'coveralls_reborn'
19
19
  gem.require_paths = ['lib']
20
20
  gem.version = Coveralls::VERSION
21
-
22
- gem.required_ruby_version = '>= 2.2'
21
+ gem.metadata = {
22
+ 'source_code_uri' => 'https://github.com/tagliala/coveralls-ruby-reborn'
23
+ }
24
+ gem.required_ruby_version = '>= 2.3'
23
25
 
24
26
  gem.add_dependency 'json', '~> 2.1'
25
- gem.add_dependency 'simplecov', '~> 0.16.1'
27
+ gem.add_dependency 'simplecov', '~> 0.17.0'
26
28
  gem.add_dependency 'term-ansicolor', '~> 1.6'
27
29
  gem.add_dependency 'thor', '~> 0.20.0'
28
30
  gem.add_dependency 'tins', '~> 1.16'
29
31
 
30
- gem.add_development_dependency 'bundler', '~> 1.16'
32
+ gem.add_development_dependency 'bundler', '>= 1.16', '< 3'
31
33
  end
@@ -44,7 +44,9 @@ module Coveralls
44
44
  begin
45
45
  require 'simplecov'
46
46
  @adapter = :simplecov if defined?(::SimpleCov)
47
- rescue StandardError
47
+ rescue StandardError => e
48
+ # TODO: Add error action
49
+ puts e.message
48
50
  end
49
51
  end
50
52
 
@@ -58,7 +60,7 @@ module Coveralls
58
60
  end
59
61
 
60
62
  def start!(simplecov_setting = 'test_frameworks', &block)
61
- return if @adapter != :simplecov
63
+ return unless @adapter == :simplecov
62
64
 
63
65
  ::SimpleCov.add_filter 'vendor'
64
66
 
@@ -82,6 +84,7 @@ module Coveralls
82
84
  # Fail early if we're not on a CI
83
85
  unless will_run?
84
86
  Coveralls::Output.puts('[Coveralls] Outside the CI environment, not sending data.', color: 'yellow')
87
+
85
88
  return false
86
89
  end
87
90
 
@@ -12,43 +12,41 @@ module Coveralls
12
12
  else
13
13
  API_HOST = ENV['COVERALLS_DEVELOPMENT'] ? 'localhost:3000' : 'coveralls.io'
14
14
  API_PROTOCOL = ENV['COVERALLS_DEVELOPMENT'] ? 'http' : 'https'
15
- API_DOMAIN = "#{API_PROTOCOL}://#{API_HOST}".freeze
15
+ API_DOMAIN = "#{API_PROTOCOL}://#{API_HOST}"
16
16
  end
17
17
 
18
- API_BASE = "#{API_DOMAIN}/api/v1".freeze
18
+ API_BASE = "#{API_DOMAIN}/api/v1"
19
19
 
20
- def self.post_json(endpoint, hash)
21
- disable_net_blockers!
22
-
23
- uri = endpoint_to_uri(endpoint)
24
-
25
- Coveralls::Output.puts(JSON.pretty_generate(hash).to_s, color: 'green') if ENV['COVERALLS_DEBUG']
26
- Coveralls::Output.puts("[Coveralls] Submitting to #{API_BASE}", color: 'cyan')
20
+ class << self
21
+ def post_json(endpoint, hash)
22
+ disable_net_blockers!
27
23
 
28
- client = build_client(uri)
29
- request = build_request(uri.path, hash)
24
+ uri = endpoint_to_uri(endpoint)
30
25
 
31
- response = client.request(request)
26
+ Coveralls::Output.puts(JSON.pretty_generate(hash).to_s, color: 'green') if ENV['COVERALLS_DEBUG']
27
+ Coveralls::Output.puts("[Coveralls] Submitting to #{API_BASE}", color: 'cyan')
32
28
 
33
- response_hash = JSON.parse(response.body.to_str)
29
+ client = build_client(uri)
30
+ request = build_request(uri.path, hash)
31
+ response = client.request(request)
32
+ response_hash = JSON.parse(response.body.to_str)
34
33
 
35
- if response_hash['message']
36
- Coveralls::Output.puts("[Coveralls] #{response_hash['message']}", color: 'cyan')
37
- end
34
+ if response_hash['message']
35
+ Coveralls::Output.puts("[Coveralls] #{response_hash['message']}", color: 'cyan')
36
+ end
38
37
 
39
- if response_hash['url']
40
- Coveralls::Output.puts("[Coveralls] #{Coveralls::Output.format(response_hash['url'], color: 'underline')}", color: 'cyan')
41
- end
38
+ if response_hash['url']
39
+ Coveralls::Output.puts("[Coveralls] #{Coveralls::Output.format(response_hash['url'], color: 'underline')}", color: 'cyan')
40
+ end
42
41
 
43
- case response
44
- when Net::HTTPServiceUnavailable
45
- Coveralls::Output.puts('[Coveralls] API timeout occured, but data should still be processed', color: 'red')
46
- when Net::HTTPInternalServerError
47
- Coveralls::Output.puts("[Coveralls] API internal error occured, we're on it!", color: 'red')
42
+ case response
43
+ when Net::HTTPServiceUnavailable
44
+ Coveralls::Output.puts('[Coveralls] API timeout occured, but data should still be processed', color: 'red')
45
+ when Net::HTTPInternalServerError
46
+ Coveralls::Output.puts("[Coveralls] API internal error occured, we're on it!", color: 'red')
47
+ end
48
48
  end
49
- end
50
49
 
51
- class << self
52
50
  private
53
51
 
54
52
  def disable_net_blockers!
@@ -57,7 +55,9 @@ module Coveralls
57
55
 
58
56
  allow = WebMock::Config.instance.allow || []
59
57
  WebMock::Config.instance.allow = [*allow].push API_HOST
60
- rescue LoadError
58
+ rescue StandardError => e
59
+ # TODO: Add error action
60
+ puts e.message
61
61
  end
62
62
 
63
63
  begin
@@ -66,7 +66,9 @@ module Coveralls
66
66
  VCR.send(VCR.version.major < 2 ? :config : :configure) do |c|
67
67
  c.ignore_hosts API_HOST
68
68
  end
69
- rescue LoadError
69
+ rescue StandardError
70
+ # TODO: Add error action
71
+ puts error.message
70
72
  end
71
73
  end
72
74
 
@@ -111,20 +113,24 @@ module Coveralls
111
113
 
112
114
  def hash_to_file(hash)
113
115
  file = nil
114
- Tempfile.open(['coveralls-upload', 'json']) do |f|
116
+
117
+ Tempfile.open(%w[coveralls-upload json]) do |f|
115
118
  f.write(JSON.dump(hash))
116
119
  file = f
117
120
  end
121
+
118
122
  File.new(file.path, 'rb')
119
123
  end
120
124
 
121
125
  def apified_hash(hash)
122
126
  config = Coveralls::Configuration.configuration
127
+
123
128
  if ENV['COVERALLS_DEBUG'] || Coveralls.testing
124
129
  Coveralls::Output.puts '[Coveralls] Submitting with config:', color: 'yellow'
125
130
  output = JSON.pretty_generate(config).gsub(/"repo_token": ?"(.*?)"/, '"repo_token": "[secure]"')
126
131
  Coveralls::Output.puts output, color: 'yellow'
127
132
  end
133
+
128
134
  hash.merge(config)
129
135
  end
130
136
  end
@@ -7,8 +7,10 @@ module Coveralls
7
7
  desc 'push', 'Runs your test suite and pushes the coverage results to Coveralls.'
8
8
  def push
9
9
  return unless ensure_can_run_locally!
10
+
10
11
  ENV['COVERALLS_RUN_LOCALLY'] = 'true'
11
12
  cmds = ['bundle exec rake']
13
+
12
14
  if File.exist?('.travis.yml')
13
15
  cmds = begin
14
16
  YAML.load_file('.travis.yml')['script'] || cmds
@@ -16,14 +18,18 @@ module Coveralls
16
18
  cmds
17
19
  end
18
20
  end
21
+
19
22
  cmds.each { |cmd| system cmd }
23
+
20
24
  ENV['COVERALLS_RUN_LOCALLY'] = nil
21
25
  end
22
26
 
23
27
  desc 'report', 'Runs your test suite locally and displays coverage statistics.'
24
28
  def report
25
29
  ENV['COVERALLS_NOISY'] = 'true'
30
+
26
31
  exec 'bundle exec rake'
32
+
27
33
  ENV['COVERALLS_NOISY'] = nil
28
34
  end
29
35
 
@@ -49,8 +55,11 @@ module Coveralls
49
55
 
50
56
  private
51
57
 
58
+ def config
59
+ Coveralls::Configuration.configuration
60
+ end
61
+
52
62
  def open_token_based_url(url)
53
- config = Coveralls::Configuration.configuration
54
63
  if config[:repo_token]
55
64
  url = url.gsub('%@', config[:repo_token])
56
65
  `open #{url}`
@@ -60,13 +69,13 @@ module Coveralls
60
69
  end
61
70
 
62
71
  def ensure_can_run_locally!
63
- config = Coveralls::Configuration.configuration
64
72
  if config[:repo_token].nil?
65
73
  Coveralls::Output.puts 'Coveralls cannot run locally because no repo_secret_token is set in .coveralls.yml', color: 'red'
66
74
  Coveralls::Output.puts 'Please try again when you get your act together.', color: 'red'
67
75
 
68
76
  return false
69
77
  end
78
+
70
79
  true
71
80
  end
72
81
  end
@@ -5,220 +5,257 @@ require 'securerandom'
5
5
 
6
6
  module Coveralls
7
7
  module Configuration
8
- def self.configuration
9
- config = {
10
- environment: relevant_env,
11
- git: git
12
- }
13
- yml = yaml_config
14
- if yml
15
- config[:configuration] = yml
16
- config[:repo_token] = yml['repo_token'] || yml['repo_secret_token']
17
- end
18
- if ENV['COVERALLS_REPO_TOKEN']
19
- config[:repo_token] = ENV['COVERALLS_REPO_TOKEN']
20
- end
21
- if ENV['COVERALLS_PARALLEL'] && ENV['COVERALLS_PARALLEL'] != 'false'
22
- config[:parallel] = true
23
- end
24
- if ENV['TRAVIS']
25
- set_service_params_for_travis(config, yml ? yml['service_name'] : nil)
26
- elsif ENV['CIRCLECI']
27
- set_service_params_for_circleci(config)
28
- elsif ENV['SEMAPHORE']
29
- set_service_params_for_semaphore(config)
30
- elsif ENV['JENKINS_URL'] || ENV['JENKINS_HOME']
31
- set_service_params_for_jenkins(config)
32
- elsif ENV['APPVEYOR']
33
- set_service_params_for_appveyor(config)
34
- elsif ENV['TDDIUM']
35
- set_service_params_for_tddium(config)
36
- elsif ENV['GITLAB_CI']
37
- set_service_params_for_gitlab(config)
38
- elsif ENV['COVERALLS_RUN_LOCALLY'] || Coveralls.testing
39
- set_service_params_for_coveralls_local(config)
40
- end
41
-
42
- # standardized env vars
43
- set_standard_service_params_for_generic_ci(config)
44
-
45
- if ENV['COVERALLS_SERVICE_NAME']
46
- config[:service_name] = ENV['COVERALLS_SERVICE_NAME']
47
- end
48
-
49
- config
50
- end
8
+ class << self
9
+ def configuration
10
+ config = {
11
+ environment: relevant_env,
12
+ git: git
13
+ }
51
14
 
52
- def self.set_service_params_for_travis(config, service_name)
53
- config[:service_job_id] = ENV['TRAVIS_JOB_ID']
54
- config[:service_pull_request] = ENV['TRAVIS_PULL_REQUEST'] unless ENV['TRAVIS_PULL_REQUEST'] == 'false'
55
- config[:service_name] = service_name || 'travis-ci'
56
- config[:service_branch] = ENV['TRAVIS_BRANCH']
57
- end
15
+ yml = yaml_config
58
16
 
59
- def self.set_service_params_for_circleci(config)
60
- config[:service_name] = 'circleci'
61
- config[:service_number] = ENV['CIRCLE_BUILD_NUM']
62
- config[:service_pull_request] = (ENV['CI_PULL_REQUEST'] || '')[/(\d+)$/, 1]
63
- config[:parallel] = ENV['CIRCLE_NODE_TOTAL'].to_i > 1
64
- config[:service_job_number] = ENV['CIRCLE_NODE_INDEX']
65
- end
17
+ if yml
18
+ config[:configuration] = yml
19
+ config[:repo_token] = yml['repo_token'] || yml['repo_secret_token']
20
+ end
66
21
 
67
- def self.set_service_params_for_semaphore(config)
68
- config[:service_name] = 'semaphore'
69
- config[:service_number] = ENV['SEMAPHORE_BUILD_NUMBER']
70
- config[:service_pull_request] = ENV['PULL_REQUEST_NUMBER']
71
- end
22
+ if ENV['COVERALLS_REPO_TOKEN']
23
+ config[:repo_token] = ENV['COVERALLS_REPO_TOKEN']
24
+ end
72
25
 
73
- def self.set_service_params_for_jenkins(config)
74
- config[:service_name] = 'jenkins'
75
- config[:service_number] = ENV['BUILD_NUMBER']
76
- config[:service_branch] = ENV['BRANCH_NAME']
77
- config[:service_pull_request] = ENV['ghprbPullId']
78
- end
26
+ if ENV['COVERALLS_PARALLEL'] && ENV['COVERALLS_PARALLEL'] != 'false'
27
+ config[:parallel] = true
28
+ end
79
29
 
80
- def self.set_service_params_for_appveyor(config)
81
- config[:service_name] = 'appveyor'
82
- config[:service_number] = ENV['APPVEYOR_BUILD_VERSION']
83
- config[:service_branch] = ENV['APPVEYOR_REPO_BRANCH']
84
- config[:commit_sha] = ENV['APPVEYOR_REPO_COMMIT']
85
- repo_name = ENV['APPVEYOR_REPO_NAME']
86
- config[:service_build_url] = format('https://ci.appveyor.com/project/%<repo_name>s/build/%<service_number>s', repo_name: repo_name, service_number: config[:service_number])
87
- end
30
+ if ENV['COVERALLS_FLAG_NAME']
31
+ config[:flag_name] = ENV['COVERALLS_FLAG_NAME']
32
+ end
88
33
 
89
- def self.set_service_params_for_tddium(config)
90
- config[:service_name] = 'tddium'
91
- config[:service_number] = ENV['TDDIUM_SESSION_ID']
92
- config[:service_job_number] = ENV['TDDIUM_TID']
93
- config[:service_pull_request] = ENV['TDDIUM_PR_ID']
94
- config[:service_branch] = ENV['TDDIUM_CURRENT_BRANCH']
95
- config[:service_build_url] = "https://ci.solanolabs.com/reports/#{ENV['TDDIUM_SESSION_ID']}"
96
- end
34
+ if ENV['TRAVIS']
35
+ define_service_params_for_travis(config, yml ? yml['service_name'] : nil)
36
+ elsif ENV['CIRCLECI']
37
+ define_service_params_for_circleci(config)
38
+ elsif ENV['SEMAPHORE']
39
+ define_service_params_for_semaphore(config)
40
+ elsif ENV['JENKINS_URL'] || ENV['JENKINS_HOME']
41
+ define_service_params_for_jenkins(config)
42
+ elsif ENV['APPVEYOR']
43
+ define_service_params_for_appveyor(config)
44
+ elsif ENV['TDDIUM']
45
+ define_service_params_for_tddium(config)
46
+ elsif ENV['GITLAB_CI']
47
+ define_service_params_for_gitlab(config)
48
+ elsif ENV['COVERALLS_RUN_LOCALLY'] || Coveralls.testing
49
+ define_service_params_for_coveralls_local(config)
50
+ end
97
51
 
98
- def self.set_service_params_for_gitlab(config)
99
- config[:service_name] = 'gitlab-ci'
100
- config[:service_job_number] = ENV['CI_BUILD_NAME']
101
- config[:service_job_id] = ENV['CI_BUILD_ID']
102
- config[:service_branch] = ENV['CI_BUILD_REF_NAME']
103
- config[:commit_sha] = ENV['CI_BUILD_REF']
104
- end
52
+ # standardized env vars
53
+ define_standard_service_params_for_generic_ci(config)
105
54
 
106
- def self.set_service_params_for_coveralls_local(config)
107
- config[:service_job_id] = nil
108
- config[:service_name] = 'coveralls-ruby'
109
- config[:service_event_type] = 'manual'
110
- end
55
+ if ENV['COVERALLS_SERVICE_NAME']
56
+ config[:service_name] = ENV['COVERALLS_SERVICE_NAME']
57
+ end
111
58
 
112
- def self.set_standard_service_params_for_generic_ci(config)
113
- config[:service_name] ||= ENV['CI_NAME']
114
- config[:service_number] ||= ENV['CI_BUILD_NUMBER']
115
- config[:service_job_id] ||= ENV['CI_JOB_ID']
116
- config[:service_build_url] ||= ENV['CI_BUILD_URL']
117
- config[:service_branch] ||= ENV['CI_BRANCH']
118
- config[:service_pull_request] ||= (ENV['CI_PULL_REQUEST'] || '')[/(\d+)$/, 1]
119
- end
59
+ config
60
+ end
120
61
 
121
- def self.yaml_config
122
- return unless configuration_path && File.exist?(configuration_path)
123
- YAML.load_file(configuration_path)
124
- end
62
+ def define_service_params_for_travis(config, service_name)
63
+ config[:service_job_id] = ENV['TRAVIS_JOB_ID']
64
+ config[:service_pull_request] = ENV['TRAVIS_PULL_REQUEST'] unless ENV['TRAVIS_PULL_REQUEST'] == 'false'
65
+ config[:service_name] = service_name || 'travis-ci'
66
+ config[:service_branch] = ENV['TRAVIS_BRANCH']
67
+ end
125
68
 
126
- def self.configuration_path
127
- File.expand_path(File.join(root, '.coveralls.yml')) if root
128
- end
69
+ def define_service_params_for_circleci(config)
70
+ config[:service_name] = 'circleci'
71
+ config[:service_number] = ENV['CIRCLE_BUILD_NUM']
72
+ config[:service_pull_request] = (ENV['CI_PULL_REQUEST'] || '')[/(\d+)$/, 1]
73
+ config[:parallel] = ENV['CIRCLE_NODE_TOTAL'].to_i > 1
74
+ config[:service_job_number] = ENV['CIRCLE_NODE_INDEX']
75
+ end
129
76
 
130
- def self.root
131
- pwd
132
- end
77
+ def define_service_params_for_semaphore(config)
78
+ config[:service_name] = 'semaphore'
79
+ config[:service_number] = ENV['SEMAPHORE_BUILD_NUMBER']
80
+ config[:service_pull_request] = ENV['PULL_REQUEST_NUMBER']
81
+ end
133
82
 
134
- def self.pwd
135
- Dir.pwd
136
- end
83
+ def define_service_params_for_jenkins(config)
84
+ config[:service_name] = 'jenkins'
85
+ config[:service_number] = ENV['BUILD_NUMBER']
86
+ config[:service_branch] = ENV['BRANCH_NAME']
87
+ config[:service_pull_request] = ENV['ghprbPullId']
88
+ end
137
89
 
138
- def self.simplecov_root
139
- ::SimpleCov.root if defined?(::SimpleCov)
140
- end
90
+ def define_service_params_for_appveyor(config)
91
+ config[:service_name] = 'appveyor'
92
+ config[:service_number] = ENV['APPVEYOR_BUILD_VERSION']
93
+ config[:service_branch] = ENV['APPVEYOR_REPO_BRANCH']
94
+ config[:commit_sha] = ENV['APPVEYOR_REPO_COMMIT']
95
+ repo_name = ENV['APPVEYOR_REPO_NAME']
96
+ config[:service_build_url] = format('https://ci.appveyor.com/project/%<repo_name>s/build/%<service_number>s', repo_name: repo_name, service_number: config[:service_number])
97
+ end
141
98
 
142
- def self.rails_root
143
- Rails.root.to_s
144
- rescue StandardError
145
- nil
146
- end
99
+ def define_service_params_for_tddium(config)
100
+ config[:service_name] = 'tddium'
101
+ config[:service_number] = ENV['TDDIUM_SESSION_ID']
102
+ config[:service_job_number] = ENV['TDDIUM_TID']
103
+ config[:service_pull_request] = ENV['TDDIUM_PR_ID']
104
+ config[:service_branch] = ENV['TDDIUM_CURRENT_BRANCH']
105
+ config[:service_build_url] = "https://ci.solanolabs.com/reports/#{ENV['TDDIUM_SESSION_ID']}"
106
+ end
147
107
 
148
- def self.git
149
- hash = {}
150
-
151
- Dir.chdir(root) do
152
- hash[:head] = {
153
- id: ENV.fetch('GIT_ID', `git log -1 --pretty=format:'%H'`),
154
- author_name: ENV.fetch('GIT_AUTHOR_NAME', `git log -1 --pretty=format:'%aN'`),
155
- author_email: ENV.fetch('GIT_AUTHOR_EMAIL', `git log -1 --pretty=format:'%ae'`),
156
- committer_name: ENV.fetch('GIT_COMMITTER_NAME', `git log -1 --pretty=format:'%cN'`),
157
- committer_email: ENV.fetch('GIT_COMMITTER_EMAIL', `git log -1 --pretty=format:'%ce'`),
158
- message: ENV.fetch('GIT_MESSAGE', `git log -1 --pretty=format:'%s'`)
159
- }
108
+ def define_service_params_for_gitlab(config)
109
+ config[:service_name] = 'gitlab-ci'
110
+ config[:service_job_number] = ENV['CI_BUILD_NAME']
111
+ config[:service_job_id] = ENV['CI_BUILD_ID']
112
+ config[:service_branch] = ENV['CI_BUILD_REF_NAME']
113
+ config[:commit_sha] = ENV['CI_BUILD_REF']
114
+ end
160
115
 
161
- # Branch
162
- hash[:branch] = ENV.fetch('GIT_BRANCH', `git rev-parse --abbrev-ref HEAD`)
163
-
164
- # Remotes
165
- remotes = nil
166
- begin
167
- remotes = `git remote -v`.split(/\n/).map do |remote|
168
- splits = remote.split(' ').compact
169
- { name: splits[0], url: splits[1] }
170
- end.uniq
171
- rescue StandardError
172
- end
173
- hash[:remotes] = remotes
116
+ def define_service_params_for_coveralls_local(config)
117
+ config[:service_job_id] = nil
118
+ config[:service_name] = 'coveralls-ruby'
119
+ config[:service_event_type] = 'manual'
174
120
  end
175
121
 
176
- hash
177
- rescue StandardError => e
178
- Coveralls::Output.puts 'Coveralls git error:', color: 'red'
179
- Coveralls::Output.puts e.to_s, color: 'red'
180
- nil
181
- end
122
+ def define_standard_service_params_for_generic_ci(config)
123
+ config[:service_name] ||= ENV['CI_NAME']
124
+ config[:service_number] ||= ENV['CI_BUILD_NUMBER']
125
+ config[:service_job_id] ||= ENV['CI_JOB_ID']
126
+ config[:service_build_url] ||= ENV['CI_BUILD_URL']
127
+ config[:service_branch] ||= ENV['CI_BRANCH']
128
+ config[:service_pull_request] ||= (ENV['CI_PULL_REQUEST'] || '')[/(\d+)$/, 1]
129
+ end
182
130
 
183
- def self.relevant_env
184
- hash = {
185
- pwd: pwd,
186
- rails_root: rails_root,
187
- simplecov_root: simplecov_root,
188
- gem_version: VERSION
189
- }
131
+ def yaml_config
132
+ return unless configuration_path && File.exist?(configuration_path)
190
133
 
191
- hash.merge! begin
192
- if ENV['TRAVIS']
193
- {
194
- travis_job_id: ENV['TRAVIS_JOB_ID'],
195
- travis_pull_request: ENV['TRAVIS_PULL_REQUEST'],
196
- branch: ENV['TRAVIS_BRANCH']
197
- }
198
- elsif ENV['CIRCLECI']
199
- {
200
- circleci_build_num: ENV['CIRCLE_BUILD_NUM'],
201
- branch: ENV['CIRCLE_BRANCH'],
202
- commit_sha: ENV['CIRCLE_SHA1']
203
- }
204
- elsif ENV['JENKINS_URL']
205
- {
206
- jenkins_build_num: ENV['BUILD_NUMBER'],
207
- jenkins_build_url: ENV['BUILD_URL'],
208
- branch: ENV['GIT_BRANCH'],
209
- commit_sha: ENV['GIT_COMMIT']
210
- }
211
- elsif ENV['SEMAPHORE']
212
- {
213
- branch: ENV['BRANCH_NAME'],
214
- commit_sha: ENV['REVISION']
134
+ YAML.load_file(configuration_path)
135
+ end
136
+
137
+ def configuration_path
138
+ return unless root
139
+
140
+ File.expand_path(File.join(root, '.coveralls.yml'))
141
+ end
142
+
143
+ def root
144
+ pwd
145
+ end
146
+
147
+ def pwd
148
+ Dir.pwd
149
+ end
150
+
151
+ def simplecov_root
152
+ return unless defined?(::SimpleCov)
153
+
154
+ ::SimpleCov.root
155
+ end
156
+
157
+ def rails_root
158
+ Rails.root.to_s
159
+ rescue StandardError
160
+ nil
161
+ end
162
+
163
+ def git
164
+ hash = {}
165
+
166
+ Dir.chdir(root) do
167
+ hash[:head] = {
168
+ id: ENV.fetch('GIT_ID', `git log -1 --pretty=format:'%H'`),
169
+ author_name: ENV.fetch('GIT_AUTHOR_NAME', `git log -1 --pretty=format:'%aN'`),
170
+ author_email: ENV.fetch('GIT_AUTHOR_EMAIL', `git log -1 --pretty=format:'%ae'`),
171
+ committer_name: ENV.fetch('GIT_COMMITTER_NAME', `git log -1 --pretty=format:'%cN'`),
172
+ committer_email: ENV.fetch('GIT_COMMITTER_EMAIL', `git log -1 --pretty=format:'%ce'`),
173
+ message: ENV.fetch('GIT_MESSAGE', `git log -1 --pretty=format:'%s'`)
215
174
  }
216
- else
217
- {}
175
+
176
+ # Branch
177
+ hash[:branch] = ENV.fetch('GIT_BRANCH', `git rev-parse --abbrev-ref HEAD`)
178
+
179
+ # Remotes
180
+ remotes = nil
181
+ begin
182
+ remotes = `git remote -v`.split(/\n/).map do |remote|
183
+ splits = remote.split(' ').compact
184
+ { name: splits[0], url: splits[1] }
185
+ end.uniq
186
+ rescue StandardError => e
187
+ # TODO: Add error action
188
+ puts e.message
189
+ end
190
+
191
+ hash[:remotes] = remotes
192
+ end
193
+
194
+ hash
195
+ rescue StandardError => e
196
+ Coveralls::Output.puts 'Coveralls git error:', color: 'red'
197
+ Coveralls::Output.puts e.to_s, color: 'red'
198
+ nil
199
+ end
200
+
201
+ def relevant_env
202
+ hash = {
203
+ pwd: pwd,
204
+ rails_root: rails_root,
205
+ simplecov_root: simplecov_root,
206
+ gem_version: VERSION
207
+ }
208
+
209
+ hash.merge! begin
210
+ if ENV['TRAVIS']
211
+ travis_env_hash
212
+ elsif ENV['CIRCLECI']
213
+ circleci_env_hash
214
+ elsif ENV['JENKINS_URL']
215
+ jenkins_env_hash
216
+ elsif ENV['SEMAPHORE']
217
+ semaphore_env_hash
218
+ else
219
+ {}
220
+ end
218
221
  end
222
+
223
+ hash
224
+ end
225
+
226
+ private
227
+
228
+ def circleci_env_hash
229
+ {
230
+ circleci_build_num: ENV['CIRCLE_BUILD_NUM'],
231
+ branch: ENV['CIRCLE_BRANCH'],
232
+ commit_sha: ENV['CIRCLE_SHA1']
233
+ }
234
+ end
235
+
236
+ def jenkins_env_hash
237
+ {
238
+ jenkins_build_num: ENV['BUILD_NUMBER'],
239
+ jenkins_build_url: ENV['BUILD_URL'],
240
+ branch: ENV['GIT_BRANCH'],
241
+ commit_sha: ENV['GIT_COMMIT']
242
+ }
219
243
  end
220
244
 
221
- hash
245
+ def semaphore_env_hash
246
+ {
247
+ branch: ENV['BRANCH_NAME'],
248
+ commit_sha: ENV['REVISION']
249
+ }
250
+ end
251
+
252
+ def travis_env_hash
253
+ {
254
+ travis_job_id: ENV['TRAVIS_JOB_ID'],
255
+ travis_pull_request: ENV['TRAVIS_PULL_REQUEST'],
256
+ branch: ENV['TRAVIS_BRANCH']
257
+ }
258
+ end
222
259
  end
223
260
  end
224
261
  end