couve 0.5.0 → 0.7.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: b00642800c7fb55e834a786a5243dafe3ff38ae2dc1e638b0c041f4686bc3c28
4
- data.tar.gz: 9d5bf8a939b2c46e528ec47add60d325fdd4105232127f06ffdbe0690840475f
3
+ metadata.gz: 6c6c4d593294316c9fe14a6a2d25d9029a5282c17ba53503a38b440c9b2c452f
4
+ data.tar.gz: bc384881652d204bc8e7cbb337beb019bd3a49db0e3e01955865ee49660791df
5
5
  SHA512:
6
- metadata.gz: 85783f6edf42296754670765ea005c6a63ae4a40aaa26de8ca56ec0861d63155ec30e7e8ab376a09bb9bd0ea76c7d4037520a71a00ad472d496bdb86234c1e65
7
- data.tar.gz: 9f1cc2e8da3106fcdcd0b64450d0d16f28b530c2f33c126df69871cc0387408788f4f4b09c7908b2be99056d9a144df1654d9d2b219745a60848916b56cfa93f
6
+ metadata.gz: e90965ed10dd06d895bad918c452b5e9efeb6bc8d6b30ded117f3150c9fd1ddc51ff1e2cfbdaa4e3b28aa7bb186dc193632b6699ad0565849d38ac1f1b864272
7
+ data.tar.gz: d1665ba532efcc3ed7177daa9e3cd3b101775e2647000800100187dc98932fe0b9f6ca4f8d5e14e4a653b68abe77e6b2fad1e6c0c951fb3690c818843b23ad06
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.7.0] - 2026-06-05
4
+
5
+ - 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.
6
+ - Rename the report heading from "Coverage problems" to "Coverage report".
7
+
8
+ ## [0.6.0] - 2026-06-04
9
+
10
+ - Add Markdown output format, selected from the output file extension (`.md`). HTML remains the default.
11
+
3
12
  ## [0.1.0] - 2023-07-19
4
13
 
5
14
  - Initial release
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- couve (0.4.0)
4
+ couve (0.7.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -33,10 +33,10 @@ GEM
33
33
  rb-inotify (~> 0.9, >= 0.9.10)
34
34
  lumberjack (1.2.9)
35
35
  method_source (1.0.0)
36
+ mini_portile2 (2.8.9)
36
37
  nenv (0.3.0)
37
- nokogiri (1.15.3-x86_64-darwin)
38
- racc (~> 1.4)
39
- nokogiri (1.15.3-x86_64-linux)
38
+ nokogiri (1.15.3)
39
+ mini_portile2 (~> 2.8.2)
40
40
  racc (~> 1.4)
41
41
  notiffany (0.1.3)
42
42
  nenv (~> 0.1)
@@ -88,6 +88,7 @@ GEM
88
88
  unicode-display_width (2.4.2)
89
89
 
90
90
  PLATFORMS
91
+ arm64-darwin-23
91
92
  x86_64-darwin-21
92
93
  x86_64-linux
93
94
 
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
- # Couve
1
+ # Couve - Generate Human Readable CodeClimate Test Reporter
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/couve`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
3
+ Couve is a Ruby gem that aims to simplify the generation of human-readable reports for the CodeClimate test-reporter gem. With Couve, you can quickly and easily generate insightful reports based on the test coverage data in a human-friendly format.
6
4
 
7
5
  ## Installation
8
6
 
@@ -22,18 +20,112 @@ Or install it yourself as:
22
20
 
23
21
  ## Usage
24
22
 
25
- TODO: Write usage instructions here
23
+ 1. Install the `couve` gem.
24
+
25
+ ```ruby
26
+ gem install couve
27
+ ```
28
+
29
+ 2. Run the following command in your terminal, providing the path to your JSON coverage file and the desired output file.
30
+
31
+ ```
32
+ $ couve path/to/coverage.json path/to/output.html
33
+ ```
34
+
35
+ Couve will process the coverage data and generate a human-readable HTML report, providing insights into your project's test coverage.
36
+
37
+ ### Output formats
38
+
39
+ Couve picks the output format from the output file's extension:
40
+
41
+ - `.html` (or anything else) — a self-contained, styled **HTML** report. Great for uploading as a CI artifact.
42
+ - `.md` — a **Markdown** report. Great for posting as a pull request comment.
43
+
44
+ ```
45
+ $ couve path/to/coverage.json path/to/report.html # HTML report
46
+ $ couve path/to/coverage.json path/to/report.md # Markdown report
47
+ ```
48
+
49
+ The Markdown report renders as a GitHub-flavored table, with a colored rating indicator (🔴/🟡/🟢) reflecting each file's coverage level:
50
+
51
+ ```markdown
52
+ ## Coverage problems
53
+
54
+ | Rating | Coverage | File | Not covered lines |
55
+ | :---: | ---: | :--- | :--- |
56
+ | 🔴 | 30% | app/models/foo.rb | 3, 8, 21 |
57
+ | 🟡 | 50% | app/services/bar.rb | 5, 6 |
58
+ ```
59
+
60
+ A typical CI setup keeps the HTML report as an artifact and posts the Markdown report to the pull request, e.g. with the GitHub CLI:
61
+
62
+ ```sh
63
+ couve coverage.json coverage.html # upload as a CI artifact
64
+ couve coverage.json coverage.md # post to the PR
65
+ gh pr comment "$PR_NUMBER" --body-file coverage.md
66
+ ```
67
+
68
+ ### Reporting only the files you changed
69
+
70
+ By default the report lists every file in the coverage data that is below 100%. With `--changed-files` you flip that around: instead of a project-wide view, you get the coverage status of exactly the files you touched on a branch — including the ones that are fully covered.
71
+
72
+ Pass a file with one repo-relative path per line, or `-` to read the list from standard input:
73
+
74
+ ```sh
75
+ git diff --name-only origin/main...HEAD > changed.txt
76
+ couve coverage.json report.md --changed-files changed.txt
77
+
78
+ # or pipe the list straight in:
79
+ git diff --name-only origin/main...HEAD | couve coverage.json report.md --changed-files -
80
+ ```
81
+
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.
26
83
 
27
84
  ## Development
28
85
 
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
86
+ To contribute to Couve's development, follow these steps:
87
+
88
+ 1. Clone the repository from GitHub:
89
+
90
+ ```
91
+ $ git clone https://github.com/asseinfo/couve.git
92
+ ```
93
+
94
+ 2. Install the gem dependencies by running:
95
+
96
+ ```
97
+ $ bin/setup
98
+ ```
99
+
100
+ 3. Run the tests to ensure everything is set up correctly:
101
+
102
+ ```
103
+ $ rake spec
104
+ ```
30
105
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
106
+ 4. You can also use the interactive prompt to experiment with the code:
107
+
108
+ ```
109
+ $ bin/console
110
+ ```
32
111
 
33
112
  ## Contributing
34
113
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/couve.
114
+ We welcome bug reports and pull requests from the community. If you encounter any issues with Couve or have suggestions for improvements, please open an issue on [GitHub](https://github.com/asseinfo/couve) to let us know.
36
115
 
37
- ## License
116
+ If you'd like to contribute directly, please follow these steps:
117
+
118
+ 1. Fork the repository on GitHub.
38
119
 
39
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
120
+ 2. Create a new branch from the `main` branch.
121
+
122
+ 3. Make your changes and commit them with descriptive commit messages.
123
+
124
+ 4. Push your changes to your fork.
125
+
126
+ 5. Submit a pull request to the `main` branch of the original repository.
127
+
128
+ We appreciate your contributions and will review and merge pull requests as appropriate.
129
+
130
+ ## License
131
+ Couve is released under the [MIT License](https://opensource.org/licenses/MIT), which allows you to use, modify, and distribute the gem freely. See the LICENSE file for more details.
data/lib/couve/parser.rb CHANGED
@@ -4,9 +4,15 @@ require "json"
4
4
 
5
5
  module Couve
6
6
  class Parser
7
- def initialize(coverage)
7
+ def initialize(coverage, changed_files: nil)
8
8
  @coverage = JSON.parse(coverage, symbolize_names: true)
9
- @coverage[:source_files].reject! { |file| file[:covered_percent] == 100 }
9
+
10
+ if changed_files
11
+ @coverage[:source_files].select! { |file| changed_files.include?(file[:name]) }
12
+ else
13
+ @coverage[:source_files].reject! { |file| file[:covered_percent] == 100 }
14
+ end
15
+
10
16
  @coverage[:source_files].sort_by! { |file| file[:covered_percent] }
11
17
  end
12
18
 
@@ -16,7 +22,7 @@ module Couve
16
22
  <body>
17
23
  <div class="container mt-5">
18
24
  <h1 class="display-5">
19
- Coverage problems
25
+ Coverage report
20
26
  </h1>
21
27
 
22
28
  <table class="table table-hover mt-5">
@@ -38,6 +44,23 @@ module Couve
38
44
  HTML
39
45
  end
40
46
 
47
+ def to_markdown
48
+ rows = @coverage[:source_files].map do |source_file|
49
+ percentage = source_file[:covered_percent].round(2)
50
+ indicator = percentage_indicator(percentage)
51
+
52
+ "| #{indicator} | #{percentage}% | #{source_file[:name]} | #{not_covered_lines(source_file)} |"
53
+ end
54
+
55
+ <<~MARKDOWN
56
+ ## Coverage report
57
+
58
+ | Rating | Coverage | File | Not covered lines |
59
+ | :---: | ---: | :--- | :--- |
60
+ #{rows.join("\n")}
61
+ MARKDOWN
62
+ end
63
+
41
64
  private
42
65
 
43
66
  # rubocop:disable Metrics/MethodLength
@@ -84,6 +107,16 @@ module Couve
84
107
  end
85
108
  end
86
109
 
110
+ def percentage_indicator(percentage)
111
+ if percentage < 33.33
112
+ "🔴"
113
+ elsif percentage < 66.66
114
+ "🟡"
115
+ else
116
+ "🟢"
117
+ end
118
+ end
119
+
87
120
  def not_covered_lines(source_file)
88
121
  total_lines = JSON.parse(source_file[:coverage])
89
122
 
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.5.0"
4
+ VERSION = "0.7.0"
5
5
  end
data/lib/couve.rb CHANGED
@@ -1,18 +1,40 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "optparse"
4
+
3
5
  require_relative "couve/version"
4
6
  require_relative "couve/parser"
5
7
 
6
8
  module Couve
7
- def self.start
8
- coverage_file = ARGV[0]
9
- output_file = ARGV[1]
9
+ def self.start(argv = ARGV)
10
+ coverage_file, output_file, changed_files_source = parse_arguments(argv)
10
11
 
11
12
  coverage = File.read(coverage_file)
12
- parser = Couve::Parser.new(coverage)
13
+ parser = Couve::Parser.new(coverage, changed_files: changed_files(changed_files_source))
14
+
15
+ report = output_file.end_with?(".md") ? parser.to_markdown : parser.to_html
16
+
17
+ File.open(output_file, "w") { |f| f.puts report }
18
+ end
19
+
20
+ def self.parse_arguments(argv)
21
+ argv = argv.dup
22
+ changed_files_source = nil
23
+
24
+ OptionParser.new do |opts|
25
+ opts.on("--changed-files PATH", "Only report the files listed in PATH (use - for stdin)") do |path|
26
+ changed_files_source = path
27
+ end
28
+ end.parse!(argv)
29
+
30
+ [argv[0], argv[1], changed_files_source]
31
+ end
32
+
33
+ def self.changed_files(source)
34
+ return nil unless source
35
+
36
+ contents = source == "-" ? $stdin.read : File.read(source)
13
37
 
14
- File.open(output_file, "w") do |f|
15
- f.puts parser.to_html
16
- end
38
+ contents.lines.map { |line| line.strip.delete_prefix("./") }.reject(&:empty?)
17
39
  end
18
40
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: couve
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cezinha
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-07-24 00:00:00.000000000 Z
11
+ date: 2026-06-05 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email:
@@ -58,7 +58,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
58
58
  - !ruby/object:Gem::Version
59
59
  version: '0'
60
60
  requirements: []
61
- rubygems_version: 3.2.32
61
+ rubygems_version: 3.5.16
62
62
  signing_key:
63
63
  specification_version: 4
64
64
  summary: Generate a human readable report for CodeClimate test-reporter gem.