rubosquad 0.1.0 → 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 +4 -4
- data/lib/rubosquad.rb +82 -20
- metadata +5 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: bc5a605727814b79d31d6d01ace3cb53ea6889e1c47e29ce27d612a31a6aea85
|
|
4
|
+
data.tar.gz: f6fc4368c48f1dc19d8081161dc10beafe3caeb7f6d7511c2cb26c13d891a12c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6d4adf406923dc9b9613bd0c90b68f6dd51023f4c03f07d05b406de2c98dd0b632cee46105c96432e0c8019ee7baa3eeed0fbea5a80d0746bb4141ceca777f04
|
|
7
|
+
data.tar.gz: af009b59c62ce252ad5cd99b97fedd079c4d52d7dd4dd2a7401eaf9d476016676717c4a570559902cdd6c9ce4c3db8bdc10c64fcaa11a8fd5cd187c6cdf7e93e
|
data/lib/rubosquad.rb
CHANGED
|
@@ -2,32 +2,80 @@
|
|
|
2
2
|
|
|
3
3
|
require 'open3'
|
|
4
4
|
require 'set'
|
|
5
|
-
|
|
5
|
+
require 'optparse'
|
|
6
|
+
|
|
7
|
+
# Get the list of changed Ruby files in the current branch compared to main
|
|
6
8
|
module Rubosquad
|
|
7
|
-
class CLI
|
|
8
|
-
def self.run
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
class CLI
|
|
10
|
+
def self.run
|
|
11
|
+
options = {}
|
|
12
|
+
OptionParser.new do |opts|
|
|
13
|
+
opts.banner = 'Usage: rubosquad [options]'
|
|
14
|
+
opts.on('-a', '--auto-correct', 'Run with rubocop -a instead of -A') do
|
|
15
|
+
options[:auto_correct] = true
|
|
16
|
+
end
|
|
17
|
+
end.parse!
|
|
18
|
+
|
|
19
|
+
# Get the base branch (try main, then master, then origin/main, then origin/master)
|
|
20
|
+
base_branch = detect_base_branch
|
|
21
|
+
|
|
22
|
+
unless base_branch
|
|
23
|
+
Rails.logger.debug 'Error: Could not find main or master branch.'
|
|
24
|
+
exit 1
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# Get current branch name
|
|
28
|
+
current_branch = `git rev-parse --abbrev-ref HEAD`.strip
|
|
29
|
+
|
|
30
|
+
if current_branch == base_branch
|
|
31
|
+
Rails.logger.debug "Warning: You are on the #{base_branch} branch. Comparing working directory changes."
|
|
32
|
+
# Compare working directory + staged changes against HEAD
|
|
33
|
+
changed_files = `git diff --name-only HEAD`.split("\n")
|
|
34
|
+
changed_files += `git diff --name-only --cached`.split("\n")
|
|
35
|
+
changed_files = changed_files.uniq.grep(/\.rb$/)
|
|
36
|
+
else
|
|
37
|
+
# Compare current branch against base branch (all commits since divergence)
|
|
38
|
+
changed_files = `git diff --name-only #{base_branch}...HEAD`.split("\n").grep(/\.rb$/)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# Filter out deleted files and files that don't exist
|
|
42
|
+
changed_files = changed_files.select { |file| File.exist?(file) }
|
|
11
43
|
|
|
12
44
|
if changed_files.empty?
|
|
13
|
-
|
|
45
|
+
Rails.logger.debug 'No Ruby files have changed.'
|
|
14
46
|
exit 0
|
|
15
47
|
end
|
|
16
48
|
|
|
17
|
-
|
|
18
|
-
|
|
49
|
+
comparison_info = if current_branch == base_branch
|
|
50
|
+
"working directory changes on #{base_branch}"
|
|
51
|
+
else
|
|
52
|
+
"#{current_branch} vs #{base_branch}"
|
|
53
|
+
end
|
|
19
54
|
|
|
20
|
-
|
|
55
|
+
Rails.logger.debug "\nRunning Rubocop on changed files (#{comparison_info}):"
|
|
56
|
+
changed_files.each { |file| puts " - #{file}" }
|
|
57
|
+
Rails.logger.debug
|
|
58
|
+
|
|
59
|
+
# Check for available RuboCop extensions that can actually be loaded
|
|
21
60
|
extensions = %w[rubocop-factory_bot rubocop-rails rubocop-rspec rubocop-rspec_rails]
|
|
22
|
-
available_extensions = extensions.select
|
|
61
|
+
available_extensions = extensions.select do |ext|
|
|
62
|
+
require ext
|
|
63
|
+
true
|
|
64
|
+
rescue LoadError
|
|
65
|
+
false
|
|
66
|
+
end
|
|
23
67
|
|
|
24
68
|
# Construct the RuboCop command
|
|
25
|
-
|
|
69
|
+
|
|
70
|
+
rubocop_option = options[:auto_correct] ? '-a' : '-A'
|
|
71
|
+
command = "rubocop #{rubocop_option} --format offenses --format simple #{available_extensions.map do |ext|
|
|
26
72
|
"--require #{ext}"
|
|
27
73
|
end.join(' ')} #{changed_files.join(' ')}"
|
|
74
|
+
|
|
28
75
|
stdout, stderr, status = Open3.capture3(command)
|
|
29
76
|
|
|
30
|
-
|
|
77
|
+
Rails.logger.debug "\nRubocop Output:"
|
|
78
|
+
Rails.logger.debug '==Error type: Legend: C = Convention, W = Warning, E = Error, F = Fatal=='
|
|
31
79
|
|
|
32
80
|
# Process and colorize output
|
|
33
81
|
processed_output = ''
|
|
@@ -54,26 +102,40 @@ module Rubosquad
|
|
|
54
102
|
end
|
|
55
103
|
end
|
|
56
104
|
|
|
57
|
-
|
|
105
|
+
Rails.logger.debug processed_output
|
|
58
106
|
|
|
59
107
|
if status.success?
|
|
60
|
-
|
|
108
|
+
Rails.logger.debug "\nRubocop auto-corrections complete."
|
|
61
109
|
else
|
|
62
|
-
|
|
110
|
+
Rails.logger.debug "\nRubocop completed with offenses:"
|
|
63
111
|
|
|
64
112
|
offenses = stdout.scan(/(\d+) offense.* detected/)
|
|
65
113
|
total_offenses = offenses.flatten.map(&:to_i).sum
|
|
66
114
|
|
|
67
|
-
|
|
68
|
-
|
|
115
|
+
Rails.logger.debug "Files inspected: #{stdout[/(\d+) files? inspected/, 1] || 'Unknown'}"
|
|
116
|
+
Rails.logger.debug "Total offenses detected: #{total_offenses}"
|
|
69
117
|
|
|
70
118
|
unless stderr.strip.empty?
|
|
71
|
-
|
|
72
|
-
|
|
119
|
+
Rails.logger.debug "\nStandard error:"
|
|
120
|
+
Rails.logger.debug stderr
|
|
73
121
|
end
|
|
74
122
|
end
|
|
75
123
|
|
|
76
|
-
|
|
124
|
+
Rails.logger.debug "\nRuboCop extensions used: #{available_extensions.join(', ')}"
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
# Detect the base branch to compare against
|
|
128
|
+
def self.detect_base_branch
|
|
129
|
+
# Try different possible base branch names
|
|
130
|
+
candidates = ['main', 'master', 'origin/main', 'origin/master']
|
|
131
|
+
|
|
132
|
+
candidates.each do |branch|
|
|
133
|
+
# Check if the branch exists
|
|
134
|
+
result = `git rev-parse --verify #{branch} 2>/dev/null`.strip
|
|
135
|
+
return branch unless result.empty?
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
nil
|
|
77
139
|
end
|
|
78
140
|
end
|
|
79
141
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rubosquad
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- LucasWaki
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2025-10-23 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rubocop
|
|
@@ -24,7 +24,8 @@ dependencies:
|
|
|
24
24
|
- - "~>"
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
26
|
version: '1.0'
|
|
27
|
-
description: A tool to run RuboCop on
|
|
27
|
+
description: A tool to run RuboCop with auto-correct on Ruby files changed in your
|
|
28
|
+
Git branch compared to main
|
|
28
29
|
email: lucas.waki@cloudwalk.io
|
|
29
30
|
executables:
|
|
30
31
|
- rubosquad
|
|
@@ -55,5 +56,5 @@ requirements: []
|
|
|
55
56
|
rubygems_version: 3.3.7
|
|
56
57
|
signing_key:
|
|
57
58
|
specification_version: 4
|
|
58
|
-
summary: Run RuboCop on changed files
|
|
59
|
+
summary: Run RuboCop on changed files in your branch/PR
|
|
59
60
|
test_files: []
|