churn_vs_complexity 1.5.1 → 1.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -2
- data/README.md +4 -1
- data/lib/churn_vs_complexity/cli/main.rb +46 -0
- data/lib/churn_vs_complexity/cli/parser.rb +1 -1
- data/lib/churn_vs_complexity/cli.rb +2 -27
- data/lib/churn_vs_complexity/delta/checker.rb +4 -6
- data/lib/churn_vs_complexity/delta/commit_hydrator.rb +22 -0
- data/lib/churn_vs_complexity/delta/config.rb +1 -1
- data/lib/churn_vs_complexity/delta.rb +1 -0
- data/lib/churn_vs_complexity/git_strategy.rb +8 -6
- data/lib/churn_vs_complexity/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 843cae8dad7f09344cbea477eb73ae3d9d57945df8a5955d93d6dfc820b5a8e1
|
4
|
+
data.tar.gz: 5066b98af73acde0f18b233fd12efe6858bb9977c4a9d553970c6ad859db98a9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7af6d2c460fd9bb2cb78751d8a7f5cdd3ada48e9026e61ccbd3ef74a22c738bcfea4185984ffea2476a5d4b726f902c881edabf2baefa211884bfb129b59f80c
|
7
|
+
data.tar.gz: c3cf5e4dfd7bea34298fac9d7e2db1b7ffe58ad16acab25e9217dae0f84b43e2da7d89f147027f1ebb3fd52115538aba81a1f05bca5a0f7e13f0ad5d3a7b9aef
|
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,9 @@
|
|
1
|
-
##
|
1
|
+
## [1.5.2] - 2024-10-21
|
2
|
+
|
3
|
+
- Fixed bug where delta mode validations would fail when the commit was a non-sha value.
|
4
|
+
- Allow HEAD as specified commit in delta mode
|
5
|
+
|
6
|
+
## [1.5.1] - 2024-10-15
|
2
7
|
|
3
8
|
- Fix bug where worktree checkout silently failed
|
4
9
|
|
@@ -32,4 +37,4 @@
|
|
32
37
|
|
33
38
|
## [1.0.0] - 2024-06-07
|
34
39
|
|
35
|
-
- Initial release
|
40
|
+
- Initial release
|
data/README.md
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
[![Gem Version](https://badge.fury.io/rb/churn_vs_complexity.svg)](https://badge.fury.io/rb/churn_vs_complexity)
|
2
|
+
|
1
3
|
# ChurnVsComplexity
|
2
4
|
|
3
5
|
A tool to visualise code complexity in a project and help direct refactoring efforts.
|
@@ -47,9 +49,10 @@ Usage: churn_vs_complexity [options] folder
|
|
47
49
|
-q, --quarter Calculate churn for the quarter leading up to the most recent commit
|
48
50
|
-y, --year Calculate churn for the year leading up to the most recent commit
|
49
51
|
--timetravel N Calculate summary for all commits at intervals of N days throughout project history or from the date specified with --since
|
50
|
-
--delta SHA Identify changes between the specified commit and the previous commit and annotate changed files with complexity score. Can be used multiple times to specify multiple commits.
|
52
|
+
--delta SHA Identify changes between the specified commit (SHA) and the previous commit and annotate changed files with complexity score. SHA can be a full or short commit hash, or the value HEAD. Can be used multiple times to specify multiple commits.
|
51
53
|
--dry-run Echo the chosen options from the CLI
|
52
54
|
-h, --help Display help
|
55
|
+
--version Display version
|
53
56
|
```
|
54
57
|
|
55
58
|
Note that when using the `--timetravel` mode, the semantics of some flags are subtly different from normal mode:
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'optparse'
|
4
|
+
|
5
|
+
module ChurnVsComplexity
|
6
|
+
module CLI
|
7
|
+
module Main
|
8
|
+
class << self
|
9
|
+
def run!(options, folder)
|
10
|
+
validate_folder!(folder)
|
11
|
+
validate_options!(options)
|
12
|
+
config = config(options)
|
13
|
+
config.validate!
|
14
|
+
|
15
|
+
config.checker.check(folder:)
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def validate_folder!(folder)
|
21
|
+
raise ValidationError, 'No folder selected. Use --help for usage information.' if folder.nil? || folder.empty?
|
22
|
+
raise ValidationError, "Folder #{folder} does not exist" unless File.directory?(folder)
|
23
|
+
end
|
24
|
+
|
25
|
+
def validate_options!(options)
|
26
|
+
raise ValidationError, 'No options selected. Use --help for usage information.' if options.empty?
|
27
|
+
raise ValidationError, 'No language selected. Use --help for usage information.' if options[:language].nil?
|
28
|
+
|
29
|
+
return unless options[:serializer].nil?
|
30
|
+
|
31
|
+
raise ValidationError, 'No serializer selected. Use --help for usage information.'
|
32
|
+
end
|
33
|
+
|
34
|
+
def config(options)
|
35
|
+
config_class =
|
36
|
+
case options[:mode]
|
37
|
+
when :timetravel then Timetravel::Config
|
38
|
+
when :delta then Delta::Config
|
39
|
+
else Normal::Config
|
40
|
+
end
|
41
|
+
config_class.new(**options)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -64,7 +64,7 @@ module ChurnVsComplexity
|
|
64
64
|
end
|
65
65
|
|
66
66
|
opts.on('--delta SHA',
|
67
|
-
'Identify changes between the specified commit and the previous commit and annotate changed files with complexity score. Can be used multiple times to specify multiple commits.',) do |value|
|
67
|
+
'Identify changes between the specified commit (SHA) and the previous commit and annotate changed files with complexity score. SHA can be a full or short commit hash, or the value HEAD. Can be used multiple times to specify multiple commits.',) do |value|
|
68
68
|
options[:mode] = :delta
|
69
69
|
(options[:commits] ||= []) << value
|
70
70
|
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative 'cli/parser'
|
4
|
+
require_relative 'cli/main'
|
4
5
|
|
5
6
|
module ChurnVsComplexity
|
6
7
|
module CLI
|
@@ -11,33 +12,7 @@ module ChurnVsComplexity
|
|
11
12
|
# First argument that is not an option is the folder
|
12
13
|
folder = ARGV.first
|
13
14
|
|
14
|
-
|
15
|
-
validate_options!(options)
|
16
|
-
config = config(options)
|
17
|
-
config.validate!
|
18
|
-
puts config.checker.check(folder:)
|
19
|
-
end
|
20
|
-
|
21
|
-
private
|
22
|
-
|
23
|
-
def validate_folder!(folder)
|
24
|
-
raise Error, 'No folder selected. Use --help for usage information.' if folder.nil? || folder.empty?
|
25
|
-
raise Error, "Folder #{folder} does not exist" unless File.directory?(folder)
|
26
|
-
end
|
27
|
-
|
28
|
-
def validate_options!(options)
|
29
|
-
raise Error, 'No options selected. Use --help for usage information.' if options.empty?
|
30
|
-
raise Error, 'No language selected. Use --help for usage information.' if options[:language].nil?
|
31
|
-
raise Error, 'No serializer selected. Use --help for usage information.' if options[:serializer].nil?
|
32
|
-
end
|
33
|
-
|
34
|
-
def config(options)
|
35
|
-
config_class = case options[:mode]
|
36
|
-
when :timetravel then Timetravel::Config
|
37
|
-
when :delta then Delta::Config
|
38
|
-
else Normal::Config
|
39
|
-
end
|
40
|
-
config_class.new(**options)
|
15
|
+
puts Main.run!(options, folder)
|
41
16
|
end
|
42
17
|
end
|
43
18
|
end
|
@@ -40,12 +40,10 @@ module ChurnVsComplexity
|
|
40
40
|
end
|
41
41
|
|
42
42
|
def commit_summary(folder:)
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
end
|
48
|
-
summary
|
43
|
+
CommitHydrator.new(
|
44
|
+
git_strategy: @factory.git_strategy(folder:),
|
45
|
+
serializer: @serializer,
|
46
|
+
).hydrate(@commit)
|
49
47
|
end
|
50
48
|
|
51
49
|
def valid_commit?(folder:)
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ChurnVsComplexity
|
4
|
+
module Delta
|
5
|
+
class CommitHydrator
|
6
|
+
def initialize(git_strategy:, serializer:)
|
7
|
+
@git_strategy = git_strategy
|
8
|
+
@serializer = serializer
|
9
|
+
end
|
10
|
+
|
11
|
+
def hydrate(commit_sha)
|
12
|
+
commit = @git_strategy.object(commit_sha)
|
13
|
+
summary = { commit: commit.sha }
|
14
|
+
if @serializer.respond_to?(:has_commit_summary?) && @serializer.has_commit_summary?
|
15
|
+
parent, next_commit = @git_strategy.surrounding(commit:)
|
16
|
+
summary.merge!(parent:, next_commit:)
|
17
|
+
end
|
18
|
+
summary
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -38,7 +38,7 @@ module ChurnVsComplexity
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def validate_commit!(commit)
|
41
|
-
return if commit.match?(/\A[0-9a-f]{40}\z/i) ||
|
41
|
+
return if commit == 'HEAD' || commit.match?(/\A[0-9a-f]{40}\z/i) || commit.match?(/\A[0-9a-f]{8}\z/i)
|
42
42
|
|
43
43
|
raise ValidationError,
|
44
44
|
"Invalid commit: #{commit}. It must be a valid 40-character SHA-1 hash or an 8-character shortened form."
|
@@ -14,13 +14,15 @@ module ChurnVsComplexity
|
|
14
14
|
false
|
15
15
|
end
|
16
16
|
|
17
|
+
def object(commit)
|
18
|
+
commit.is_a?(Git::Object::Commit) ? commit : @repo.object(commit)
|
19
|
+
end
|
20
|
+
|
17
21
|
def surrounding(commit:)
|
18
|
-
current =
|
19
|
-
|
20
|
-
next_commit = @repo.log(100_000).find
|
21
|
-
|
22
|
-
end
|
23
|
-
[parent&.sha, next_commit&.sha]
|
22
|
+
current = object(commit)
|
23
|
+
is_head = current.sha == @repo.object('HEAD').sha
|
24
|
+
next_commit = is_head ? nil : @repo.log(100_000).find { |c| c.parents.map(&:sha).include?(current.sha) }
|
25
|
+
[current.parent&.sha, next_commit&.sha]
|
24
26
|
end
|
25
27
|
|
26
28
|
def changes(commit:)
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: churn_vs_complexity
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.5.
|
4
|
+
version: 1.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Erik T. Madsen
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date: 2024-10-
|
10
|
+
date: 2024-10-21 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: flog
|
@@ -62,6 +62,7 @@ files:
|
|
62
62
|
- lib/churn_vs_complexity.rb
|
63
63
|
- lib/churn_vs_complexity/churn.rb
|
64
64
|
- lib/churn_vs_complexity/cli.rb
|
65
|
+
- lib/churn_vs_complexity/cli/main.rb
|
65
66
|
- lib/churn_vs_complexity/cli/parser.rb
|
66
67
|
- lib/churn_vs_complexity/complexity.rb
|
67
68
|
- lib/churn_vs_complexity/complexity/eslint_calculator.rb
|
@@ -73,6 +74,7 @@ files:
|
|
73
74
|
- lib/churn_vs_complexity/concurrent_calculator.rb
|
74
75
|
- lib/churn_vs_complexity/delta.rb
|
75
76
|
- lib/churn_vs_complexity/delta/checker.rb
|
77
|
+
- lib/churn_vs_complexity/delta/commit_hydrator.rb
|
76
78
|
- lib/churn_vs_complexity/delta/complexity_annotator.rb
|
77
79
|
- lib/churn_vs_complexity/delta/config.rb
|
78
80
|
- lib/churn_vs_complexity/delta/factory.rb
|