circleci-coverage_reporter 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +4 -0
- data/CHANGELOG.md +9 -1
- data/Gemfile +1 -0
- data/README.md +10 -19
- data/Rakefile +1 -1
- data/bin/rspec +18 -0
- data/bin/rubocop +18 -0
- data/bin/yard +18 -0
- data/lib/circleci/coverage_reporter/artifact.rb +8 -4
- data/lib/circleci/coverage_reporter/build.rb +9 -0
- data/lib/circleci/coverage_reporter/client.rb +13 -2
- data/lib/circleci/coverage_reporter/configuration.rb +7 -31
- data/lib/circleci/coverage_reporter/report.rb +43 -29
- data/lib/circleci/coverage_reporter/reporters/base.rb +119 -0
- data/lib/circleci/coverage_reporter/reporters/flow.rb +32 -0
- data/lib/circleci/coverage_reporter/reporters/link.rb +51 -0
- data/lib/circleci/coverage_reporter/reporters/rubycritic.rb +33 -0
- data/lib/circleci/coverage_reporter/reporters/simplecov.rb +32 -0
- data/lib/circleci/coverage_reporter/result.rb +12 -0
- data/lib/circleci/coverage_reporter/runner.rb +3 -9
- data/lib/circleci/coverage_reporter/vcs/base.rb +23 -0
- data/lib/circleci/coverage_reporter/vcs/github.rb +39 -0
- data/lib/circleci/coverage_reporter/version.rb +1 -1
- data/lib/circleci/coverage_reporter.rb +4 -4
- metadata +13 -20
- data/lib/circleci/coverage_reporter/abstract_build_result.rb +0 -24
- data/lib/circleci/coverage_reporter/abstract_current_result.rb +0 -45
- data/lib/circleci/coverage_reporter/abstract_reporter.rb +0 -56
- data/lib/circleci/coverage_reporter/abstract_result.rb +0 -21
- data/lib/circleci/coverage_reporter/abstract_vcs_client.rb +0 -21
- data/lib/circleci/coverage_reporter/flow/build_result.rb +0 -23
- data/lib/circleci/coverage_reporter/flow/current_result.rb +0 -23
- data/lib/circleci/coverage_reporter/flow/reporter.rb +0 -37
- data/lib/circleci/coverage_reporter/github_client.rb +0 -35
- data/lib/circleci/coverage_reporter/link/current_result.rb +0 -28
- data/lib/circleci/coverage_reporter/link/reporter.rb +0 -35
- data/lib/circleci/coverage_reporter/reports_renderer.rb +0 -24
- data/lib/circleci/coverage_reporter/rubycritic/build_result.rb +0 -23
- data/lib/circleci/coverage_reporter/rubycritic/current_result.rb +0 -29
- data/lib/circleci/coverage_reporter/rubycritic/reporter.rb +0 -37
- data/lib/circleci/coverage_reporter/simplecov/build_result.rb +0 -23
- data/lib/circleci/coverage_reporter/simplecov/current_result.rb +0 -23
- data/lib/circleci/coverage_reporter/simplecov/reporter.rb +0 -37
@@ -0,0 +1,119 @@
|
|
1
|
+
require_relative '../report'
|
2
|
+
|
3
|
+
module CircleCI
|
4
|
+
module CoverageReporter
|
5
|
+
module Reporters
|
6
|
+
# @abstract Subclass and override {.default_dir}, {.default_html_file_name},
|
7
|
+
# {.default_json_file_name} and {#parse_json} to implement a custom Reporter class.
|
8
|
+
class Base
|
9
|
+
def self.default_dir
|
10
|
+
raise NotImplementedError
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.default_html_file_name
|
14
|
+
raise NotImplementedError
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.default_json_file_name
|
18
|
+
raise NotImplementedError
|
19
|
+
end
|
20
|
+
|
21
|
+
def initialize(options = {})
|
22
|
+
@options = options
|
23
|
+
end
|
24
|
+
|
25
|
+
# @return [Boolean]
|
26
|
+
def active?
|
27
|
+
File.directory?(File.join(configuration.artifacts_dir, dir))
|
28
|
+
end
|
29
|
+
|
30
|
+
# @param base_build [Build, nil]
|
31
|
+
# @param previous_build [Build, nil]
|
32
|
+
# @return [Report]
|
33
|
+
def report(base_build, previous_build)
|
34
|
+
Report.new(
|
35
|
+
self,
|
36
|
+
create_current_result,
|
37
|
+
base: base_build ? create_build_result(base_build) : nil,
|
38
|
+
previous: previous_build ? create_build_result(previous_build) : nil
|
39
|
+
)
|
40
|
+
end
|
41
|
+
|
42
|
+
# Name of reporter.
|
43
|
+
#
|
44
|
+
# @return [String]
|
45
|
+
def name
|
46
|
+
self.class.name.split('::').last
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
# @return [String]
|
52
|
+
def dir
|
53
|
+
@options[:dir] || self.class.default_dir
|
54
|
+
end
|
55
|
+
|
56
|
+
def html_file_name
|
57
|
+
@options[:html_file_name] || self.class.default_html_file_name
|
58
|
+
end
|
59
|
+
|
60
|
+
def json_file_name
|
61
|
+
@options[:json_file_name] || self.class.default_json_file_name
|
62
|
+
end
|
63
|
+
|
64
|
+
# @param build [Build, nil]
|
65
|
+
# @return [Result, nil]
|
66
|
+
def create_build_result(build)
|
67
|
+
Result.new(build_coverage(build), build_url(build))
|
68
|
+
end
|
69
|
+
|
70
|
+
# @return [AbstractResult]
|
71
|
+
def create_current_result
|
72
|
+
Result.new(current_coverage, current_url)
|
73
|
+
end
|
74
|
+
|
75
|
+
# @return [Float]
|
76
|
+
def current_coverage
|
77
|
+
parse_json(File.read(File.join(configuration.artifacts_dir, dir, json_file_name)))
|
78
|
+
end
|
79
|
+
|
80
|
+
# @return [String]
|
81
|
+
def current_url
|
82
|
+
[
|
83
|
+
'https://circle-artifacts.com/gh',
|
84
|
+
configuration.project,
|
85
|
+
configuration.current_build_number,
|
86
|
+
'artifacts',
|
87
|
+
"0#{configuration.artifacts_dir}",
|
88
|
+
dir,
|
89
|
+
html_file_name
|
90
|
+
].join('/')
|
91
|
+
end
|
92
|
+
|
93
|
+
# @param build [Build]
|
94
|
+
# @return [Float]
|
95
|
+
def build_coverage(build)
|
96
|
+
artifact = build.find_artifact(json_file_name) or return Float::NAN
|
97
|
+
parse_json(artifact.body)
|
98
|
+
end
|
99
|
+
|
100
|
+
# @param build [Build]
|
101
|
+
# @return [String]
|
102
|
+
def build_url(build)
|
103
|
+
artifact = build.find_artifact(html_file_name) or return '#'
|
104
|
+
artifact.url
|
105
|
+
end
|
106
|
+
|
107
|
+
def configuration
|
108
|
+
CoverageReporter.configuration
|
109
|
+
end
|
110
|
+
|
111
|
+
# @param json [String]
|
112
|
+
# @return [Float]
|
113
|
+
def parse_json(json) # rubocop:disable Lint/UnusedMethodArgument
|
114
|
+
raise NotImplementedError
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
require_relative '../result'
|
4
|
+
require_relative './base'
|
5
|
+
|
6
|
+
module CircleCI
|
7
|
+
module CoverageReporter
|
8
|
+
module Reporters
|
9
|
+
class Flow < Base
|
10
|
+
def self.default_dir
|
11
|
+
'flow-coverage'
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.default_html_file_name
|
15
|
+
'index.html'
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.default_json_file_name
|
19
|
+
'flow-coverage.json'
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
# @param json [String]
|
25
|
+
# @return [Float]
|
26
|
+
def parse_json(json)
|
27
|
+
JSON.parse(json)['percent'].to_f
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require_relative '../result'
|
2
|
+
|
3
|
+
module CircleCI
|
4
|
+
module CoverageReporter
|
5
|
+
module Reporters
|
6
|
+
class Link
|
7
|
+
LinkReport = Struct.new(:name, :url) do
|
8
|
+
def to_s
|
9
|
+
"[#{name}](#{url})"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize(options = {})
|
14
|
+
@options = options
|
15
|
+
end
|
16
|
+
|
17
|
+
# @note Implementation for {Base#active?}
|
18
|
+
def active?
|
19
|
+
File.file?(File.join(configuration.artifacts_dir, @options[:path]))
|
20
|
+
end
|
21
|
+
|
22
|
+
# @note Override {Base#name}
|
23
|
+
def name
|
24
|
+
@options[:name]
|
25
|
+
end
|
26
|
+
|
27
|
+
def report(_base_build, _previous_build)
|
28
|
+
LinkReport.new(@options[:name], url)
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
# @return [String]
|
34
|
+
def url
|
35
|
+
[
|
36
|
+
'https://circle-artifacts.com/gh',
|
37
|
+
configuration.project,
|
38
|
+
configuration.current_build_number,
|
39
|
+
'artifacts',
|
40
|
+
"0#{configuration.artifacts_dir}",
|
41
|
+
@options[:path]
|
42
|
+
].join('/')
|
43
|
+
end
|
44
|
+
|
45
|
+
def configuration
|
46
|
+
CoverageReporter.configuration
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
require_relative '../result'
|
4
|
+
require_relative './base'
|
5
|
+
|
6
|
+
module CircleCI
|
7
|
+
module CoverageReporter
|
8
|
+
module Reporters
|
9
|
+
class RubyCritic < Base
|
10
|
+
DEFAULT_DIR = 'rubycritic'.freeze
|
11
|
+
def self.default_dir
|
12
|
+
'rubycritic'
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.default_html_file_name
|
16
|
+
'overview.html'
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.default_json_file_name
|
20
|
+
'report.json'
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
# @param json [String]
|
26
|
+
# @return [Float]
|
27
|
+
def parse_json(json)
|
28
|
+
JSON.parse(json)['score'].to_f
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
require_relative '../result'
|
4
|
+
require_relative './base'
|
5
|
+
|
6
|
+
module CircleCI
|
7
|
+
module CoverageReporter
|
8
|
+
module Reporters
|
9
|
+
class SimpleCov < Base
|
10
|
+
def self.default_dir
|
11
|
+
'coverage'
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.default_html_file_name
|
15
|
+
'index.html'
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.default_json_file_name
|
19
|
+
'.last_run.json'
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
# @param json [String]
|
25
|
+
# @return [Float]
|
26
|
+
def parse_json(json)
|
27
|
+
JSON.parse(json)['result']['covered_percent'].to_f
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module CircleCI
|
2
|
+
module CoverageReporter
|
3
|
+
# @attr coverage [Float]
|
4
|
+
# @attr url [String] URL for coverage index.html
|
5
|
+
Result = Struct.new(:coverage, :url) do
|
6
|
+
# @return [String]
|
7
|
+
def pretty_coverage
|
8
|
+
"#{coverage.round(2)}%"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -1,5 +1,4 @@
|
|
1
|
-
require_relative '
|
2
|
-
require_relative 'reports_renderer'
|
1
|
+
require_relative 'vcs/github'
|
3
2
|
|
4
3
|
module CircleCI
|
5
4
|
module CoverageReporter
|
@@ -7,7 +6,7 @@ module CircleCI
|
|
7
6
|
# @return [void]
|
8
7
|
def run
|
9
8
|
reports = reporters.map { |reporter| reporter.report(base_build, previous_build) }
|
10
|
-
vcs_client.create_comment(
|
9
|
+
vcs_client.create_comment(reports.map(&:to_s).join("\n"))
|
11
10
|
end
|
12
11
|
|
13
12
|
# @return [void]
|
@@ -23,16 +22,11 @@ module CircleCI
|
|
23
22
|
|
24
23
|
private
|
25
24
|
|
26
|
-
# @return [ReportsRenderer]
|
27
|
-
def reports_renderer
|
28
|
-
ReportsRenderer.new
|
29
|
-
end
|
30
|
-
|
31
25
|
# @return [AbstractVCSClient]
|
32
26
|
def vcs_client
|
33
27
|
case configuration.vcs_type
|
34
28
|
when 'github'
|
35
|
-
|
29
|
+
VCS::GitHub.new(configuration.vcs_token)
|
36
30
|
else
|
37
31
|
raise NotImplementedError
|
38
32
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module CircleCI
|
2
|
+
module CoverageReporter
|
3
|
+
module VCS
|
4
|
+
# @abstract Subclass and override {#create_comment} to implement a custom VCS client class.
|
5
|
+
class Base
|
6
|
+
# @param token [String]
|
7
|
+
def initialize(token)
|
8
|
+
@token = token
|
9
|
+
end
|
10
|
+
|
11
|
+
# @param body [String]
|
12
|
+
# @return [void]
|
13
|
+
def create_comment(body) # rubocop:disable Lint/UnusedMethodArgument
|
14
|
+
raise NotImplementedError
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
attr_reader :token
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
|
3
|
+
require_relative '../errors'
|
4
|
+
require_relative 'base'
|
5
|
+
|
6
|
+
module CircleCI
|
7
|
+
module CoverageReporter
|
8
|
+
module VCS
|
9
|
+
class GitHub < Base
|
10
|
+
# @note Implement {Base#create_comment}
|
11
|
+
# @param body [String]
|
12
|
+
# @return [void]
|
13
|
+
# @raise [RequestError]
|
14
|
+
def create_comment(body)
|
15
|
+
resp = request(body)
|
16
|
+
raise RequestError.new(JSON.parse(resp.body)['message'], resp) unless resp.success?
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
# @param body [String]
|
22
|
+
# @return [Faraday::Response]
|
23
|
+
def request(body)
|
24
|
+
Faraday.new(url: 'https://api.github.com').post do |req|
|
25
|
+
req.url ['/repos', configuration.project, 'commits', configuration.current_revision, 'comments'].join('/')
|
26
|
+
req.headers['Authorization'] = "token #{token}"
|
27
|
+
req.headers['Content-Type'] = 'application/json'
|
28
|
+
req.body = JSON.generate(body: body)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# @return [Configuration]
|
33
|
+
def configuration
|
34
|
+
CoverageReporter.configuration
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -3,10 +3,10 @@ require_relative 'coverage_reporter/configuration'
|
|
3
3
|
require_relative 'coverage_reporter/errors'
|
4
4
|
require_relative 'coverage_reporter/runner'
|
5
5
|
|
6
|
-
require_relative 'coverage_reporter/flow
|
7
|
-
require_relative 'coverage_reporter/link
|
8
|
-
require_relative 'coverage_reporter/rubycritic
|
9
|
-
require_relative 'coverage_reporter/simplecov
|
6
|
+
require_relative 'coverage_reporter/reporters/flow'
|
7
|
+
require_relative 'coverage_reporter/reporters/link'
|
8
|
+
require_relative 'coverage_reporter/reporters/rubycritic'
|
9
|
+
require_relative 'coverage_reporter/reporters/simplecov'
|
10
10
|
|
11
11
|
module CircleCI
|
12
12
|
module CoverageReporter
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: circleci-coverage_reporter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yuku Takahashi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-05-
|
11
|
+
date: 2017-05-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -55,37 +55,30 @@ files:
|
|
55
55
|
- LICENSE.txt
|
56
56
|
- README.md
|
57
57
|
- Rakefile
|
58
|
+
- bin/rspec
|
59
|
+
- bin/rubocop
|
58
60
|
- bin/setup
|
61
|
+
- bin/yard
|
59
62
|
- circle.yml
|
60
63
|
- circleci-coverage_reporter.gemspec
|
61
64
|
- lib/circleci/coverage_reporter.rb
|
62
|
-
- lib/circleci/coverage_reporter/abstract_build_result.rb
|
63
|
-
- lib/circleci/coverage_reporter/abstract_current_result.rb
|
64
|
-
- lib/circleci/coverage_reporter/abstract_reporter.rb
|
65
|
-
- lib/circleci/coverage_reporter/abstract_result.rb
|
66
|
-
- lib/circleci/coverage_reporter/abstract_vcs_client.rb
|
67
65
|
- lib/circleci/coverage_reporter/artifact.rb
|
68
66
|
- lib/circleci/coverage_reporter/build.rb
|
69
67
|
- lib/circleci/coverage_reporter/client.rb
|
70
68
|
- lib/circleci/coverage_reporter/configuration.rb
|
71
69
|
- lib/circleci/coverage_reporter/errors.rb
|
72
|
-
- lib/circleci/coverage_reporter/flow/build_result.rb
|
73
|
-
- lib/circleci/coverage_reporter/flow/current_result.rb
|
74
|
-
- lib/circleci/coverage_reporter/flow/reporter.rb
|
75
|
-
- lib/circleci/coverage_reporter/github_client.rb
|
76
|
-
- lib/circleci/coverage_reporter/link/current_result.rb
|
77
|
-
- lib/circleci/coverage_reporter/link/reporter.rb
|
78
70
|
- lib/circleci/coverage_reporter/rake_task.rb
|
79
71
|
- lib/circleci/coverage_reporter/report.rb
|
80
|
-
- lib/circleci/coverage_reporter/
|
81
|
-
- lib/circleci/coverage_reporter/
|
82
|
-
- lib/circleci/coverage_reporter/
|
83
|
-
- lib/circleci/coverage_reporter/rubycritic
|
72
|
+
- lib/circleci/coverage_reporter/reporters/base.rb
|
73
|
+
- lib/circleci/coverage_reporter/reporters/flow.rb
|
74
|
+
- lib/circleci/coverage_reporter/reporters/link.rb
|
75
|
+
- lib/circleci/coverage_reporter/reporters/rubycritic.rb
|
76
|
+
- lib/circleci/coverage_reporter/reporters/simplecov.rb
|
77
|
+
- lib/circleci/coverage_reporter/result.rb
|
84
78
|
- lib/circleci/coverage_reporter/runner.rb
|
85
79
|
- lib/circleci/coverage_reporter/sandbox.rb
|
86
|
-
- lib/circleci/coverage_reporter/
|
87
|
-
- lib/circleci/coverage_reporter/
|
88
|
-
- lib/circleci/coverage_reporter/simplecov/reporter.rb
|
80
|
+
- lib/circleci/coverage_reporter/vcs/base.rb
|
81
|
+
- lib/circleci/coverage_reporter/vcs/github.rb
|
89
82
|
- lib/circleci/coverage_reporter/version.rb
|
90
83
|
homepage: https://github.com/increments/circleci-coverage_reporter
|
91
84
|
licenses:
|