couve 0.7.0 → 0.8.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
  SHA256:
3
- metadata.gz: 6c6c4d593294316c9fe14a6a2d25d9029a5282c17ba53503a38b440c9b2c452f
4
- data.tar.gz: bc384881652d204bc8e7cbb337beb019bd3a49db0e3e01955865ee49660791df
3
+ metadata.gz: 6733bb77b61c6eeb3d8154eb7dc8e04afdae265464983866b237c7474198612a
4
+ data.tar.gz: 2418be05c9acbf968ac32019ef0d86918b117b68a9f77719d4295e88c074188c
5
5
  SHA512:
6
- metadata.gz: e90965ed10dd06d895bad918c452b5e9efeb6bc8d6b30ded117f3150c9fd1ddc51ff1e2cfbdaa4e3b28aa7bb186dc193632b6699ad0565849d38ac1f1b864272
7
- data.tar.gz: d1665ba532efcc3ed7177daa9e3cd3b101775e2647000800100187dc98932fe0b9f6ca4f8d5e14e4a653b68abe77e6b2fad1e6c0c951fb3690c818843b23ad06
6
+ metadata.gz: 819b2d0c9f768011eb37641ac59a7ac94077222071e867a4a1a50cc51a6ece7bf4028bac072463551e266940e0d12d6b0ce72b15e76070f651a05bef5f4e0257
7
+ data.tar.gz: 9f4cb0dc81003cacd9df9a4702e4d4bc4b4950747d84a1c28ca7c7783241cd3b823e1589a873da0b792123527bf2b8a90c0f08dec66019f6821a6256c8585d42
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.8.0] - 2026-06-05
4
+
5
+ - Add `--fail-on-low-coverage` flag to exit with a non-zero status when any reported file is below 100% coverage.
6
+
3
7
  ## [0.7.0] - 2026-06-05
4
8
 
5
9
  - Add `--changed-files` to report the coverage status of a given list of files (e.g. a branch's changed files), including fully covered ones, instead of the project-wide below-100% view.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- couve (0.7.0)
4
+ couve (0.8.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -81,6 +81,27 @@ git diff --name-only origin/main...HEAD | couve coverage.json report.md --change
81
81
 
82
82
  Only files that appear both in the list and in the coverage data are shown; the rest of the project is left out. Coverage is still reported per file (the whole file's percentage and missed lines), not just the lines in your diff.
83
83
 
84
+ ### Failing the build on low coverage
85
+
86
+ By default couve always exits `0` — it only generates the report. Pass `--fail-on-low-coverage` to make couve exit `1` when any **reported** file is below the green threshold, i.e. rated 🔴 or 🟡 (`< 66.66%`):
87
+
88
+ ```sh
89
+ couve coverage.json report.md --fail-on-low-coverage
90
+ ```
91
+
92
+ The report is written **before** couve exits, so the offending files stay visible in the report (and in any PR comment built from it). The offending files are also printed to standard error:
93
+
94
+ ```
95
+ couve: coverage below 66.66% in app/models/foo.rb, app/services/bar.rb
96
+ ```
97
+
98
+ The threshold is the same fixed band used for the rating indicators; there is nothing to configure. The flag respects `--changed-files` scope: when you only report the files you changed, only those files are evaluated, so a green (or empty) changed-file set passes the build even if untouched files elsewhere are poorly covered.
99
+
100
+ ```sh
101
+ # Post the report to the PR, then redden the build if a changed file is under-covered:
102
+ git diff --name-only origin/main...HEAD | couve coverage.json report.md --changed-files - --fail-on-low-coverage
103
+ ```
104
+
84
105
  ## Development
85
106
 
86
107
  To contribute to Couve's development, follow these steps:
data/lib/couve/parser.rb CHANGED
@@ -3,7 +3,10 @@
3
3
  require "json"
4
4
 
5
5
  module Couve
6
- class Parser
6
+ class Parser # rubocop:disable Metrics/ClassLength
7
+ RED_THRESHOLD = 33.33
8
+ GREEN_THRESHOLD = 66.66
9
+
7
10
  def initialize(coverage, changed_files: nil)
8
11
  @coverage = JSON.parse(coverage, symbolize_names: true)
9
12
 
@@ -61,6 +64,16 @@ module Couve
61
64
  MARKDOWN
62
65
  end
63
66
 
67
+ def low_coverage_files
68
+ @coverage[:source_files]
69
+ .select { |source_file| source_file[:covered_percent].round(2) < GREEN_THRESHOLD }
70
+ .map { |source_file| source_file[:name] }
71
+ end
72
+
73
+ def low_coverage?
74
+ low_coverage_files.any?
75
+ end
76
+
64
77
  private
65
78
 
66
79
  # rubocop:disable Metrics/MethodLength
@@ -98,9 +111,9 @@ module Couve
98
111
  # rubocop:enable Metrics/MethodLength
99
112
 
100
113
  def percentage_bar_color(percentage)
101
- if percentage < 33.33
114
+ if percentage < RED_THRESHOLD
102
115
  "bg-danger"
103
- elsif percentage < 66.66
116
+ elsif percentage < GREEN_THRESHOLD
104
117
  "bg-warning"
105
118
  else
106
119
  "bg-success"
@@ -108,9 +121,9 @@ module Couve
108
121
  end
109
122
 
110
123
  def percentage_indicator(percentage)
111
- if percentage < 33.33
124
+ if percentage < RED_THRESHOLD
112
125
  "🔴"
113
- elsif percentage < 66.66
126
+ elsif percentage < GREEN_THRESHOLD
114
127
  "🟡"
115
128
  else
116
129
  "🟢"
data/lib/couve/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Couve
4
- VERSION = "0.7.0"
4
+ VERSION = "0.8.0"
5
5
  end
data/lib/couve.rb CHANGED
@@ -7,7 +7,7 @@ require_relative "couve/parser"
7
7
 
8
8
  module Couve
9
9
  def self.start(argv = ARGV)
10
- coverage_file, output_file, changed_files_source = parse_arguments(argv)
10
+ coverage_file, output_file, changed_files_source, fail_on_low_coverage = parse_arguments(argv)
11
11
 
12
12
  coverage = File.read(coverage_file)
13
13
  parser = Couve::Parser.new(coverage, changed_files: changed_files(changed_files_source))
@@ -15,19 +15,30 @@ module Couve
15
15
  report = output_file.end_with?(".md") ? parser.to_markdown : parser.to_html
16
16
 
17
17
  File.open(output_file, "w") { |f| f.puts report }
18
+
19
+ return unless fail_on_low_coverage && parser.low_coverage?
20
+
21
+ warn "couve: coverage below #{Couve::Parser::GREEN_THRESHOLD}% in #{parser.low_coverage_files.join(", ")}"
22
+ exit 1
18
23
  end
19
24
 
20
- def self.parse_arguments(argv)
25
+ def self.parse_arguments(argv) # rubocop:disable Metrics/MethodLength
21
26
  argv = argv.dup
22
27
  changed_files_source = nil
28
+ fail_on_low_coverage = false
23
29
 
24
30
  OptionParser.new do |opts|
25
31
  opts.on("--changed-files PATH", "Only report the files listed in PATH (use - for stdin)") do |path|
26
32
  changed_files_source = path
27
33
  end
34
+
35
+ opts.on("--fail-on-low-coverage",
36
+ "Exit 1 if any reported file is below #{Couve::Parser::GREEN_THRESHOLD}% coverage") do
37
+ fail_on_low_coverage = true
38
+ end
28
39
  end.parse!(argv)
29
40
 
30
- [argv[0], argv[1], changed_files_source]
41
+ [argv[0], argv[1], changed_files_source, fail_on_low_coverage]
31
42
  end
32
43
 
33
44
  def self.changed_files(source)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: couve
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cezinha
@@ -32,7 +32,6 @@ files:
32
32
  - bin/guard
33
33
  - bin/rubocop
34
34
  - bin/setup
35
- - couve.gemspec
36
35
  - exe/couve
37
36
  - lib/couve.rb
38
37
  - lib/couve/parser.rb
data/couve.gemspec DELETED
@@ -1,31 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "lib/couve/version"
4
-
5
- Gem::Specification.new do |spec|
6
- spec.name = "couve"
7
- spec.version = Couve::VERSION
8
- spec.authors = ["Cezinha"]
9
- spec.email = ["cesar@asseinfo.com.br"]
10
- spec.metadata = { "rubygems_mfa_required" => "true" }
11
-
12
- spec.summary = "Generate a human readable report for CodeClimate test-reporter gem."
13
-
14
- # Specify which files should be added to the gem when it is released.
15
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
16
- spec.files = Dir.chdir(File.expand_path(__dir__)) do
17
- `git ls-files -z`.split("\x0").reject do |f|
18
- (f == __FILE__) || f.match(%r{\A(?:(?:test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
19
- end
20
- end
21
- spec.bindir = "exe"
22
- spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
23
- spec.require_paths = ["lib", "lib/couve"]
24
- spec.required_ruby_version = ">= 3"
25
-
26
- # Uncomment to register a new dependency of your gem
27
- # spec.add_dependency "example-gem", "~> 1.0"
28
-
29
- # For more information and examples about making a new gem, checkout our
30
- # guide at: https://bundler.io/guides/creating_gem.html
31
- end