quality_report 1.5.0 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 23d2fbfb3f81887e40858181c9822346e770e8f242d96cfb39b8239b5288cb37
4
- data.tar.gz: f39b9f3ae08503660b79bcc0d286ae622d5e0aa5c06b056ef635a8af8def8576
3
+ metadata.gz: eb26bd22c7b99d601f0eca7648de96e15dc06ac06b405c887cca9c92e96d353f
4
+ data.tar.gz: 03bc3e1613cc9bdb6b84d123164ec213051054d5f05b9627ab57394ca9df721f
5
5
  SHA512:
6
- metadata.gz: de5bfd72e7ea4b31e0bf57785ea38d5503624f0861adc660c1844848d32d839a90ecfb0ed6f5de1eabe13293846fd1771be45bb8f373725eabf6aed092fb50bf
7
- data.tar.gz: bd38063b3c625ac4296dacff7ca0499192bcbb140f744ea7a063a8fe4e3f98c5f1a1ee93831242592e0f744fecef512081f5fc5c9f134751dba6ea91d14e0285
6
+ metadata.gz: 4a35e38922d52d49f34d6e4269e76aa1e43820f7c3d22ab569aa92667397cf3a1b9b0bfeed46fbc188bf3fcf9911166c6ec8372f074c033272e378b21a9e3383
7
+ data.tar.gz: d841f2ecc4afc0bbefeacc3500be6132e976d82da5705759151527d8be64b03cfdb96083e2819eff1590d725d1f34e59b644c349bb6c08ef09146bf4e893211a
data/.rubocop.yml CHANGED
@@ -1,2 +1,2 @@
1
1
  AllCops:
2
- TargetRubyVersion: 3.1
2
+ TargetRubyVersion: 3.1
data/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  ## Installation
4
4
 
5
5
  ```sh
6
- gem install quality-report
6
+ gem install quality_report
7
7
  ```
8
8
 
9
9
  ## Usage
data/Rakefile CHANGED
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "bundler/gem_tasks"
4
- require "rspec/core/rake_task"
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
5
 
6
6
  RSpec::Core::RakeTask.new(:spec)
7
7
 
@@ -1,6 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
+ require 'json'
5
+ require 'tty-option'
4
6
  require 'tty-table'
5
7
  require 'pastel'
6
8
 
@@ -43,17 +45,27 @@ def generate_csv(combined_stats)
43
45
  .join("\n")
44
46
  end
45
47
 
46
- def generate_table(combined_stats)
47
- table = TTY::Table.new(header: %W[Author Percent\nFlagged Flagged\nLines All\nLines])
48
- table_data = generate_data(combined_stats).reject { should_skip?(_1) }
48
+ def generate_table(combined_stats, colspec: {}, skip: '')
49
+ default_headings = ['Author', 'Percent Flagged', 'Flagged Lines', 'All lines']
50
+ static_heading = colspec.keys&.first # Handle just one column for now
51
+ all_headings = (default_headings + [static_heading]).compact
52
+
53
+ table = TTY::Table.new(header: all_headings)
54
+ table_data = generate_data(combined_stats).reject { should_skip?(_1) }
55
+ static_values = colspec[static_heading] || {}
49
56
 
50
57
  table_data.each do |stats|
51
- table << [
58
+ next if skip.include?(stats[:label])
59
+
60
+ new_row = [
52
61
  { value: stats[:label], alignment: :left },
53
62
  { value: "#{stats[:percent]}%", alignment: :right },
54
63
  { value: int_to_accounting(stats[:part_count]), alignment: :right },
55
64
  { value: int_to_accounting(stats[:whole_count]), alignment: :right }
56
65
  ]
66
+ new_row << { value: static_values[stats[:label]], alignment: :left } if static_heading
67
+
68
+ table << new_row
57
69
  end
58
70
 
59
71
  render_table(table, table_data)
@@ -126,11 +138,82 @@ def int_to_accounting(an_int)
126
138
  an_int.to_s.reverse.gsub(/(\d{3})(?=\d)/, '\\1,').reverse
127
139
  end
128
140
 
141
+ #
142
+ # CLI Argument Parser
143
+ #
144
+ class Command
145
+ include TTY::Option
146
+
147
+ usage do
148
+ program 'ruby-quality-report'
149
+ no_command
150
+ header 'Ruby Quality Report'
151
+ desc <<~DESC
152
+ Generates a report of the percentage of flagged lines of code written by each author. For improved relevance, it excludes:
153
+
154
+ - authors with fewer than 200 lines of code
155
+ - authors with no commits in the previous 60 days
156
+
157
+ It runs a suite of Rubocop metrics on *.rb files recursively starting in the current directory. Then, using git, it calculates the percentage of warnings per line written, per author. Each failing check is another warning.
158
+ DESC
159
+
160
+ example <<~EXAMPLE1
161
+ Append a column showing office location. The order of the keys in the JSON does not matter:
162
+ $ ruby-quality-report -c '{"Location": {"Amy": "NYC", "Bob": "Remote"}}'
163
+ EXAMPLE1
164
+
165
+ example <<~EXAMPLE2
166
+ Skip one author:
167
+ $ ruby-quality-report --skip Cathy
168
+ EXAMPLE2
169
+ end
170
+
171
+ option :add_column do
172
+ long '--add-column JSON'
173
+ short '-c JSON'
174
+ desc 'Add a static column to the report. This is a simple way to add known information. See the examples.'
175
+ end
176
+
177
+ flag :skip do
178
+ long '--skip AUTHOR'
179
+ short '-s AUTHOR'
180
+ desc 'Filter out a git author'
181
+ end
182
+
183
+ flag :help do
184
+ short '-h'
185
+ long '--help'
186
+ desc 'Print this help'
187
+ end
188
+
189
+ def run
190
+ if params[:help]
191
+ print help
192
+ exit 1
193
+ elsif params.errors.any?
194
+ puts params.errors.summary
195
+ exit 1
196
+ end
197
+ end
198
+ end
199
+
129
200
  #
130
201
  # Execution begins here
131
202
  #
203
+
204
+ command = Command.new
205
+ command.parse
206
+ command.run
207
+
208
+ add_column_param = command.params[:add_column]
209
+ colspec = add_column_param ? JSON.parse(add_column_param) : {}
210
+ puts "Adding column: #{colspec.keys.first}" unless colspec.empty?
211
+
212
+ skip = command.params[:skip] || ''
213
+ puts "Skipping author: #{skip}" if skip != ''
214
+
132
215
  PART_STATS = `ruby-author-warnings | frequency-list`.freeze
133
- WHOLE_STATS = `ruby-line-authors | frequency-list`.freeze
216
+ WHOLE_STATS = `ruby-line-authors | frequency-list`.freeze
134
217
  COMBINED_STATS = create_combined_stats(PART_STATS, WHOLE_STATS)
135
218
 
136
- puts generate_table(COMBINED_STATS)
219
+ puts generate_table(COMBINED_STATS, colspec:, skip:)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module QualityReport
4
- VERSION = '1.5.0'
4
+ VERSION = '1.6.0'
5
5
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "quality_report/version"
3
+ require_relative 'quality_report/version'
4
4
 
5
5
  module QualityReport
6
6
  class Error < StandardError; end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quality_report
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robb Shecter
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-11-10 00:00:00.000000000 Z
11
+ date: 2024-11-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.68'
27
+ - !ruby/object:Gem::Dependency
28
+ name: tty-option
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.3.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.3.0
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: tty-table
29
43
  requirement: !ruby/object:Gem::Requirement