circleci-coverage_reporter 0.1.3 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7043f473068bec23109876b4e38bf8aca96410f0
4
- data.tar.gz: bfeb330edb4de8f150cb1fd4bd0183d33fee6720
3
+ metadata.gz: 5184426bc67f4c8e7217a623eb7674643204dbc0
4
+ data.tar.gz: b060f3721644ebf5d7a0704efbf86a1683923a90
5
5
  SHA512:
6
- metadata.gz: 32ade229dc33219e38c324737c98d8600b70c2bb4a792a486274cd16ccd1e7e0ce1b0ffc886a3251aa4b4a6ac440bed6dcdbad5b8e9d65dd3478e6413550a0f0
7
- data.tar.gz: ca44ef9e3ca8faebec5b3510a48bb9142ebac517b66727373445d71e2f96c0d57fac9c4e112827827408e3ffd4d05ec0ba678734b6fbd1fda8546d2332ff04c3
6
+ metadata.gz: 536bc1d1c085a916efffd13a2c95a729a41c4072b5f8cfa80aa3e33909745bf3de4af84b258ce36a0b0e1210a0d0249e496ef8f2f029ff4f2635ad7d9ce63b48
7
+ data.tar.gz: 5452ccd5386b7a907a0c1ae2c22a31678c250e6a829ee8b36b14fc6eacdf0abb829fb69ab7cc0fc198b032d7ce443a51d5cfa35f7317782347b72d497c8f9fa9
data/.yardopts ADDED
@@ -0,0 +1,4 @@
1
+ --markup markdown
2
+ -
3
+ CHANGELOG.md
4
+ LICENSE.txt
data/CHANGELOG.md CHANGED
@@ -6,6 +6,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.2.0] - 2017-03-14
10
+ ### Added
11
+ - Support [Flow](flowtype.org) coverage reported by [flow-coverage-report](https://github.com/rpl/flow-coverage-report)
12
+
13
+ ### Fixed
14
+ - Disable inactive reporters
15
+ - Fix uninitialized constant `Float::NaN`
16
+
9
17
  ## [0.1.3] - 2017-03-12
10
18
  ### Fixed
11
19
  - Raise `RequestError` if some API reqeust fails
@@ -26,7 +34,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
26
34
 
27
35
  - Initial release
28
36
 
29
- [Unreleased]: https://github.com/increments/circleci-coverage_reporter/compare/v0.1.3...HEAD
37
+ [Unreleased]: https://github.com/increments/circleci-coverage_reporter/compare/v0.2.0...HEAD
38
+ [0.2.0]: https://github.com/increments/circleci-coverage_reporter/compare/v0.1.3...v0.2.0
30
39
  [0.1.3]: https://github.com/increments/circleci-coverage_reporter/compare/v0.1.2...v0.1.3
31
40
  [0.1.2]: https://github.com/increments/circleci-coverage_reporter/compare/v0.1.1...v0.1.2
32
41
  [0.1.1]: https://github.com/increments/circleci-coverage_reporter/compare/v0.1.0...v0.1.1
data/README.md CHANGED
@@ -34,7 +34,7 @@
34
34
  ```yaml
35
35
  test:
36
36
  post:
37
- - bundle exec circleci:report_coverage
37
+ - bundle exec rake circleci:report_coverage
38
38
  ```
39
39
 
40
40
  ## Run manually
@@ -54,7 +54,7 @@ CircleCI::CoverageReporter.run
54
54
  ### SimpleCov
55
55
 
56
56
  `CircleCI::CoverageReporter::SimpleCov::Reporter` handles coverage files generated by
57
- [SimpleCov](https://github.com/colszowka/simplecov). It is used by default.
57
+ [SimpleCov](https://github.com/colszowka/simplecov).
58
58
 
59
59
  It expects that coverage files are located in `$CIRCLE_ARTIFACTS/coverage` directory:
60
60
 
@@ -66,11 +66,31 @@ SimpleCov.coverage_dir(File.join(ENV['CIRCLE_ARTIFACTS'], 'coverage')) if ENV['C
66
66
  SimpleCov.start
67
67
  ```
68
68
 
69
- If you put files in directory, say `$CIRCLE_ARTIFACTS/foo/bar`, you have to set reporter as follows:
69
+ If you put files in another directory, say `$CIRCLE_ARTIFACTS/foo/bar`, you have to set reporter as follows:
70
70
 
71
71
  ```ruby
72
72
  CircleCI::CoverageReporter.configure do |config|
73
- config.reporters = [CircleCI::CoverageReporter::SimpleCov::Reporter.new('foo/bar')]
73
+ config.reporters << CircleCI::CoverageReporter::SimpleCov::Reporter.new('foo/bar')
74
+ end
75
+ ```
76
+
77
+ ### Flow
78
+
79
+ `CircleCI::CoverageReporter::Flow::Reporter` handles coverage files generated by
80
+ [flow-coverage-report](https://github.com/rpl/flow-coverage-report)
81
+
82
+ It expects that there is `$CIRCLE_ARTIFACTS/flow-coverage/flow-coverage.json`:
83
+
84
+ ```bash
85
+ $(npm bin)/flow-coverage-report -t json -o $CIRCLE_ARTIFACTS/flow-coverage
86
+ ```
87
+
88
+ If you put the file in another path, say `$CIRCLE_ARTIFACTS/foo/bar/flow-coverage.json`,
89
+ you have to set reporter as follows:
90
+
91
+ ```ruby
92
+ CircleCI::CoverageReporter.configure do |config|
93
+ config.reporters << CircleCI::CoverageReporter::Flow::Reporter.new('foo/bar')
74
94
  end
75
95
  ```
76
96
 
@@ -1,5 +1,6 @@
1
- require_relative 'coverage_reporter/configuration'
2
1
  require_relative 'coverage_reporter/client'
2
+ require_relative 'coverage_reporter/configuration'
3
+ require_relative 'coverage_reporter/errors'
3
4
  require_relative 'coverage_reporter/runner'
4
5
 
5
6
  module CircleCI
@@ -23,27 +24,10 @@ module CircleCI
23
24
 
24
25
  # @return [void]
25
26
  def self.run
26
- dump
27
- Runner.new.run
28
- end
29
-
30
- # @return [void]
31
- def self.dump # rubocop:disable AbcSize
32
- puts <<-EOF
33
- Configuration | Value
34
- ----------------------|----------------------------------------------------------------------------
35
- artifacts_dir | #{configuration.artifacts_dir.inspect}
36
- base_revision | #{configuration.base_revision.inspect}
37
- circleci_token | #{configuration.circleci_token[-4..-1].rjust(40, '*').inspect}
38
- current_build_number | #{configuration.current_build_number.inspect}
39
- current_revision | #{configuration.current_revision.inspect}
40
- previous_build_number | #{configuration.previous_build_number.inspect}
41
- reporters | #{configuration.reporters.inspect}
42
- repository_name | #{configuration.repository_name.inspect}
43
- user_name | #{configuration.user_name.inspect}
44
- vcs_token | #{configuration.vcs_token[-4..-1].rjust(40, '*').inspect}
45
- vcs_type | #{configuration.vcs_type.inspect}
46
- EOF
27
+ configuration.reporters.select!(&:active?)
28
+ configuration.dump
29
+ raise NoActiveReporter if configuration.reporters.empty?
30
+ Runner.new.tap(&:dump).run
47
31
  end
48
32
  end
49
33
  end
@@ -5,6 +5,16 @@ module CircleCI
5
5
  # @abstract Subclass and override {#name}, {#create_build_result} and {#create_current_result}
6
6
  # to implement a custom Reporter class.
7
7
  class AbstractReporter
8
+ # @param path [String] 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(CoverageReporter.configuration.artifacts_dir, path))
16
+ end
17
+
8
18
  # @param base_build [Build, nil]
9
19
  # @param previous_build [Build, nil]
10
20
  # @return [Report]
@@ -24,6 +34,8 @@ module CircleCI
24
34
 
25
35
  private
26
36
 
37
+ attr_reader :path
38
+
27
39
  # @param build [Build, nil]
28
40
  # @return [AbstractResult, nil]
29
41
  def create_build_result(build) # rubocop:disable Lint/UnusedMethodArgument
@@ -1,9 +1,13 @@
1
+ require_relative 'flow/reporter'
1
2
  require_relative 'simplecov/reporter'
2
3
 
3
4
  module CircleCI
4
5
  module CoverageReporter
5
6
  class Configuration
6
- DEFAULT_REPORTERS = [SimpleCov::Reporter.new].freeze
7
+ DEFAULT_REPORTERS = [
8
+ SimpleCov::Reporter.new,
9
+ Flow::Reporter.new
10
+ ].freeze
7
11
  DEFAULT_VCS_TYPE = 'github'.freeze
8
12
 
9
13
  attr_accessor :circleci_token, :vcs_token
@@ -17,7 +21,7 @@ module CircleCI
17
21
 
18
22
  # @return [Array<AbstractReporter>]
19
23
  def reporters
20
- @reporters ||= DEFAULT_REPORTERS
24
+ @reporters ||= DEFAULT_REPORTERS.dup
21
25
  end
22
26
 
23
27
  # @return [String]
@@ -59,6 +63,25 @@ module CircleCI
59
63
  def user_name
60
64
  @user_name ||= ENV['CIRCLE_PROJECT_USERNAME']
61
65
  end
66
+
67
+ # @return [void]
68
+ def dump # rubocop:disable AbcSize
69
+ puts <<-EOF
70
+ Configuration | Value
71
+ ----------------------|----------------------------------------------------------------------------
72
+ artifacts_dir | #{artifacts_dir.inspect}
73
+ base_revision | #{base_revision.inspect}
74
+ circleci_token | #{circleci_token[-4..-1].rjust(40, '*').inspect}
75
+ current_build_number | #{current_build_number.inspect}
76
+ current_revision | #{current_revision.inspect}
77
+ previous_build_number | #{previous_build_number.inspect}
78
+ reporters | #{reporters.inspect}
79
+ repository_name | #{repository_name.inspect}
80
+ user_name | #{user_name.inspect}
81
+ vcs_token | #{vcs_token[-4..-1].rjust(40, '*').inspect}
82
+ vcs_type | #{vcs_type.inspect}
83
+ EOF
84
+ end
62
85
  end
63
86
  end
64
87
  end
@@ -13,5 +13,7 @@ module CircleCI
13
13
  super(message)
14
14
  end
15
15
  end
16
+
17
+ class NoActiveReporter < Error; end
16
18
  end
17
19
  end
@@ -0,0 +1,40 @@
1
+ require_relative '../abstract_result'
2
+
3
+ module CircleCI
4
+ module CoverageReporter
5
+ module Flow
6
+ class BuildResult < AbstractResult
7
+ # @param path [String]
8
+ # @param build [Build]
9
+ def initialize(path, build)
10
+ @path = path
11
+ @build = build
12
+ end
13
+
14
+ # @note Implement {AbstractResult#coverage}
15
+ # @return [Float]
16
+ def coverage
17
+ flow_coverage_json = find_artifact('flow-coverage.json') or return Float::NAN
18
+ JSON.parse(flow_coverage_json.body)['percent']
19
+ end
20
+
21
+ # @note Implement {AbstractResult#url}
22
+ # @return [String]
23
+ def url
24
+ index_html = find_artifact('index.html') or return '#'
25
+ index_html.url
26
+ end
27
+
28
+ private
29
+
30
+ attr_reader :build, :path
31
+
32
+ # @param end_with [String]
33
+ # @return [Artifact]
34
+ def find_artifact(end_with)
35
+ build.artifacts.find { |a| a.end_with?("#{path}/#{end_with}") }
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,48 @@
1
+ require_relative '../abstract_result'
2
+
3
+ module CircleCI
4
+ module CoverageReporter
5
+ module Flow
6
+ class CurrentResult < AbstractResult
7
+ # @param path [String] path to coverage directory
8
+ def initialize(path)
9
+ @path = path
10
+ end
11
+
12
+ # @note Implement {AbstractResult#coverage}
13
+ # @return [Float]
14
+ def coverage
15
+ JSON.parse(File.read(join('flow-coverage.json')))['percent']
16
+ end
17
+
18
+ # @note Implement {AbstractResult#url}
19
+ # @return [String]
20
+ def url
21
+ [
22
+ 'https://circle-artifacts.com/gh',
23
+ configuration.project,
24
+ configuration.current_build_number,
25
+ 'artifacts',
26
+ "0#{configuration.artifacts_dir}",
27
+ path,
28
+ 'index.html'
29
+ ].join('/')
30
+ end
31
+
32
+ private
33
+
34
+ attr_reader :path
35
+
36
+ # @return
37
+ def join(name)
38
+ File.join(configuration.artifacts_dir, path, name)
39
+ end
40
+
41
+ # @return [Client]
42
+ def configuration
43
+ CoverageReporter.client.configuration
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,37 @@
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
@@ -5,13 +5,10 @@ module CircleCI
5
5
  class Runner
6
6
  # @return [void]
7
7
  def run
8
- dump
9
8
  reports = reporters.map { |reporter| reporter.report(base_build, previous_build) }
10
9
  vcs_client.create_comment(reports)
11
10
  end
12
11
 
13
- private
14
-
15
12
  # @return [void]
16
13
  def dump
17
14
  puts <<-EOF
@@ -23,6 +20,8 @@ previous_build | #{previous_build.inspect}
23
20
  EOF
24
21
  end
25
22
 
23
+ private
24
+
26
25
  # @return [AbstractVCSClient]
27
26
  def vcs_client
28
27
  case client.configuration.vcs_type
@@ -4,15 +4,17 @@ module CircleCI
4
4
  module CoverageReporter
5
5
  module SimpleCov
6
6
  class BuildResult < AbstractResult
7
+ # @param path [String]
7
8
  # @param build [Build]
8
- def initialize(build)
9
+ def initialize(path, build)
10
+ @path = path
9
11
  @build = build
10
12
  end
11
13
 
12
14
  # @note Implement {AbstractResult#coverage}
13
15
  # @return [Float]
14
16
  def coverage
15
- last_run_json = find_artifact('.last_run.json') or return Float::NaN
17
+ last_run_json = find_artifact('.last_run.json') or return Float::NAN
16
18
  JSON.parse(last_run_json.body)['result']['covered_percent']
17
19
  end
18
20
 
@@ -25,12 +27,12 @@ module CircleCI
25
27
 
26
28
  private
27
29
 
28
- attr_reader :build
30
+ attr_reader :build, :path
29
31
 
30
32
  # @param end_with [String]
31
33
  # @return [Artifact]
32
34
  def find_artifact(end_with)
33
- build.artifacts.find { |a| a.end_with?(end_with) }
35
+ build.artifacts.find { |a| a.end_with?("#{path}/#{end_with}") }
34
36
  end
35
37
  end
36
38
  end
@@ -10,11 +10,6 @@ module CircleCI
10
10
  class Reporter < AbstractReporter
11
11
  DEFAULT_PATH = 'coverage'.freeze
12
12
 
13
- # @param path [String] relative path from artifacts dir to coverage directory
14
- def initialize(path = DEFAULT_PATH)
15
- @path = path
16
- end
17
-
18
13
  # @note Implement {AbstractReporter#name}
19
14
  # @return [String]
20
15
  def name
@@ -23,14 +18,12 @@ module CircleCI
23
18
 
24
19
  private
25
20
 
26
- attr_reader :path
27
-
28
21
  # @note Implement {AbstractReporter#create_build_result}
29
22
  # @param build [Build, nil]
30
23
  # @return [BuildResult, nil]
31
24
  def create_build_result(build)
32
25
  return unless build
33
- BuildResult.new(build)
26
+ BuildResult.new(path, build)
34
27
  end
35
28
 
36
29
  # @note Implement {AbstractReporter#create_current_result}
@@ -2,8 +2,8 @@ module CircleCI
2
2
  module CoverageReporter
3
3
  module Version
4
4
  MAJOR = 0
5
- MINOR = 1
6
- PATCH = 3
5
+ MINOR = 2
6
+ PATCH = 0
7
7
 
8
8
  def self.to_s
9
9
  [MAJOR, MINOR, PATCH].join('.')
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.1.3
4
+ version: 0.2.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-03-11 00:00:00.000000000 Z
11
+ date: 2017-03-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -48,6 +48,7 @@ files:
48
48
  - ".gitignore"
49
49
  - ".rspec"
50
50
  - ".rubocop.yml"
51
+ - ".yardopts"
51
52
  - CHANGELOG.md
52
53
  - Gemfile
53
54
  - LICENSE.txt
@@ -65,6 +66,9 @@ files:
65
66
  - lib/circleci/coverage_reporter/client.rb
66
67
  - lib/circleci/coverage_reporter/configuration.rb
67
68
  - lib/circleci/coverage_reporter/errors.rb
69
+ - lib/circleci/coverage_reporter/flow/build_result.rb
70
+ - lib/circleci/coverage_reporter/flow/current_result.rb
71
+ - lib/circleci/coverage_reporter/flow/reporter.rb
68
72
  - lib/circleci/coverage_reporter/github_client.rb
69
73
  - lib/circleci/coverage_reporter/rake_task.rb
70
74
  - lib/circleci/coverage_reporter/report.rb