codeclimate_batch 0.1.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 +7 -0
- data/MIT-LICENSE +20 -0
- data/bin/codeclimate-batch +48 -0
- data/lib/codeclimate_batch.rb +59 -0
- data/lib/codeclimate_batch/version.rb +3 -0
- metadata +62 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a62949c60a2a8185556f4bfe335d8eb3b7bebaeb
|
4
|
+
data.tar.gz: 5bf01dc74e06b2d4e55eee340cc863679640807d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: dd5b521bf8557b733a268ea374618d0f6eba55983b6edb65204e30ee49ce18954c1ebd47bbd8beac29ebff56fe82afc9f26f08b801f6331713e717238364723c
|
7
|
+
data.tar.gz: ed12cb796cbd4c4c8123f51f448b2566ff157ded29d9d2127e4ee11d4e8d54c2b1b548218dd91c6e40686a9f81dc1a361e6d4be1c3b4396111186af167c0a2d3
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (C) 2013 Michael Grosser <michael@grosser.it>
|
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.
|
@@ -0,0 +1,48 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# report coverage to code-climate by combining reports from multiple servers
|
3
|
+
|
4
|
+
# enable local usage from cloned repo
|
5
|
+
root = File.expand_path("../..", __FILE__)
|
6
|
+
$LOAD_PATH << "#{root}/lib" if File.exist?("#{root}/Gemfile")
|
7
|
+
|
8
|
+
require 'benchmark'
|
9
|
+
require 'optparse'
|
10
|
+
require 'codeclimate_batch'
|
11
|
+
|
12
|
+
options = {}
|
13
|
+
OptionParser.new do |opts|
|
14
|
+
opts.banner = <<BANNER
|
15
|
+
Report a batch of codeclimate results by merging and from multiple servers
|
16
|
+
|
17
|
+
Usage:
|
18
|
+
codeclimate-batch --groups 4
|
19
|
+
|
20
|
+
Options:
|
21
|
+
BANNER
|
22
|
+
opts.on("--groups COUNT", Integer, "how many groups are being reports?") { |g| options[:groups] = g }
|
23
|
+
opts.on("--key KEY", String, "key to use to report to cc-amend (auto-filled with repo + build-number on travis)") { |k| options[:key] = k }
|
24
|
+
opts.on("-h", "--help","Show this.") { puts opts; exit }
|
25
|
+
opts.on('-v', '--version','Show Version'){ puts CodeclimateBatch::VERSION; exit}
|
26
|
+
end.parse!
|
27
|
+
|
28
|
+
coverage_files = "#{Dir.tmpdir}/codeclimate-test-coverage-*"
|
29
|
+
files = Dir.glob(coverage_files) # if coverage was not run there will be no files
|
30
|
+
success = true
|
31
|
+
|
32
|
+
status = if files.any?
|
33
|
+
time = Benchmark.realtime do
|
34
|
+
content = CodeclimateBatch.unify(files)
|
35
|
+
File.write('report.json', JSON.dump(content))
|
36
|
+
key = options[:key] || "#{ENV.fetch('TRAVIS_REPO_SLUG').tr('/', '-')}-#{ENV.fetch('TRAVIS_BUILD_NUMBER')}"
|
37
|
+
puts `curl -X POST --data-binary @report.json https://cc-amend.herokuapp.com/amend/#{key}?count=#{options.fetch(:groups)}`
|
38
|
+
success = $?.success?
|
39
|
+
system("rm -rf #{coverage_files} report.json") # cleanup in case we run locally
|
40
|
+
end
|
41
|
+
"#{time.round(2)}s to send #{files.size} reports"
|
42
|
+
else
|
43
|
+
"No files found to report"
|
44
|
+
end
|
45
|
+
|
46
|
+
puts "Code climate: #{status}"
|
47
|
+
|
48
|
+
exit(success ? 0 : 1)
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module CodeclimateBatch
|
4
|
+
class << self
|
5
|
+
def unify(coverage_files)
|
6
|
+
initial, *rest = coverage_files
|
7
|
+
report = load(initial)
|
8
|
+
rest.each do |file|
|
9
|
+
merge_source_files(report.fetch("source_files"), load(file).fetch("source_files"))
|
10
|
+
end
|
11
|
+
recalculate_counters(report)
|
12
|
+
report
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def load(file)
|
18
|
+
JSON.load(File.read(file))
|
19
|
+
end
|
20
|
+
|
21
|
+
def recalculate_counters(report)
|
22
|
+
source_files = report.fetch("source_files").map { |s| s["line_counts"] }
|
23
|
+
report["line_counts"].keys.each do |k|
|
24
|
+
report["line_counts"][k] = source_files.map { |s| s[k] }.inject(:+)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def merge_source_files(all, source_files)
|
29
|
+
source_files.each do |new_file|
|
30
|
+
old_file = all.detect { |source_file| source_file["name"] == new_file["name"] }
|
31
|
+
|
32
|
+
if old_file
|
33
|
+
# merge source files
|
34
|
+
coverage = merge_coverage(
|
35
|
+
JSON.load(new_file.fetch("coverage")),
|
36
|
+
JSON.load(old_file.fetch("coverage"))
|
37
|
+
)
|
38
|
+
old_file["coverage"] = JSON.dump(coverage)
|
39
|
+
|
40
|
+
total = coverage.size
|
41
|
+
missed, covered = coverage.compact.partition { |l| l == 0 }.map(&:size)
|
42
|
+
old_file["covered_percent"] = (covered == 0 ? 0.0 : covered * 100.0 / (covered + missed))
|
43
|
+
old_file["line_counts"] = {"total" => total, "covered" => covered, "missed" => missed}
|
44
|
+
else
|
45
|
+
# just use the new value
|
46
|
+
all << new_file
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# [nil,1,0] + [nil,nil,2] -> [nil,1,2]
|
52
|
+
def merge_coverage(a,b)
|
53
|
+
b.map! do |b_count|
|
54
|
+
a_count = a.shift
|
55
|
+
(!b_count && !a_count) ? nil : b_count.to_i + a_count.to_i
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
metadata
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: codeclimate_batch
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Michael Grosser
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-04-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: json
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description:
|
28
|
+
email: michael@grosser.it
|
29
|
+
executables:
|
30
|
+
- codeclimate-batch
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- MIT-LICENSE
|
35
|
+
- bin/codeclimate-batch
|
36
|
+
- lib/codeclimate_batch.rb
|
37
|
+
- lib/codeclimate_batch/version.rb
|
38
|
+
homepage: https://github.com/grosser/codeclimate_batch
|
39
|
+
licenses:
|
40
|
+
- MIT
|
41
|
+
metadata: {}
|
42
|
+
post_install_message:
|
43
|
+
rdoc_options: []
|
44
|
+
require_paths:
|
45
|
+
- lib
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '0'
|
51
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
requirements: []
|
57
|
+
rubyforge_project:
|
58
|
+
rubygems_version: 2.2.2
|
59
|
+
signing_key:
|
60
|
+
specification_version: 4
|
61
|
+
summary: Report a batch of codeclimate results by merging and from multiple servers
|
62
|
+
test_files: []
|