pullreview-coverage 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.
- checksums.yaml +7 -0
- data/.gitignore +16 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +20 -0
- data/README.md +56 -0
- data/Rakefile +1 -0
- data/lib/pullreview/coverage/client_api.rb +109 -0
- data/lib/pullreview/coverage/config.rb +51 -0
- data/lib/pullreview/coverage/continuous_build.rb +122 -0
- data/lib/pullreview/coverage/formatter.rb +82 -0
- data/lib/pullreview/coverage/git.rb +83 -0
- data/lib/pullreview/coverage/version.rb +6 -0
- data/lib/pullreview/coverage.rb +22 -0
- data/pullreview-coverage.gemspec +24 -0
- metadata +106 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 43dbef35aeec4ac67f0b747299bc1bc04efba654
|
4
|
+
data.tar.gz: 22bbb19335f218f594a243262e3b5be15f538926
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: aab646b40c2f4e49689f9e092f7c17748daf23cb25580a204b3bf8c0811dc366d076b4b77c3dfbe71836f3b189fcc4d3cf7a55c7437c9dc794a8a93d54d3cdbb
|
7
|
+
data.tar.gz: 03fb513a645b250673185a6b14182c7b2eaf9a8bfcdae47a965e7a597d19e939b1bb57d89cbd8bb2d72386648b6288d82a61afc666a7ad6f4f3f8c847288678f
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
# Pullreview::Coverage
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
group :test, :development do
|
11
|
+
# .... your other test gem like simplecov
|
12
|
+
gem 'pullreview-coverage', require: false
|
13
|
+
end
|
14
|
+
```
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
Adapt your SimpleCov Formatter listing to add the PullReview formatter.
|
23
|
+
This formatter will post over https the coverage report and a few additional informations.
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
require 'simplecov'
|
27
|
+
require 'simplecov-rcov'
|
28
|
+
require 'pullreview/coverage'
|
29
|
+
|
30
|
+
formatters = [SimpleCov::Formatter::HTMLFormatter]
|
31
|
+
formatters << SimpleCov::Formatter::RcovFormatter if ENV['BUILD_ID'] # sample jenkins-ci formatter
|
32
|
+
formatters << PullReview::Coverage::Formatter
|
33
|
+
|
34
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[*formatters]
|
35
|
+
|
36
|
+
```
|
37
|
+
|
38
|
+
## How can I check the content submitted to pullreview
|
39
|
+
|
40
|
+
In your project directory, launch
|
41
|
+
|
42
|
+
```
|
43
|
+
PULLREVIEW_REPO_TOKEN=4564654 PULLREVIEW_COVERAGE_TO_FILE=true rake test
|
44
|
+
....
|
45
|
+
PullReview::Coverage : info : Generated /tmp/coverage-8c2c37dd-8412-4137-9b38-7147c1662140.json
|
46
|
+
```
|
47
|
+
|
48
|
+
A json file will be generated in /tmp/ the content might change a little bit depending on your environment (dev, ci)
|
49
|
+
|
50
|
+
## Contributing
|
51
|
+
|
52
|
+
1. Fork it ( http://github.com/<my-github-username>/pullreview-coverage/fork )
|
53
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
54
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
55
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
56
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,109 @@
|
|
1
|
+
require 'securerandom'
|
2
|
+
require 'tmpdir'
|
3
|
+
|
4
|
+
module PullReview
|
5
|
+
module Coverage
|
6
|
+
# Local file based implementation
|
7
|
+
# ease testing/debugging coverage report content generation
|
8
|
+
class LocalFileApi
|
9
|
+
attr_reader :config
|
10
|
+
|
11
|
+
def initialize(config)
|
12
|
+
@config = config || Config.new
|
13
|
+
end
|
14
|
+
|
15
|
+
# generate a random file in tmp dir with the same json payload (except pretty formatted)
|
16
|
+
def publish(payload)
|
17
|
+
file_path = File.join(Dir.tmpdir, "coverage-#{SecureRandom.uuid}.json")
|
18
|
+
File.open(file_path, 'w') { |file| file.write(JSON.pretty_generate(payload)) }
|
19
|
+
PullReview::Coverage.log(:info, "Generated #{file_path}")
|
20
|
+
file_path
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# Remote api based implementation for production intent
|
25
|
+
class ClientApi
|
26
|
+
attr_reader :config
|
27
|
+
|
28
|
+
def initialize(config)
|
29
|
+
@config = config || Config.new
|
30
|
+
end
|
31
|
+
|
32
|
+
# post json payload to pullreview host.
|
33
|
+
def publish(payload)
|
34
|
+
allow_pullreview_webmock
|
35
|
+
allow_pullreview_vcr
|
36
|
+
response = post(payload)
|
37
|
+
"#{response.code} : #{response.body}"
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
# post the payload and return exception if error occured.
|
43
|
+
def post(payload)
|
44
|
+
response = http(config.api_uri).request(zipped_post(config.api_uri, payload))
|
45
|
+
if response.code.to_i >= 200 && response.code.to_i < 300
|
46
|
+
response
|
47
|
+
else
|
48
|
+
raise "HTTP Error: #{response.code} #{config.api_uri}"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
# return Net::HTTP::Post with gzipped json payload
|
53
|
+
def zipped_post(uri, payload)
|
54
|
+
request = Net::HTTP::Post.new(uri.path)
|
55
|
+
request['User-Agent'] = config.user_agent
|
56
|
+
request['X-Repo-Token'] = config.repo_token
|
57
|
+
request['Content-Type'] = 'application/json'
|
58
|
+
request['Content-Encoding'] = 'gzip'
|
59
|
+
request.body = compress(payload.to_json)
|
60
|
+
|
61
|
+
request
|
62
|
+
end
|
63
|
+
|
64
|
+
# return gzipped str
|
65
|
+
def compress(str)
|
66
|
+
sio = StringIO.new('w')
|
67
|
+
# don't use the block notation for StringIO
|
68
|
+
# https://bugs.ruby-lang.org/issues/8935
|
69
|
+
gz = Zlib::GzipWriter.new(sio)
|
70
|
+
gz.write(str)
|
71
|
+
gz.close
|
72
|
+
sio.string
|
73
|
+
end
|
74
|
+
|
75
|
+
# Return an Net::HTTP configured with timeout and https certificate verification if necessary
|
76
|
+
def http(uri)
|
77
|
+
Net::HTTP.new(uri.host, uri.port).tap do |http|
|
78
|
+
if uri.scheme == 'https'
|
79
|
+
http.use_ssl = true
|
80
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
81
|
+
http.verify_depth = 5
|
82
|
+
end
|
83
|
+
http.open_timeout = config.api_open_timeout_in_seconds
|
84
|
+
http.read_timeout = config.api_read_timeout_in_seconds
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
# white list the pullreview host for webmock
|
89
|
+
def allow_pullreview_webmock
|
90
|
+
if defined?(WebMock) && allow = WebMock::Config.instance.allow || []
|
91
|
+
WebMock::Config.instance.allow = [*allow].push(config.api_host)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
# white list the pullreview host for vcr
|
96
|
+
def allow_pullreview_vcr
|
97
|
+
if defined?(VCR)
|
98
|
+
VCR.send(VCR.version.major < 2 ? :config : :configure) do |c|
|
99
|
+
c.ignore_hosts(config.api_host)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def to_s
|
105
|
+
"ClientApi : #{config.api_uri}"
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'uri'
|
2
|
+
module PullReview
|
3
|
+
module Coverage
|
4
|
+
# PullReview api coverage settings, allow overwriting via ENV for dev/testing
|
5
|
+
class Config
|
6
|
+
def api_host
|
7
|
+
ENV['PULLREVIEW_HOST'] || 'www.pullreview.com'
|
8
|
+
end
|
9
|
+
|
10
|
+
def api_protocol
|
11
|
+
ENV['PULLREVIEW_PROTOCOL'] || 'https'
|
12
|
+
end
|
13
|
+
|
14
|
+
def api_port
|
15
|
+
ENV['PULLREVIEW_PORT'] || '443'
|
16
|
+
end
|
17
|
+
|
18
|
+
def api_to_file?
|
19
|
+
!!ENV['PULLREVIEW_COVERAGE_TO_FILE']
|
20
|
+
end
|
21
|
+
|
22
|
+
def api_read_timeout_in_seconds
|
23
|
+
ENV['PULLREVIEW_READ_TIMEOUT_S'] || 5
|
24
|
+
end
|
25
|
+
|
26
|
+
def api_open_timeout_in_seconds
|
27
|
+
ENV['PULLREVIEW_OPEN_TIMEOUT_S'] || 5
|
28
|
+
end
|
29
|
+
|
30
|
+
def api_https_cacert
|
31
|
+
File.expand_path('../../../../config/cacert.pem', __FILE__)
|
32
|
+
end
|
33
|
+
|
34
|
+
def user_agent
|
35
|
+
"PullReview::Coverage.#{VERSION}"
|
36
|
+
end
|
37
|
+
|
38
|
+
def repo_token
|
39
|
+
ENV['PULLREVIEW_REPO_TOKEN']
|
40
|
+
end
|
41
|
+
|
42
|
+
def should_run?
|
43
|
+
!!repo_token
|
44
|
+
end
|
45
|
+
|
46
|
+
def api_uri
|
47
|
+
URI("#{api_protocol}://#{api_host}:#{api_port}/api/coverage")
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,122 @@
|
|
1
|
+
module PullReview
|
2
|
+
module Coverage
|
3
|
+
# Various continuous build providers
|
4
|
+
module ContinousBuild
|
5
|
+
# https://travis-ci.org/
|
6
|
+
class TravisCi
|
7
|
+
def enabled?
|
8
|
+
!!ENV['TRAVIS']
|
9
|
+
end
|
10
|
+
#:nodoc
|
11
|
+
def infos
|
12
|
+
{
|
13
|
+
name: 'travis-ci',
|
14
|
+
branch: ENV['TRAVIS_BRANCH'],
|
15
|
+
build_id: ENV['TRAVIS_JOB_ID'],
|
16
|
+
pull_request: ENV['TRAVIS_PULL_REQUEST']
|
17
|
+
}
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# https://circleci.com/
|
22
|
+
class CircleCi
|
23
|
+
def enabled?
|
24
|
+
!!ENV['CIRCLECI']
|
25
|
+
end
|
26
|
+
|
27
|
+
#:nodoc
|
28
|
+
def infos
|
29
|
+
{
|
30
|
+
name: 'circleci',
|
31
|
+
build_id: ENV['CIRCLE_BUILD_NUM'],
|
32
|
+
branch: ENV['CIRCLE_BRANCH'],
|
33
|
+
commit_sha: ENV['CIRCLE_SHA1']
|
34
|
+
}
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# https://semaphoreapp.com/
|
39
|
+
class Semaphore
|
40
|
+
def enabled?
|
41
|
+
!!ENV['SEMAPHORE']
|
42
|
+
end
|
43
|
+
|
44
|
+
#:nodoc
|
45
|
+
def infos
|
46
|
+
{
|
47
|
+
name: 'semaphore',
|
48
|
+
branch: ENV['BRANCH_NAME'],
|
49
|
+
build_id: ENV['SEMAPHORE_BUILD_NUMBER']
|
50
|
+
}
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# http://jenkins-ci.org/
|
55
|
+
class Jenkins
|
56
|
+
def enabled?
|
57
|
+
!!ENV['JENKINS_URL']
|
58
|
+
end
|
59
|
+
|
60
|
+
#:nodoc
|
61
|
+
def infos
|
62
|
+
{
|
63
|
+
name: 'jenkins',
|
64
|
+
build_id: ENV['BUILD_NUMBER'],
|
65
|
+
build_url: ENV['BUILD_URL'],
|
66
|
+
branch: ENV['GIT_BRANCH'],
|
67
|
+
commit_sha: ENV['GIT_COMMIT']
|
68
|
+
}
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
# https://www.codeship.io/
|
73
|
+
class Codeship
|
74
|
+
def enabled?
|
75
|
+
ENV['CI_NAME'] =~ /codeship/i
|
76
|
+
end
|
77
|
+
|
78
|
+
#:nodoc
|
79
|
+
def infos
|
80
|
+
{
|
81
|
+
name: 'codeship',
|
82
|
+
build_id: ENV['CI_BUILD_NUMBER'],
|
83
|
+
build_url: ENV['CI_BUILD_URL'],
|
84
|
+
branch: ENV['CI_BRANCH'],
|
85
|
+
commit_sha: ENV['CI_COMMIT_ID']
|
86
|
+
}
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
# Damned you should really get one !
|
91
|
+
class None
|
92
|
+
def enabled?
|
93
|
+
true
|
94
|
+
end
|
95
|
+
|
96
|
+
#:nodoc
|
97
|
+
def infos
|
98
|
+
{}
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
# return hash with ci build info like
|
103
|
+
# name, build_id, build_url, branch, commit_sha if provided via ENV
|
104
|
+
def self.infos
|
105
|
+
provider.infos
|
106
|
+
end
|
107
|
+
|
108
|
+
private
|
109
|
+
|
110
|
+
def self.provider
|
111
|
+
[
|
112
|
+
TravisCi.new,
|
113
|
+
CircleCi.new,
|
114
|
+
Semaphore.new,
|
115
|
+
Jenkins.new,
|
116
|
+
Codeship.new,
|
117
|
+
None.new
|
118
|
+
].find { |ci| ci.enabled? }
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
module PullReview
|
2
|
+
module Coverage
|
3
|
+
# A simplecov Formatter implementation
|
4
|
+
# see README.md for usage.
|
5
|
+
class Formatter
|
6
|
+
# Simplecov callback to format report
|
7
|
+
def format(result)
|
8
|
+
return unless config.should_run?
|
9
|
+
response = api.publish(to_payload(result))
|
10
|
+
PullReview::Coverage.log(:info, "Coverage report ok #{api} : #{response}")
|
11
|
+
rescue => e
|
12
|
+
PullReview::Coverage.log(:error, "Coverage report submission failed #{api}", e)
|
13
|
+
end
|
14
|
+
|
15
|
+
def config
|
16
|
+
@config ||= PullReview::Coverage::Config.new
|
17
|
+
end
|
18
|
+
|
19
|
+
# return based on config a remote api client or a local file implementation.
|
20
|
+
def api
|
21
|
+
config.api_to_file? ? PullReview::Coverage::LocalFileApi.new(config) : PullReview::Coverage::ClientApi.new(config)
|
22
|
+
end
|
23
|
+
|
24
|
+
# Transform simplecov result to huge hash.
|
25
|
+
def to_payload(result)
|
26
|
+
totals = Hash.new(0)
|
27
|
+
sources = sources_coverage(result, totals)
|
28
|
+
{
|
29
|
+
repo_token: config.repo_token,
|
30
|
+
files_coverage: sources,
|
31
|
+
run_at: result.created_at.to_i,
|
32
|
+
covered_percent: round(result.covered_percent, 2),
|
33
|
+
covered_strength: round(result.covered_strength, 2),
|
34
|
+
line_counts: totals,
|
35
|
+
git_info: Git.new.infos,
|
36
|
+
environment: {
|
37
|
+
test_framework: result.command_name.downcase,
|
38
|
+
pwd: Dir.pwd,
|
39
|
+
rails_root: (Rails.root.to_s rescue nil),
|
40
|
+
simplecov_root: ::SimpleCov.root,
|
41
|
+
gem_version: VERSION
|
42
|
+
},
|
43
|
+
ci_info: ContinousBuild.infos
|
44
|
+
}
|
45
|
+
end
|
46
|
+
|
47
|
+
# return array of hash with coverage details for each files
|
48
|
+
# a side effect is calculating the coverage's totals
|
49
|
+
def sources_coverage(result, totals)
|
50
|
+
sources = result.files.map do |file|
|
51
|
+
file_name = short_filename(file.filename)
|
52
|
+
next if file_name.start_with?('vendor')
|
53
|
+
totals[:total] += file.lines.count
|
54
|
+
totals[:covered] += file.covered_lines.count
|
55
|
+
totals[:missed] += file.missed_lines.count
|
56
|
+
{
|
57
|
+
name: file_name,
|
58
|
+
coverage_details: file.coverage.to_json,
|
59
|
+
covered_percent: round(file.covered_percent, 2),
|
60
|
+
covered_strength: round(file.covered_strength, 2),
|
61
|
+
line_counts: {
|
62
|
+
total: file.lines.count,
|
63
|
+
covered: file.covered_lines.count,
|
64
|
+
missed: file.missed_lines.count
|
65
|
+
}
|
66
|
+
}
|
67
|
+
end
|
68
|
+
sources
|
69
|
+
end
|
70
|
+
|
71
|
+
def short_filename(filename)
|
72
|
+
return filename unless ::SimpleCov.root
|
73
|
+
filename = filename.gsub(::SimpleCov.root, '.').gsub(/^\.\//, '')
|
74
|
+
filename
|
75
|
+
end
|
76
|
+
|
77
|
+
def round(numeric, precision)
|
78
|
+
Float(numeric).round(precision)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
module PullReview
|
2
|
+
module Coverage
|
3
|
+
# Fetch git infos
|
4
|
+
class Git
|
5
|
+
# return hash with head,
|
6
|
+
# head: all commit information
|
7
|
+
# sha, author, committer, message, committed_at
|
8
|
+
# remotes: list of git urls (name url)
|
9
|
+
# committed_at: commit time(as UNIX timestamp)
|
10
|
+
# branch: name of the branch.
|
11
|
+
def infos
|
12
|
+
{
|
13
|
+
head: last_commit,
|
14
|
+
remotes: remotes,
|
15
|
+
branch: branch_from_git_or_continuous_build
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def last_commit
|
22
|
+
{
|
23
|
+
sha: `git log -1 --pretty=format:'%H'`.strip,
|
24
|
+
author_name: `git log -1 --pretty=format:'%aN'`.strip,
|
25
|
+
author_email: `git log -1 --pretty=format:'%ae'`.strip,
|
26
|
+
committer_name: `git log -1 --pretty=format:'%cN'`.strip,
|
27
|
+
committer_email: `git log -1 --pretty=format:'%ce'`.strip,
|
28
|
+
message: `git log -1 --pretty=format:'%s'`.strip,
|
29
|
+
committed_at: committed_at
|
30
|
+
}
|
31
|
+
end
|
32
|
+
|
33
|
+
def remotes
|
34
|
+
remotes = nil
|
35
|
+
begin
|
36
|
+
remotes = `git remote -v`.split(/\n/).map do |remote|
|
37
|
+
splits = remote.split(' ').compact
|
38
|
+
{ name: splits[0], url: splits[1] }
|
39
|
+
end.uniq
|
40
|
+
rescue => e
|
41
|
+
PullReview::Coverage.log(:warn, 'failed to fetch remotes urls', e)
|
42
|
+
end
|
43
|
+
remotes
|
44
|
+
end
|
45
|
+
|
46
|
+
# Cover case when fetching the branch name isn't obvious
|
47
|
+
# git clone --depth=50 git://github.com/rails/rails.git rails/rails
|
48
|
+
# cd rails/rails
|
49
|
+
# git fetch origin +refs/pull/14423/merge:
|
50
|
+
# git checkout -qf FETCH_HEAD
|
51
|
+
# git branch
|
52
|
+
# /tmp/rails/rails [:cb7ba03] > git branch
|
53
|
+
# * (no branch)
|
54
|
+
# master
|
55
|
+
def branch_from_git_or_continuous_build
|
56
|
+
git_branch = branch_from_git
|
57
|
+
ci_branch = ContinousBuild.infos[:branch]
|
58
|
+
branch = 'master'
|
59
|
+
if ci_branch.to_s.strip.size > 0
|
60
|
+
branch = ci_branch
|
61
|
+
elsif git_branch.to_s.strip.size > 0 && !git_branch.to_s.strip.start_with?('(')
|
62
|
+
branch = git_branch
|
63
|
+
end
|
64
|
+
cleanup_branch(branch)
|
65
|
+
end
|
66
|
+
|
67
|
+
def cleanup_branch(branch)
|
68
|
+
branch.sub(/^origin\//, '')
|
69
|
+
end
|
70
|
+
|
71
|
+
def committed_at
|
72
|
+
committed_at = `git log -1 --pretty=format:'%ct'`
|
73
|
+
committed_at.to_i.zero? ? nil : committed_at.to_i
|
74
|
+
end
|
75
|
+
|
76
|
+
def branch_from_git
|
77
|
+
branch = `git branch`.split("\n").delete_if { |i| i[0] != '*' }
|
78
|
+
branch = [branch].flatten.first
|
79
|
+
branch ? branch.gsub('* ', '') : nil
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# https://www.pullreview.com
|
2
|
+
module PullReview
|
3
|
+
# Collect coverage report to generate action points for the review.
|
4
|
+
module Coverage
|
5
|
+
# log to stdout message and optional exception at a given level
|
6
|
+
def self.log(level, message, exception = nil)
|
7
|
+
full_message = ["PullReview::Coverage : #{level} : #{message}"]
|
8
|
+
if exception
|
9
|
+
full_message << "#{exception.message} #{exception.class}"
|
10
|
+
full_message << exception.backtrace.join("\n")
|
11
|
+
end
|
12
|
+
puts full_message.join("\n")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
require_relative 'coverage/version'
|
18
|
+
require_relative 'coverage/config'
|
19
|
+
require_relative 'coverage/continuous_build'
|
20
|
+
require_relative 'coverage/git'
|
21
|
+
require_relative 'coverage/client_api'
|
22
|
+
require_relative 'coverage/formatter'
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'pullreview/coverage/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'pullreview-coverage'
|
8
|
+
spec.version = PullReview::Coverage::VERSION
|
9
|
+
spec.authors = ['Stephan Mestach']
|
10
|
+
spec.email = ['stephan.mestach@8thcolor.com']
|
11
|
+
spec.summary = %q{Collect coverage information and send them to PullReview.com}
|
12
|
+
spec.description = %q{Collect coverage information generated by simplecov and send them to PullReview.com}
|
13
|
+
spec.homepage = 'https://www.pullreview.com'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_dependency 'simplecov', '>= 0.7.1', '< 1.0.0'
|
22
|
+
spec.add_development_dependency 'bundler', '~> 1.5'
|
23
|
+
spec.add_development_dependency 'rake'
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pullreview-coverage
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Stephan Mestach
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-04-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: simplecov
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.7.1
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.0.0
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.7.1
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 1.0.0
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: bundler
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '1.5'
|
40
|
+
type: :development
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '1.5'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rake
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
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
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
description: Collect coverage information generated by simplecov and send them to
|
62
|
+
PullReview.com
|
63
|
+
email:
|
64
|
+
- stephan.mestach@8thcolor.com
|
65
|
+
executables: []
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files: []
|
68
|
+
files:
|
69
|
+
- ".gitignore"
|
70
|
+
- Gemfile
|
71
|
+
- LICENSE.txt
|
72
|
+
- README.md
|
73
|
+
- Rakefile
|
74
|
+
- lib/pullreview/coverage.rb
|
75
|
+
- lib/pullreview/coverage/client_api.rb
|
76
|
+
- lib/pullreview/coverage/config.rb
|
77
|
+
- lib/pullreview/coverage/continuous_build.rb
|
78
|
+
- lib/pullreview/coverage/formatter.rb
|
79
|
+
- lib/pullreview/coverage/git.rb
|
80
|
+
- lib/pullreview/coverage/version.rb
|
81
|
+
- pullreview-coverage.gemspec
|
82
|
+
homepage: https://www.pullreview.com
|
83
|
+
licenses:
|
84
|
+
- MIT
|
85
|
+
metadata: {}
|
86
|
+
post_install_message:
|
87
|
+
rdoc_options: []
|
88
|
+
require_paths:
|
89
|
+
- lib
|
90
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
requirements: []
|
101
|
+
rubyforge_project:
|
102
|
+
rubygems_version: 2.2.2
|
103
|
+
signing_key:
|
104
|
+
specification_version: 4
|
105
|
+
summary: Collect coverage information and send them to PullReview.com
|
106
|
+
test_files: []
|