codeclimate-test-reporter 0.0.1
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.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +40 -0
- data/README.md +42 -0
- data/Rakefile +11 -0
- data/codeclimate-test-reporter.gemspec +23 -0
- data/lib/codeclimate-test-reporter.rb +162 -0
- data/spec/spec_helper.rb +7 -0
- metadata +104 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
Copyright (c) 2013 Code Climate LLC
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
20
|
+
|
21
|
+
This gem includes code by Wil Gieseler, distributed under the MIT license:
|
22
|
+
|
23
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
24
|
+
a copy of this software and associated documentation files (the
|
25
|
+
"Software"), to deal in the Software without restriction, including
|
26
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
27
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
28
|
+
permit persons to whom the Software is furnished to do so, subject to
|
29
|
+
the following conditions:
|
30
|
+
|
31
|
+
The above copyright notice and this permission notice shall be
|
32
|
+
included in all copies or substantial portions of the Software.
|
33
|
+
|
34
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
35
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
36
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
37
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
38
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
39
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
40
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# codeclimate-test-reporter
|
2
|
+
|
3
|
+
Collects test coverage data from your Ruby test suite and sends it to Code
|
4
|
+
Climate's hosted, automated code review service. Based on SimpleCov.
|
5
|
+
|
6
|
+
Code Climate - [https://codeclimate.com](https://codeclimate.com)
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
This gem only works with Code Climate accounts, so if you don't have one the
|
11
|
+
first step is to create an account at: [https://codeclimate.com](https://codeclimate.com). Then:
|
12
|
+
|
13
|
+
1. Add this to your Gemfile:
|
14
|
+
|
15
|
+
gem install "codeclimate-test-reporter", group: :test
|
16
|
+
|
17
|
+
1. Start the test reporter **at the very beginning** of your `test_helper.rb` or
|
18
|
+
`spec_helper.rb` file:
|
19
|
+
|
20
|
+
require "codeclimate-test-reporter"
|
21
|
+
CodeClimate::TestReporter.start
|
22
|
+
|
23
|
+
Then set the `CODECLIMATE_REPO_TOKEN` environment variable when you run your build
|
24
|
+
on your CI server, and the results will show up in your Code Climate account.
|
25
|
+
|
26
|
+
The `CODECLIMATE_REPO_TOKEN` value is provided after you add your repo to your
|
27
|
+
Code Climate account.
|
28
|
+
|
29
|
+
Please contact hello@codeclimate.com if you need any assistance setting this up.
|
30
|
+
|
31
|
+
## Contributions
|
32
|
+
|
33
|
+
Patches, bug fixed, feature requests, and pull requests are welcome on the
|
34
|
+
GitHub page for this project: [https://github.com/codeclimate/ruby-test-reporter](https://github.com/codeclimate/ruby-test-reporter)
|
35
|
+
|
36
|
+
This gem is maintained by Bryan Helmkamp (bryan@codeclimate.com).
|
37
|
+
|
38
|
+
## Copyright
|
39
|
+
|
40
|
+
See LICENSE.txt
|
41
|
+
|
42
|
+
Portions of the implementation were inspired by the coveralls-ruby gem.
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "codeclimate-test-reporter"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "codeclimate-test-reporter"
|
8
|
+
spec.version = CodeClimate::TestReporter::VERSION
|
9
|
+
spec.authors = ["Bryan Helmkamp"]
|
10
|
+
spec.email = ["bryan@brynary.com"]
|
11
|
+
spec.description = %q{Collects test coverage data from your Ruby test suite and sends it to Code Climate's hosted, automated code review service. Based on SimpleCov.}
|
12
|
+
spec.summary = %q{Uploads Ruby test coverage data to Code Climate.}
|
13
|
+
spec.homepage = ""
|
14
|
+
|
15
|
+
spec.files = `git ls-files`.split($/)
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_dependency "simplecov", "~> 0.7.1"
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
@@ -0,0 +1,162 @@
|
|
1
|
+
require "json"
|
2
|
+
require "net/https"
|
3
|
+
require "uri"
|
4
|
+
|
5
|
+
module CodeClimate
|
6
|
+
class TestReporter
|
7
|
+
VERSION = "0.0.1"
|
8
|
+
|
9
|
+
class API
|
10
|
+
def self.host
|
11
|
+
ENV["CODECLIMATE_API_HOST"] ||
|
12
|
+
"https://codeclimate.com"
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.post_results(result)
|
16
|
+
uri = URI.parse("#{host}/test_reports")
|
17
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
18
|
+
|
19
|
+
if uri.scheme == "https"
|
20
|
+
http.use_ssl = true
|
21
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
22
|
+
end
|
23
|
+
|
24
|
+
http.open_timeout = 5 # in seconds
|
25
|
+
http.read_timeout = 5 # in seconds
|
26
|
+
|
27
|
+
request = Net::HTTP::Post.new(uri.path)
|
28
|
+
request["Content-Type"] = "application/json"
|
29
|
+
request.body = result.to_json
|
30
|
+
|
31
|
+
response = http.request(request)
|
32
|
+
|
33
|
+
if response.code.to_i >= 200 && response.code.to_i < 300
|
34
|
+
response
|
35
|
+
else
|
36
|
+
raise "HTTP Error: #{response.code}"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
class Formatter
|
42
|
+
def format(result)
|
43
|
+
totals = Hash.new(0)
|
44
|
+
|
45
|
+
source_files = result.files.map do |file|
|
46
|
+
totals[:total] += file.lines.count
|
47
|
+
totals[:covered] += file.covered_lines.count
|
48
|
+
totals[:missed] += file.missed_lines.count
|
49
|
+
|
50
|
+
{
|
51
|
+
name: short_filename(file.filename),
|
52
|
+
coverage: file.coverage.to_json,
|
53
|
+
covered_percent: file.covered_percent.round(2),
|
54
|
+
covered_strength: file.covered_strength.round(2),
|
55
|
+
line_counts: {
|
56
|
+
total: file.lines.count,
|
57
|
+
covered: file.covered_lines.count,
|
58
|
+
missed: file.missed_lines.count
|
59
|
+
}
|
60
|
+
}
|
61
|
+
end
|
62
|
+
|
63
|
+
print "Coverage = #{result.covered_percent.round(2)}%. Sending report to #{API.host}... "
|
64
|
+
|
65
|
+
API.post_results({
|
66
|
+
repo_token: ENV["CODECLIMATE_REPO_TOKEN"],
|
67
|
+
source_files: source_files,
|
68
|
+
run_at: result.created_at,
|
69
|
+
covered_percent: result.covered_percent.round(2),
|
70
|
+
covered_strength: result.covered_strength.round(2),
|
71
|
+
line_counts: totals,
|
72
|
+
git: {
|
73
|
+
head: `git log -1 --pretty=format:'%H'`,
|
74
|
+
committed_at: committed_at,
|
75
|
+
branch: git_branch,
|
76
|
+
},
|
77
|
+
environment: {
|
78
|
+
test_framework: result.command_name.downcase,
|
79
|
+
pwd: Dir.pwd,
|
80
|
+
rails_root: (Rails.root.to_s rescue nil),
|
81
|
+
simplecov_root: ::SimpleCov.root,
|
82
|
+
gem_version: VERSION
|
83
|
+
},
|
84
|
+
ci_service: ci_service_data
|
85
|
+
})
|
86
|
+
|
87
|
+
puts "done."
|
88
|
+
true
|
89
|
+
rescue => ex
|
90
|
+
puts "\nCode Climate encountered an exception: #{ex.class}"
|
91
|
+
puts ex.message
|
92
|
+
ex.backtrace.each do |line|
|
93
|
+
puts line
|
94
|
+
end
|
95
|
+
false
|
96
|
+
end
|
97
|
+
|
98
|
+
def ci_service_data
|
99
|
+
if ENV['TRAVIS']
|
100
|
+
{
|
101
|
+
name: "travis-ci",
|
102
|
+
build_identifier: ENV['TRAVIS_JOB_ID'],
|
103
|
+
pull_request: ENV['TRAVIS_PULL_REQUEST']
|
104
|
+
}
|
105
|
+
elsif ENV['CIRCLECI']
|
106
|
+
{
|
107
|
+
name: "circlci",
|
108
|
+
build_identifier: ENV['CIRCLE_BUILD_NUM'],
|
109
|
+
branch: ENV['CIRCLE_BRANCH'],
|
110
|
+
commit_sha: ENV['CIRCLE_SHA1']
|
111
|
+
}
|
112
|
+
elsif ENV['SEMAPHORE']
|
113
|
+
{
|
114
|
+
name: "semaphore",
|
115
|
+
build_identifier: ENV['SEMAPHORE_BUILD_NUMBER']
|
116
|
+
}
|
117
|
+
elsif ENV['JENKINS_URL']
|
118
|
+
{
|
119
|
+
name: "jenkins",
|
120
|
+
build_identifier: ENV['BUILD_NUMBER'],
|
121
|
+
build_url: ENV['BUILD_URL'],
|
122
|
+
branch: ENV['GIT_BRANCH'],
|
123
|
+
commit_sha: ENV['GIT_COMMIT']
|
124
|
+
}
|
125
|
+
else
|
126
|
+
{}
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
def short_filename(filename)
|
131
|
+
return filename unless ::SimpleCov.root
|
132
|
+
filename.gsub(::SimpleCov.root, '.').gsub(/^\.\//, '')
|
133
|
+
end
|
134
|
+
|
135
|
+
def committed_at
|
136
|
+
committed_at = `git log -1 --pretty=format:'%ct'`
|
137
|
+
committed_at.to_i.zero? ? nil : committed_at.to_i
|
138
|
+
end
|
139
|
+
|
140
|
+
def git_branch
|
141
|
+
branch = `git branch`.split("\n").delete_if { |i| i[0] != "*" }
|
142
|
+
branch = [branch].flatten.first
|
143
|
+
branch ? branch.gsub("* ","") : nil
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
def self.start
|
148
|
+
if run?
|
149
|
+
require "simplecov"
|
150
|
+
::SimpleCov.add_filter 'vendor'
|
151
|
+
::SimpleCov.formatter = Formatter
|
152
|
+
::SimpleCov.start("test_frameworks")
|
153
|
+
else
|
154
|
+
puts("Not reporting to Code Climate because ENV['CODECLIMATE_REPO_TOKEN'] is not set.")
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
def self.run?
|
159
|
+
!!ENV["CODECLIMATE_REPO_TOKEN"]
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: codeclimate-test-reporter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Bryan Helmkamp
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-06-24 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: simplecov
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.7.1
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.7.1
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: bundler
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '1.3'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '1.3'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rake
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
description: Collects test coverage data from your Ruby test suite and sends it to
|
63
|
+
Code Climate's hosted, automated code review service. Based on SimpleCov.
|
64
|
+
email:
|
65
|
+
- bryan@brynary.com
|
66
|
+
executables: []
|
67
|
+
extensions: []
|
68
|
+
extra_rdoc_files: []
|
69
|
+
files:
|
70
|
+
- .gitignore
|
71
|
+
- Gemfile
|
72
|
+
- LICENSE.txt
|
73
|
+
- README.md
|
74
|
+
- Rakefile
|
75
|
+
- codeclimate-test-reporter.gemspec
|
76
|
+
- lib/codeclimate-test-reporter.rb
|
77
|
+
- spec/spec_helper.rb
|
78
|
+
homepage: ''
|
79
|
+
licenses: []
|
80
|
+
post_install_message:
|
81
|
+
rdoc_options: []
|
82
|
+
require_paths:
|
83
|
+
- lib
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
85
|
+
none: false
|
86
|
+
requirements:
|
87
|
+
- - ! '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
none: false
|
92
|
+
requirements:
|
93
|
+
- - ! '>='
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
requirements: []
|
97
|
+
rubyforge_project:
|
98
|
+
rubygems_version: 1.8.23
|
99
|
+
signing_key:
|
100
|
+
specification_version: 3
|
101
|
+
summary: Uploads Ruby test coverage data to Code Climate.
|
102
|
+
test_files:
|
103
|
+
- spec/spec_helper.rb
|
104
|
+
has_rdoc:
|