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.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +4 -0
  3. data/CHANGELOG.md +9 -1
  4. data/Gemfile +1 -0
  5. data/README.md +10 -19
  6. data/Rakefile +1 -1
  7. data/bin/rspec +18 -0
  8. data/bin/rubocop +18 -0
  9. data/bin/yard +18 -0
  10. data/lib/circleci/coverage_reporter/artifact.rb +8 -4
  11. data/lib/circleci/coverage_reporter/build.rb +9 -0
  12. data/lib/circleci/coverage_reporter/client.rb +13 -2
  13. data/lib/circleci/coverage_reporter/configuration.rb +7 -31
  14. data/lib/circleci/coverage_reporter/report.rb +43 -29
  15. data/lib/circleci/coverage_reporter/reporters/base.rb +119 -0
  16. data/lib/circleci/coverage_reporter/reporters/flow.rb +32 -0
  17. data/lib/circleci/coverage_reporter/reporters/link.rb +51 -0
  18. data/lib/circleci/coverage_reporter/reporters/rubycritic.rb +33 -0
  19. data/lib/circleci/coverage_reporter/reporters/simplecov.rb +32 -0
  20. data/lib/circleci/coverage_reporter/result.rb +12 -0
  21. data/lib/circleci/coverage_reporter/runner.rb +3 -9
  22. data/lib/circleci/coverage_reporter/vcs/base.rb +23 -0
  23. data/lib/circleci/coverage_reporter/vcs/github.rb +39 -0
  24. data/lib/circleci/coverage_reporter/version.rb +1 -1
  25. data/lib/circleci/coverage_reporter.rb +4 -4
  26. metadata +13 -20
  27. data/lib/circleci/coverage_reporter/abstract_build_result.rb +0 -24
  28. data/lib/circleci/coverage_reporter/abstract_current_result.rb +0 -45
  29. data/lib/circleci/coverage_reporter/abstract_reporter.rb +0 -56
  30. data/lib/circleci/coverage_reporter/abstract_result.rb +0 -21
  31. data/lib/circleci/coverage_reporter/abstract_vcs_client.rb +0 -21
  32. data/lib/circleci/coverage_reporter/flow/build_result.rb +0 -23
  33. data/lib/circleci/coverage_reporter/flow/current_result.rb +0 -23
  34. data/lib/circleci/coverage_reporter/flow/reporter.rb +0 -37
  35. data/lib/circleci/coverage_reporter/github_client.rb +0 -35
  36. data/lib/circleci/coverage_reporter/link/current_result.rb +0 -28
  37. data/lib/circleci/coverage_reporter/link/reporter.rb +0 -35
  38. data/lib/circleci/coverage_reporter/reports_renderer.rb +0 -24
  39. data/lib/circleci/coverage_reporter/rubycritic/build_result.rb +0 -23
  40. data/lib/circleci/coverage_reporter/rubycritic/current_result.rb +0 -29
  41. data/lib/circleci/coverage_reporter/rubycritic/reporter.rb +0 -37
  42. data/lib/circleci/coverage_reporter/simplecov/build_result.rb +0 -23
  43. data/lib/circleci/coverage_reporter/simplecov/current_result.rb +0 -23
  44. data/lib/circleci/coverage_reporter/simplecov/reporter.rb +0 -37
@@ -1,24 +0,0 @@
1
- require_relative 'abstract_result'
2
-
3
- module CircleCI
4
- module CoverageReporter
5
- class AbstractBuildResult < AbstractResult
6
- # @param path [String]
7
- # @param build [Build]
8
- def initialize(path, build)
9
- @path = path
10
- @build = build
11
- end
12
-
13
- private
14
-
15
- attr_reader :build, :path
16
-
17
- # @param end_with [String]
18
- # @return [Artifact]
19
- def find_artifact(end_with)
20
- build.artifacts.find { |artifact| artifact.end_with?("#{path}/#{end_with}") }
21
- end
22
- end
23
- end
24
- end
@@ -1,45 +0,0 @@
1
- require_relative 'abstract_result'
2
-
3
- module CircleCI
4
- module CoverageReporter
5
- class AbstractCurrentResult < AbstractResult
6
- # @param path [String] path to coverage directory
7
- def initialize(path)
8
- @path = path
9
- end
10
-
11
- # @note Implement {AbstractResult#url}
12
- # @return [String]
13
- def url
14
- [
15
- 'https://circle-artifacts.com/gh',
16
- configuration.project,
17
- configuration.current_build_number,
18
- 'artifacts',
19
- "0#{configuration.artifacts_dir}",
20
- path,
21
- html_file_name
22
- ].compact.join('/')
23
- end
24
-
25
- private
26
-
27
- attr_reader :path
28
-
29
- # @return [String]
30
- def html_file_name
31
- raise NotImplementedError
32
- end
33
-
34
- # @return
35
- def join(name)
36
- File.join(configuration.artifacts_dir, path, name)
37
- end
38
-
39
- # @return [Configuration]
40
- def configuration
41
- CoverageReporter.configuration
42
- end
43
- end
44
- end
45
- end
@@ -1,56 +0,0 @@
1
- require_relative 'report'
2
-
3
- module CircleCI
4
- module CoverageReporter
5
- # @abstract Subclass and override {#name}, {#create_build_result} and {#create_current_result}
6
- # to implement a custom Reporter class.
7
- class AbstractReporter
8
- # @param path [String, nil] relative path from artifacts dir to coverage directory
9
- def initialize(path = self.class::DEFAULT_PATH)
10
- @path = path
11
- end
12
-
13
- # @return [Boolean] whether it is active
14
- def active?
15
- File.directory?(File.join(configuration.artifacts_dir, path || ''))
16
- end
17
-
18
- # @param base_build [Build, nil]
19
- # @param previous_build [Build, nil]
20
- # @return [Report]
21
- def report(base_build, previous_build)
22
- Report.new(
23
- self,
24
- create_current_result,
25
- base: create_build_result(base_build),
26
- previous: create_build_result(previous_build)
27
- )
28
- end
29
-
30
- # @return [String]
31
- def name
32
- raise NotImplementedError
33
- end
34
-
35
- private
36
-
37
- attr_reader :path
38
-
39
- # @param build [Build, nil]
40
- # @return [AbstractResult, nil]
41
- def create_build_result(build) # rubocop:disable Lint/UnusedMethodArgument
42
- raise NotImplementedError
43
- end
44
-
45
- # @return [AbstractResult]
46
- def create_current_result
47
- raise NotImplementedError
48
- end
49
-
50
- # @return [Configuration]
51
- def configuration
52
- CoverageReporter.configuration
53
- end
54
- end
55
- end
56
- end
@@ -1,21 +0,0 @@
1
- module CircleCI
2
- module CoverageReporter
3
- # @abstract Subclass and override {#coverage} and {#url} to implement a custom Result class.
4
- class AbstractResult
5
- # @return [Float]
6
- def coverage
7
- raise NotImplementedError
8
- end
9
-
10
- # @return [String] URL for coverage index.html
11
- def url
12
- raise NotImplementedError
13
- end
14
-
15
- # @return [String]
16
- def pretty_coverage
17
- "#{coverage.round(2)}%"
18
- end
19
- end
20
- end
21
- end
@@ -1,21 +0,0 @@
1
- module CircleCI
2
- module CoverageReporter
3
- # @abstract Subclass and override {#create_comment} to implement a custom VCS client class.
4
- class AbstractVCSClient
5
- # @param token [String]
6
- def initialize(token)
7
- @token = token
8
- end
9
-
10
- # @param body [String]
11
- # @return [void]
12
- def create_comment(body) # rubocop:disable Lint/UnusedMethodArgument
13
- raise NotImplementedError
14
- end
15
-
16
- private
17
-
18
- attr_reader :token
19
- end
20
- end
21
- end
@@ -1,23 +0,0 @@
1
- require_relative '../abstract_build_result'
2
-
3
- module CircleCI
4
- module CoverageReporter
5
- module Flow
6
- class BuildResult < AbstractBuildResult
7
- # @note Implement {AbstractResult#coverage}
8
- # @return [Float]
9
- def coverage
10
- flow_coverage_json = find_artifact('flow-coverage.json') or return Float::NAN
11
- JSON.parse(flow_coverage_json.body)['percent'].to_f
12
- end
13
-
14
- # @note Implement {AbstractResult#url}
15
- # @return [String]
16
- def url
17
- index_html = find_artifact('index.html') or return '#'
18
- index_html.url
19
- end
20
- end
21
- end
22
- end
23
- end
@@ -1,23 +0,0 @@
1
- require_relative '../abstract_current_result'
2
-
3
- module CircleCI
4
- module CoverageReporter
5
- module Flow
6
- class CurrentResult < AbstractCurrentResult
7
- # @note Implement {AbstractResult#coverage}
8
- # @return [Float]
9
- def coverage
10
- JSON.parse(File.read(join('flow-coverage.json')))['percent'].to_f
11
- end
12
-
13
- private
14
-
15
- # @note Implementation for {AbstractCurrentResult#html_file_name}
16
- # @return [String]
17
- def html_file_name
18
- 'index.html'
19
- end
20
- end
21
- end
22
- end
23
- end
@@ -1,37 +0,0 @@
1
- require 'json'
2
-
3
- require_relative '../abstract_reporter'
4
- require_relative 'build_result'
5
- require_relative 'current_result'
6
-
7
- module CircleCI
8
- module CoverageReporter
9
- module Flow
10
- class Reporter < AbstractReporter
11
- DEFAULT_PATH = 'flow-coverage'.freeze
12
-
13
- # @note Implement {AbstractReporter#name}
14
- # @return [String]
15
- def name
16
- 'Flow'
17
- end
18
-
19
- private
20
-
21
- # @note Implement {AbstractReporter#create_build_result}
22
- # @param build [Build, nil]
23
- # @return [BuildResult, nil]
24
- def create_build_result(build)
25
- return unless build
26
- BuildResult.new(path, build)
27
- end
28
-
29
- # @note Implement {AbstractReporter#create_current_result}
30
- # @return [CurrentResult]
31
- def create_current_result
32
- CurrentResult.new(path)
33
- end
34
- end
35
- end
36
- end
37
- end
@@ -1,35 +0,0 @@
1
- require_relative 'abstract_vcs_client'
2
- require_relative 'errors'
3
-
4
- module CircleCI
5
- module CoverageReporter
6
- class GitHubClient < AbstractVCSClient
7
- # @note Implement {AbstractVCSClient#create_comment}
8
- # @param body [String]
9
- # @return [void]
10
- # @raise [RequestError]
11
- def create_comment(body)
12
- resp = request(body)
13
- raise RequestError.new(JSON.parse(resp.body)['message'], resp) unless resp.success?
14
- end
15
-
16
- private
17
-
18
- # @param body [String]
19
- # @return [Faraday::Response]
20
- def request(body)
21
- Faraday.new(url: 'https://api.github.com').post do |req|
22
- req.url ['/repos', configuration.project, 'commits', configuration.current_revision, 'comments'].join('/')
23
- req.headers['Authorization'] = "token #{token}"
24
- req.headers['Content-Type'] = 'application/json'
25
- req.body = JSON.generate(body: body)
26
- end
27
- end
28
-
29
- # @return [Configuration]
30
- def configuration
31
- CoverageReporter.configuration
32
- end
33
- end
34
- end
35
- end
@@ -1,28 +0,0 @@
1
- module CircleCI
2
- module CoverageReporter
3
- module Link
4
- class CurrentResult < AbstractCurrentResult
5
- # @note Override
6
- def initialize(path, html_file_name)
7
- @html_file_name = html_file_name
8
- super(path)
9
- end
10
-
11
- # @note Implement {AbstractResult#coverage}
12
- # @return [Float]
13
- def coverage
14
- Float::NAN
15
- end
16
-
17
- # @note Override {AbstractResult#pretty_coverage}
18
- def pretty_coverage
19
- ''
20
- end
21
-
22
- private
23
-
24
- attr_reader :html_file_name
25
- end
26
- end
27
- end
28
- end
@@ -1,35 +0,0 @@
1
- require_relative 'current_result'
2
-
3
- module CircleCI
4
- module CoverageReporter
5
- module Link
6
- class Reporter < AbstractReporter
7
- attr_reader :name
8
-
9
- # @param path [String, nil] relative path from artifacts dir to coverage directory
10
- # @param file_name [String] file name
11
- # @param name [String] reporter name
12
- def initialize(path, file_name, name: nil)
13
- @path = path
14
- @file_name = file_name
15
- @name = name || file_name
16
- end
17
-
18
- private
19
-
20
- # @note Implement {AbstractReporter#create_build_result}
21
- # @param _build [Build, nil]
22
- # @return [nil]
23
- def create_build_result(_build)
24
- nil
25
- end
26
-
27
- # @note Implement {AbstractReporter#create_current_result}
28
- # @return [CurrentResult]
29
- def create_current_result
30
- CurrentResult.new(path, @file_name)
31
- end
32
- end
33
- end
34
- end
35
- end
@@ -1,24 +0,0 @@
1
- require 'erb'
2
-
3
- module CircleCI
4
- module CoverageReporter
5
- class ReportsRenderer
6
- # @param reports [Array<Report>]
7
- # @return [String]
8
- def render(reports)
9
- ERB.new(
10
- CoverageReporter.configuration.template,
11
- nil,
12
- CoverageReporter.configuration.template_trim_mode
13
- ).result(binding)
14
- end
15
-
16
- private
17
-
18
- # @return [String]
19
- def vcs_type
20
- CoverageReporter.configuration.vcs_type
21
- end
22
- end
23
- end
24
- end
@@ -1,23 +0,0 @@
1
- require_relative '../abstract_build_result'
2
-
3
- module CircleCI
4
- module CoverageReporter
5
- module RubyCritic
6
- class BuildResult < AbstractBuildResult
7
- # @note Implement {AbstractResult#coverage}
8
- # @return [Float]
9
- def coverage
10
- last_run_json = find_artifact('report.json') or return Float::NAN
11
- JSON.parse(last_run_json.body)['score'].to_f
12
- end
13
-
14
- # @note Implement {AbstractResult#url}
15
- # @return [String]
16
- def url
17
- index_html = find_artifact('overview.html') or return '#'
18
- index_html.url
19
- end
20
- end
21
- end
22
- end
23
- end
@@ -1,29 +0,0 @@
1
- require_relative '../abstract_current_result'
2
-
3
- module CircleCI
4
- module CoverageReporter
5
- module RubyCritic
6
- class CurrentResult < AbstractCurrentResult
7
- # @note Implement {AbstractResult#coverage}
8
- # @return [Float]
9
- def coverage
10
- JSON.parse(File.read(join('report.json')))['score'].to_f
11
- end
12
-
13
- # @note Override {AbstractResult#pretty_coverage}
14
- # @return [String]
15
- def pretty_coverage
16
- "#{coverage.round(2)}pt"
17
- end
18
-
19
- private
20
-
21
- # @note Implementation for {AbstractCurrentResult#html_file_name}
22
- # @return [String]
23
- def html_file_name
24
- 'overview.html'
25
- end
26
- end
27
- end
28
- end
29
- end