codeclimate-test-reporter 0.6.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +51 -125
- data/bin/cc-tddium-post-worker +1 -1
- data/bin/codeclimate-test-reporter +24 -0
- data/lib/code_climate/test_reporter/calculate_blob.rb +1 -3
- data/lib/code_climate/test_reporter/client.rb +2 -3
- data/lib/code_climate/test_reporter/exception_message.rb +8 -9
- data/lib/code_climate/test_reporter/formatter.rb +18 -52
- data/lib/code_climate/test_reporter/git.rb +4 -6
- data/lib/code_climate/test_reporter/payload_validator.rb +1 -1
- data/lib/code_climate/test_reporter/post_results.rb +30 -0
- data/lib/code_climate/test_reporter/shorten_filename.rb +24 -0
- data/lib/code_climate/test_reporter/version.rb +1 -1
- data/lib/code_climate/test_reporter.rb +25 -8
- data/lib/codeclimate-test-reporter.rb +2 -0
- metadata +10 -12
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5178637634549cf9582b2157406010d9be7b5fd2
|
|
4
|
+
data.tar.gz: 35d82de9aa353cf145183f4c612f7e1ee7f221ed
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e0689fc31b7bcb21b8bc7ce529c2dfb98c45d01596b04c16a1da5b9ed076297dcb2949bb9e3f4012e5bd97476b6d6cf4508f121e021c0bb8ba65535787f19ac6
|
|
7
|
+
data.tar.gz: 7565a72528d0493ed30dd29b3b4869050e5984ad04389a79e47ed87a6ec121f4c61a37b2c814017487b663b96d18e856b1ae5b848fc5f7c07b32a5967f86f0e4
|
data/README.md
CHANGED
|
@@ -2,147 +2,73 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://codeclimate.com/github/codeclimate/ruby-test-reporter)
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
Posts SimpleCov test coverage data from your Ruby test suite to Code Climate's
|
|
6
|
+
hosted, automated code review service.
|
|
7
7
|
|
|
8
8
|
Code Climate - [https://codeclimate.com](https://codeclimate.com)
|
|
9
9
|
|
|
10
|
-
# Important FYIs
|
|
11
|
-
|
|
12
|
-
Across the many different testing frameworks, setups, and environments, there are lots of variables at play. Before setting up test coverage, it's important to understand what we do and do not currently support:
|
|
13
|
-
|
|
14
|
-
* **Default branch only:** We only support test coverage for your [default branch](http://docs.codeclimate.com/article/151-glossary-default-branch). Be sure to check out this branch before running your tests.
|
|
15
|
-
* **Single payload:** We currently only support a single test coverage payload per commit. If you run your tests in multiple steps, or via parallel tests, Code Climate will only process the first payload that we receive. If you are using a CI, be sure to check if you are running your tests in a parallel mode.
|
|
16
|
-
|
|
17
|
-
**Note:** There is one exception to this rule. We've specifically built an integration with [Solano Labs](https://www.solanolabs.com/) to support parallel tests.
|
|
18
|
-
|
|
19
|
-
**Note:** If you've configured Code Climate to analyze multiple languages in the same repository (e.g., Ruby and JavaScript), we can nonetheless only process test coverage information for one of these languages. We'll process the first payload that we receive.
|
|
20
|
-
* **Invalid File Paths:** By default, our test reporters expect your application to exist at the root of your repository. If this is not the case, the file paths in your test coverage payload will not match the file paths that Code Climate expects. For our Ruby test reporter, [we have a work-around to this issue](http://docs.codeclimate.com/article/220-help-im-having-trouble-with-test-coverage#ruby_sub_folder).
|
|
21
|
-
|
|
22
10
|
## Installation
|
|
23
11
|
|
|
24
|
-
This gem requires a user, but not necessarily a paid account, on Code Climate,
|
|
25
|
-
first step is to signup at:
|
|
12
|
+
This gem requires a user, but not necessarily a paid account, on Code Climate,
|
|
13
|
+
so if you don't have one the first step is to signup at:
|
|
14
|
+
[https://codeclimate.com](https://codeclimate.com). Then:
|
|
26
15
|
|
|
27
|
-
|
|
16
|
+
* Add this to your Gemfile:
|
|
28
17
|
|
|
29
|
-
|
|
18
|
+
```ruby
|
|
19
|
+
group :test do
|
|
20
|
+
gem "simplecov"
|
|
21
|
+
gem "codeclimate-test-reporter", "~> 1.0.0"
|
|
22
|
+
end
|
|
23
|
+
```
|
|
30
24
|
|
|
31
|
-
|
|
32
|
-
|
|
25
|
+
* Start SimpleCov as you normally would (more information here:
|
|
26
|
+
https://github.com/colszowka/simplecov)
|
|
27
|
+
* Set the `CODECLIMATE_REPO_TOKEN` environment variable (provided after you add
|
|
28
|
+
your repo to your Code Climate account by clicking on "Setup Test Coverage" on
|
|
29
|
+
the right hand side of your feed)
|
|
30
|
+
* Run the `codeclimate-test-reporter` executable after your test suite
|
|
33
31
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
on your CI server, and the results will show up in your Code Climate account.
|
|
39
|
-
|
|
40
|
-
The `CODECLIMATE_REPO_TOKEN` value is provided after you add your repo to your
|
|
41
|
-
Code Climate account by clicking on "Setup Test Coverage" on the right hand side of your feed.
|
|
32
|
+
```
|
|
33
|
+
bundle exec rake
|
|
34
|
+
bundle exec codeclimate-test-reporter
|
|
35
|
+
```
|
|
42
36
|
|
|
43
37
|
Please contact hello@codeclimate.com if you need any assistance setting this up.
|
|
44
38
|
|
|
45
|
-
##
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
## Troubleshooting
|
|
73
|
-
|
|
74
|
-
If you're having trouble setting up or working with our test coverage feature, [see our detailed help doc](http://docs.codeclimate.com/article/220-help-im-having-trouble-with-test-coverage), which covers the most common issues encountered.
|
|
75
|
-
|
|
76
|
-
## Extending Simplecov with other formatters
|
|
77
|
-
|
|
78
|
-
Since ruby-test-reporter 0.4.0 you can use `CodeClimate::TestReporter::Formatter` as a Simplecov formatter directly. Just add the formatter to your Simplecov formatter in addition to the rest of your configuration:
|
|
79
|
-
|
|
80
|
-
```ruby
|
|
81
|
-
require 'codeclimate-test-reporter'
|
|
82
|
-
SimpleCov.start do
|
|
83
|
-
formatter SimpleCov::Formatter::MultiFormatter.new([
|
|
84
|
-
SimpleCov::Formatter::HTMLFormatter,
|
|
85
|
-
CodeClimate::TestReporter::Formatter
|
|
86
|
-
])
|
|
87
|
-
...
|
|
88
|
-
end
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
## Using with [parallel_tests](https://github.com/grosser/parallel_tests)
|
|
92
|
-
|
|
93
|
-
Note: This may work with other parallel test runners as long as they run on the same machine.
|
|
94
|
-
|
|
95
|
-
Be sure you're using `simplecov` `>= 0.9.0`.
|
|
96
|
-
|
|
97
|
-
Add the following to your `test_helper.rb`/`spec_helper.rb` instead of what is normally required.
|
|
98
|
-
|
|
99
|
-
```ruby
|
|
100
|
-
require 'simplecov'
|
|
101
|
-
require 'codeclimate-test-reporter'
|
|
102
|
-
SimpleCov.add_filter 'vendor'
|
|
103
|
-
SimpleCov.formatters = []
|
|
104
|
-
SimpleCov.start CodeClimate::TestReporter.configuration.profile
|
|
105
|
-
```
|
|
106
|
-
|
|
107
|
-
Then after all your tests run, in a rake task or as a build step do:
|
|
108
|
-
|
|
109
|
-
```
|
|
110
|
-
require 'simplecov'
|
|
111
|
-
require 'codeclimate-test-reporter'
|
|
112
|
-
CodeClimate::TestReporter::Formatter.new.format(SimpleCov.result)
|
|
113
|
-
```
|
|
114
|
-
|
|
115
|
-
## Using with multiple machines
|
|
116
|
-
|
|
117
|
-
For the time-being, we don't officially support coverage data from parallel test runs. That said, [codeclimate batch](https://github.com/grosser/codeclimate_batch) is a handy work-around that was created by one of our customers.
|
|
118
|
-
|
|
119
|
-
Note that this solution requires standing up a separate server (like a Heroku instance) that sits between your testing environment and Code Climate. Though this option is not formally supported, if you have an immediate need for parallel testing support, [codeclimate batch](https://github.com/grosser/codeclimate_batch) is a helpful interim solution until we can release our official support for this.
|
|
120
|
-
|
|
121
|
-
## Help! Your gem is raising a ...
|
|
122
|
-
|
|
123
|
-
### VCR::Errors::UnhandledHTTPRequestError
|
|
124
|
-
|
|
125
|
-
Add the following to your spec or test helper:
|
|
126
|
-
|
|
127
|
-
VCR.configure do |config|
|
|
128
|
-
# your existing configuration
|
|
129
|
-
config.ignore_hosts 'codeclimate.com'
|
|
130
|
-
end
|
|
131
|
-
|
|
132
|
-
### WebMock::NetConnectNotAllowedError
|
|
133
|
-
|
|
134
|
-
Add the following to your spec or test helper:
|
|
135
|
-
|
|
136
|
-
WebMock.disable_net_connect!(:allow => "codeclimate.com")
|
|
137
|
-
|
|
138
|
-
### Other communication failures
|
|
139
|
-
|
|
140
|
-
If you are using a web stubbing library similar to VCR or WebMock which prevent external requests during test runs, you will need configure these libraries to allow Code Climate to make external requests.
|
|
39
|
+
## Troubleshooting / FYIs
|
|
40
|
+
|
|
41
|
+
Across the many different testing frameworks, setups, and environments, there
|
|
42
|
+
are lots of variables at play. If you're having any trouble with your test
|
|
43
|
+
coverage reporting or the results are confusing, please see our full
|
|
44
|
+
documentation here: https://docs.codeclimate.com/docs/setting-up-test-coverage
|
|
45
|
+
|
|
46
|
+
## Upgrading from pre-1.0 Versions
|
|
47
|
+
|
|
48
|
+
Version `1.0` of the this gem introduces new, breaking changes to the way the
|
|
49
|
+
test reporter is meant to be executed. The following list summarizes the major
|
|
50
|
+
differences:
|
|
51
|
+
|
|
52
|
+
* Previously, this gem extended `Simplecov` with a custom formatter which posted
|
|
53
|
+
results to Code Climate. Now, you are responsible for executing `Simplecov`
|
|
54
|
+
yourself, and then running `codeclimate-test-reporter` as a separate step in
|
|
55
|
+
your build.
|
|
56
|
+
* Previously, this gem added some exclusion rules tuned according to feedback
|
|
57
|
+
from its users, and now these no longer happen automatically. *If you are
|
|
58
|
+
experiencing a discrepancy in test coverage % after switching to the new gem
|
|
59
|
+
version, it may be due to missing exclusions. Filtering `vendor`, `spec`, or
|
|
60
|
+
`test` directories may fix this issue.*
|
|
61
|
+
* Previously, during the execution of multiple test suites, this gem would send
|
|
62
|
+
results from the first suite completed. You are now expected to run an
|
|
63
|
+
executable packaged with this gem as a separate build step, which means that
|
|
64
|
+
whatever results are there (likely the results from the last suite) will be
|
|
65
|
+
posted to Code Climate.
|
|
141
66
|
|
|
142
67
|
## Contributions
|
|
143
68
|
|
|
144
69
|
Patches, bug fixes, feature requests, and pull requests are welcome on the
|
|
145
|
-
GitHub page for this project:
|
|
70
|
+
GitHub page for this project:
|
|
71
|
+
[https://github.com/codeclimate/ruby-test-reporter](https://github.com/codeclimate/ruby-test-reporter)
|
|
146
72
|
|
|
147
73
|
This gem is maintained by Bryan Helmkamp (bryan@codeclimate.com).
|
|
148
74
|
|
data/bin/cc-tddium-post-worker
CHANGED
|
@@ -7,7 +7,7 @@ if ENV["CODECLIMATE_REPO_TOKEN"]
|
|
|
7
7
|
tmpdir = Dir.tmpdir
|
|
8
8
|
puts "Searching #{tmpdir} for files to POST."
|
|
9
9
|
coverage_report_files = Dir.glob("#{tmpdir}/codeclimate-test-coverage-*")
|
|
10
|
-
if coverage_report_files.
|
|
10
|
+
if coverage_report_files.any?
|
|
11
11
|
puts "Found: "
|
|
12
12
|
puts coverage_report_files.join("\n")
|
|
13
13
|
client = CodeClimate::TestReporter::Client.new
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "codeclimate-test-reporter"
|
|
4
|
+
|
|
5
|
+
COVERAGE_FILE = "coverage/.resultset.json".freeze
|
|
6
|
+
|
|
7
|
+
if (repo_token = ENV["CODECLIMATE_REPO_TOKEN"]) && !repo_token.empty?
|
|
8
|
+
if File.exist?(COVERAGE_FILE)
|
|
9
|
+
begin
|
|
10
|
+
results = JSON.parse(File.read(COVERAGE_FILE))
|
|
11
|
+
rescue JSON::ParserError => e
|
|
12
|
+
$stderr.puts "Error encountered while parsing #{COVERAGE_FILE}: #{e}"
|
|
13
|
+
exit(1)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
CodeClimate::TestReporter.run(results)
|
|
17
|
+
else
|
|
18
|
+
$stderr.puts "Coverage results not found"
|
|
19
|
+
exit(1)
|
|
20
|
+
end
|
|
21
|
+
else
|
|
22
|
+
$stderr.puts "Cannot post results: environment variable CODECLIMATE_REPO_TOKEN must be set."
|
|
23
|
+
exit(0)
|
|
24
|
+
end
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
module CodeClimate
|
|
2
2
|
module TestReporter
|
|
3
3
|
class CalculateBlob
|
|
4
|
-
|
|
5
4
|
def initialize(file_path)
|
|
6
5
|
@file_path = file_path
|
|
7
6
|
end
|
|
@@ -10,7 +9,7 @@ module CodeClimate
|
|
|
10
9
|
calculate_with_file or calculate_with_git
|
|
11
10
|
end
|
|
12
11
|
|
|
13
|
-
|
|
12
|
+
private
|
|
14
13
|
|
|
15
14
|
def calculate_with_file
|
|
16
15
|
File.open(@file_path, "rb") do |file|
|
|
@@ -31,7 +30,6 @@ module CodeClimate
|
|
|
31
30
|
|
|
32
31
|
output
|
|
33
32
|
end
|
|
34
|
-
|
|
35
33
|
end
|
|
36
34
|
end
|
|
37
35
|
end
|
|
@@ -5,9 +5,8 @@ require "net/https"
|
|
|
5
5
|
module CodeClimate
|
|
6
6
|
module TestReporter
|
|
7
7
|
class Client
|
|
8
|
-
|
|
9
8
|
DEFAULT_TIMEOUT = 5 # in seconds
|
|
10
|
-
USER_AGENT = "Code Climate (Ruby Test Reporter v#{VERSION})"
|
|
9
|
+
USER_AGENT = "Code Climate (Ruby Test Reporter v#{CodeClimate::TestReporter::VERSION})".freeze
|
|
11
10
|
|
|
12
11
|
def host
|
|
13
12
|
ENV["CODECLIMATE_API_HOST"] ||
|
|
@@ -72,7 +71,7 @@ module CodeClimate
|
|
|
72
71
|
end
|
|
73
72
|
end
|
|
74
73
|
|
|
75
|
-
|
|
74
|
+
private
|
|
76
75
|
|
|
77
76
|
def http_client(uri)
|
|
78
77
|
Net::HTTP.new(uri.host, uri.port).tap do |http|
|
|
@@ -6,9 +6,9 @@ module CodeClimate
|
|
|
6
6
|
end
|
|
7
7
|
|
|
8
8
|
def instructions
|
|
9
|
-
|
|
9
|
+
<<-STR
|
|
10
10
|
WebMock.disable_net_connect!(:allow => "codeclimate.com")
|
|
11
|
-
STR
|
|
11
|
+
STR
|
|
12
12
|
end
|
|
13
13
|
end
|
|
14
14
|
|
|
@@ -18,21 +18,20 @@ STR
|
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
def instructions
|
|
21
|
-
|
|
21
|
+
<<-STR
|
|
22
22
|
VCR.configure do |config|
|
|
23
23
|
# your existing configuration
|
|
24
24
|
config.ignore_hosts 'codeclimate.com'
|
|
25
25
|
end
|
|
26
|
-
STR
|
|
26
|
+
STR
|
|
27
27
|
end
|
|
28
28
|
end
|
|
29
29
|
|
|
30
30
|
class ExceptionMessage
|
|
31
|
-
|
|
32
31
|
HTTP_STUBBING_MESSAGES = {
|
|
33
|
-
"VCR::Errors::UnhandledHTTPRequestError" => VCRMessage,
|
|
34
|
-
"WebMock::NetConnectNotAllowedError"
|
|
35
|
-
}
|
|
32
|
+
"VCR::Errors::UnhandledHTTPRequestError".freeze => VCRMessage,
|
|
33
|
+
"WebMock::NetConnectNotAllowedError".freeze => WebMockMessage,
|
|
34
|
+
}.freeze
|
|
36
35
|
|
|
37
36
|
def initialize(exception)
|
|
38
37
|
@exception = exception
|
|
@@ -59,7 +58,7 @@ Add the following to your spec or test helper to ensure codeclimate-test-reporte
|
|
|
59
58
|
parts.join("\n")
|
|
60
59
|
end
|
|
61
60
|
|
|
62
|
-
|
|
61
|
+
private
|
|
63
62
|
|
|
64
63
|
def exception_class
|
|
65
64
|
@exception.class.to_s
|
|
@@ -12,41 +12,27 @@ require "code_climate/test_reporter/payload_validator"
|
|
|
12
12
|
module CodeClimate
|
|
13
13
|
module TestReporter
|
|
14
14
|
class Formatter
|
|
15
|
-
|
|
16
|
-
return true unless CodeClimate::TestReporter.run?
|
|
15
|
+
class InvalidSimpleCovResultError < StandardError; end
|
|
17
16
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
file_path = File.join(Dir.tmpdir, "codeclimate-test-coverage-#{SecureRandom.uuid}.json")
|
|
24
|
-
print "Coverage results saved to #{file_path}... "
|
|
25
|
-
File.open(file_path, "w") { |file| file.write(payload.to_json) }
|
|
26
|
-
else
|
|
27
|
-
client = Client.new
|
|
28
|
-
print "Sending report to #{client.host} for branch #{Git.branch_from_git_or_ci}... "
|
|
29
|
-
client.post_results(payload)
|
|
17
|
+
def format(results)
|
|
18
|
+
begin
|
|
19
|
+
validated_results = results.values.fetch(0).fetch("coverage")
|
|
20
|
+
rescue NoMethodError, KeyError => ex
|
|
21
|
+
raise InvalidSimpleCovResultError, ex.message
|
|
30
22
|
end
|
|
31
23
|
|
|
32
|
-
|
|
33
|
-
true
|
|
34
|
-
rescue => ex
|
|
35
|
-
puts ExceptionMessage.new(ex).message
|
|
36
|
-
false
|
|
37
|
-
end
|
|
24
|
+
simplecov_results = SimpleCov::Result.new(validated_results)
|
|
38
25
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
apply_prefix filename
|
|
26
|
+
payload = to_payload(simplecov_results)
|
|
27
|
+
PayloadValidator.validate(payload)
|
|
28
|
+
|
|
29
|
+
payload
|
|
44
30
|
end
|
|
45
31
|
|
|
46
|
-
|
|
32
|
+
private
|
|
47
33
|
|
|
48
34
|
def partial?
|
|
49
|
-
tddium?
|
|
35
|
+
CodeClimate::TestReporter.tddium?
|
|
50
36
|
end
|
|
51
37
|
|
|
52
38
|
def to_payload(result)
|
|
@@ -62,7 +48,7 @@ module CodeClimate
|
|
|
62
48
|
end
|
|
63
49
|
|
|
64
50
|
{
|
|
65
|
-
name:
|
|
51
|
+
name: ShortenFilename.new(file.filename).short_filename,
|
|
66
52
|
blob_id: CalculateBlob.new(file.filename).blob_id,
|
|
67
53
|
coverage: file.coverage.to_json,
|
|
68
54
|
covered_percent: round(file.covered_percent, 2),
|
|
@@ -70,8 +56,8 @@ module CodeClimate
|
|
|
70
56
|
line_counts: {
|
|
71
57
|
total: file.lines.count,
|
|
72
58
|
covered: file.covered_lines.count,
|
|
73
|
-
missed: file.missed_lines.count
|
|
74
|
-
}
|
|
59
|
+
missed: file.missed_lines.count,
|
|
60
|
+
},
|
|
75
61
|
}
|
|
76
62
|
end
|
|
77
63
|
|
|
@@ -85,40 +71,20 @@ module CodeClimate
|
|
|
85
71
|
partial: partial?,
|
|
86
72
|
git: Git.info,
|
|
87
73
|
environment: {
|
|
88
|
-
test_framework: result.command_name.downcase,
|
|
89
74
|
pwd: Dir.pwd,
|
|
90
75
|
rails_root: (Rails.root.to_s rescue nil),
|
|
91
76
|
simplecov_root: ::SimpleCov.root,
|
|
92
|
-
gem_version: VERSION
|
|
77
|
+
gem_version: VERSION,
|
|
93
78
|
},
|
|
94
|
-
ci_service: ci_service_data
|
|
79
|
+
ci_service: CodeClimate::TestReporter.ci_service_data,
|
|
95
80
|
}
|
|
96
81
|
end
|
|
97
82
|
|
|
98
|
-
def tddium?
|
|
99
|
-
ci_service_data && ci_service_data[:name] == "tddium"
|
|
100
|
-
end
|
|
101
|
-
|
|
102
83
|
# Convert to Float before rounding.
|
|
103
84
|
# Fixes [#7] possible segmentation fault when calling #round on a Rational
|
|
104
85
|
def round(numeric, precision)
|
|
105
86
|
Float(numeric).round(precision)
|
|
106
87
|
end
|
|
107
|
-
|
|
108
|
-
def write_to_file?
|
|
109
|
-
warn "TO_FILE is deprecated, use CODECLIMATE_TO_FILE" if ENV["TO_FILE"]
|
|
110
|
-
tddium? || ENV["CODECLIMATE_TO_FILE"] || ENV["TO_FILE"]
|
|
111
|
-
end
|
|
112
|
-
|
|
113
|
-
def apply_prefix filename
|
|
114
|
-
prefix = CodeClimate::TestReporter.configuration.path_prefix
|
|
115
|
-
return filename if prefix.nil?
|
|
116
|
-
"#{prefix}/#{filename}"
|
|
117
|
-
end
|
|
118
|
-
|
|
119
|
-
def ci_service_data
|
|
120
|
-
@ci_service_data ||= Ci.service_data
|
|
121
|
-
end
|
|
122
88
|
end
|
|
123
89
|
end
|
|
124
90
|
end
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
module CodeClimate
|
|
2
2
|
module TestReporter
|
|
3
3
|
class Git
|
|
4
|
-
|
|
5
4
|
class << self
|
|
6
5
|
def info
|
|
7
6
|
{
|
|
@@ -17,16 +16,16 @@ module CodeClimate
|
|
|
17
16
|
|
|
18
17
|
def clean_service_branch
|
|
19
18
|
ci_branch = String(Ci.service_data[:branch])
|
|
20
|
-
clean = ci_branch.strip.sub(
|
|
19
|
+
clean = ci_branch.strip.sub(%r{^origin/}, "")
|
|
21
20
|
|
|
22
|
-
clean.
|
|
21
|
+
!clean.empty? ? clean : nil
|
|
23
22
|
end
|
|
24
23
|
|
|
25
24
|
def clean_git_branch
|
|
26
25
|
git_branch = String(branch_from_git)
|
|
27
|
-
clean = git_branch.sub(
|
|
26
|
+
clean = git_branch.sub(%r{^origin/}, "") unless git_branch.start_with?("(")
|
|
28
27
|
|
|
29
|
-
clean.
|
|
28
|
+
!clean.empty? ? clean : nil
|
|
30
29
|
end
|
|
31
30
|
|
|
32
31
|
private
|
|
@@ -65,4 +64,3 @@ module CodeClimate
|
|
|
65
64
|
end
|
|
66
65
|
end
|
|
67
66
|
end
|
|
68
|
-
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
module CodeClimate
|
|
2
|
+
module TestReporter
|
|
3
|
+
class PostResults
|
|
4
|
+
def initialize(results)
|
|
5
|
+
@results = results
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def post
|
|
9
|
+
if write_to_file?
|
|
10
|
+
file_path = File.join(Dir.tmpdir, "codeclimate-test-coverage-#{SecureRandom.uuid}.json")
|
|
11
|
+
print "Coverage results saved to #{file_path}... "
|
|
12
|
+
File.open(file_path, "w") { |file| file.write(@results.to_json) }
|
|
13
|
+
else
|
|
14
|
+
client = Client.new
|
|
15
|
+
print "Sending report to #{client.host} for branch #{Git.branch_from_git_or_ci}... "
|
|
16
|
+
client.post_results(@results)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
puts "done."
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
private
|
|
23
|
+
|
|
24
|
+
def write_to_file?
|
|
25
|
+
warn "TO_FILE is deprecated, use CODECLIMATE_TO_FILE" if ENV["TO_FILE"]
|
|
26
|
+
CodeClimate::TestReporter.tddium? || ENV["CODECLIMATE_TO_FILE"] || ENV["TO_FILE"]
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
module CodeClimate
|
|
2
|
+
module TestReporter
|
|
3
|
+
class ShortenFilename
|
|
4
|
+
def initialize(filename)
|
|
5
|
+
@filename = filename
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def short_filename
|
|
9
|
+
return @filename unless ::SimpleCov.root
|
|
10
|
+
apply_prefix @filename.gsub(/^#{::SimpleCov.root}/, ".").gsub(%r{^\./}, "")
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
private
|
|
14
|
+
|
|
15
|
+
def apply_prefix(filename)
|
|
16
|
+
if (prefix = CodeClimate::TestReporter.configuration.path_prefix)
|
|
17
|
+
File.join(prefix, filename)
|
|
18
|
+
else
|
|
19
|
+
filename
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -1,14 +1,23 @@
|
|
|
1
1
|
module CodeClimate
|
|
2
2
|
module TestReporter
|
|
3
|
+
WARNING_MESSAGE = <<-EOS.freeze
|
|
4
|
+
This usage of the Code Climate Test Reporter is now deprecated. Since version
|
|
5
|
+
1.0, we now require you to run `SimpleCov` in your test/spec helper, and then
|
|
6
|
+
run the provided `codeclimate-ruby` binary separately to report your results
|
|
7
|
+
to Code Climate.
|
|
8
|
+
|
|
9
|
+
More information here: https://github.com/codeclimate/ruby-test-reporter/blob/master/README.md
|
|
10
|
+
EOS
|
|
11
|
+
|
|
3
12
|
def self.start
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
13
|
+
logger.warn(WARNING_MESSAGE)
|
|
14
|
+
exit(1)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def self.run(results)
|
|
18
|
+
return unless CodeClimate::TestReporter.run?
|
|
19
|
+
formatted_results = CodeClimate::TestReporter::Formatter.new.format(results)
|
|
20
|
+
CodeClimate::TestReporter::PostResults.new(formatted_results).post
|
|
12
21
|
end
|
|
13
22
|
|
|
14
23
|
def self.run?
|
|
@@ -50,5 +59,13 @@ module CodeClimate
|
|
|
50
59
|
def self.logger
|
|
51
60
|
CodeClimate::TestReporter.configuration.logger
|
|
52
61
|
end
|
|
62
|
+
|
|
63
|
+
def self.tddium?
|
|
64
|
+
ci_service_data && ci_service_data[:name] == "tddium"
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def self.ci_service_data
|
|
68
|
+
Ci.service_data
|
|
69
|
+
end
|
|
53
70
|
end
|
|
54
71
|
end
|
|
@@ -2,6 +2,8 @@ require "code_climate/test_reporter"
|
|
|
2
2
|
require "code_climate/test_reporter/calculate_blob"
|
|
3
3
|
require "code_climate/test_reporter/version"
|
|
4
4
|
require "code_climate/test_reporter/client"
|
|
5
|
+
require "code_climate/test_reporter/post_results"
|
|
6
|
+
require "code_climate/test_reporter/shorten_filename"
|
|
5
7
|
require "code_climate/test_reporter/formatter"
|
|
6
8
|
require "code_climate/test_reporter/configuration"
|
|
7
9
|
require "code_climate/test_reporter/git"
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: codeclimate-test-reporter
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 1.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Bryan Helmkamp
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2016-
|
|
11
|
+
date: 2016-11-04 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: simplecov
|
|
@@ -16,20 +16,14 @@ dependencies:
|
|
|
16
16
|
requirements:
|
|
17
17
|
- - ">="
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: 0
|
|
20
|
-
|
|
21
|
-
- !ruby/object:Gem::Version
|
|
22
|
-
version: 1.0.0
|
|
23
|
-
type: :runtime
|
|
19
|
+
version: '0'
|
|
20
|
+
type: :development
|
|
24
21
|
prerelease: false
|
|
25
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
26
23
|
requirements:
|
|
27
24
|
- - ">="
|
|
28
25
|
- !ruby/object:Gem::Version
|
|
29
|
-
version: 0
|
|
30
|
-
- - "<"
|
|
31
|
-
- !ruby/object:Gem::Version
|
|
32
|
-
version: 1.0.0
|
|
26
|
+
version: '0'
|
|
33
27
|
- !ruby/object:Gem::Dependency
|
|
34
28
|
name: bundler
|
|
35
29
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -106,12 +100,14 @@ email:
|
|
|
106
100
|
- bryan@brynary.com
|
|
107
101
|
executables:
|
|
108
102
|
- cc-tddium-post-worker
|
|
103
|
+
- codeclimate-test-reporter
|
|
109
104
|
extensions: []
|
|
110
105
|
extra_rdoc_files: []
|
|
111
106
|
files:
|
|
112
107
|
- LICENSE.txt
|
|
113
108
|
- README.md
|
|
114
109
|
- bin/cc-tddium-post-worker
|
|
110
|
+
- bin/codeclimate-test-reporter
|
|
115
111
|
- config/cacert.pem
|
|
116
112
|
- lib/code_climate/test_reporter.rb
|
|
117
113
|
- lib/code_climate/test_reporter/calculate_blob.rb
|
|
@@ -122,6 +118,8 @@ files:
|
|
|
122
118
|
- lib/code_climate/test_reporter/formatter.rb
|
|
123
119
|
- lib/code_climate/test_reporter/git.rb
|
|
124
120
|
- lib/code_climate/test_reporter/payload_validator.rb
|
|
121
|
+
- lib/code_climate/test_reporter/post_results.rb
|
|
122
|
+
- lib/code_climate/test_reporter/shorten_filename.rb
|
|
125
123
|
- lib/code_climate/test_reporter/version.rb
|
|
126
124
|
- lib/codeclimate-test-reporter.rb
|
|
127
125
|
homepage: https://github.com/codeclimate/ruby-test-reporter
|
|
@@ -144,7 +142,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
144
142
|
version: '0'
|
|
145
143
|
requirements: []
|
|
146
144
|
rubyforge_project:
|
|
147
|
-
rubygems_version: 2.
|
|
145
|
+
rubygems_version: 2.5.1
|
|
148
146
|
signing_key:
|
|
149
147
|
specification_version: 4
|
|
150
148
|
summary: Uploads Ruby test coverage data to Code Climate.
|