nucop 0.8.0 → 0.9.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/nucop/cli.rb +86 -1
- data/lib/nucop/version.rb +1 -1
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 40456b1522f92b7bf6e329fbfea17e7f791d1ab2ae60a9cefe3bd227001b748b
|
4
|
+
data.tar.gz: 15c67e8bfacd08cf148832fa0780f5248955c3f0592584e241f7325560898d50
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '068244795d6dbe1fae94fddfca5185e80ca4fcdc6ad0516c66fc5d158329e4ade87c781e0d760cdb8832accec568e97d957c815634b135d5cec6c72e65d83fd6'
|
7
|
+
data.tar.gz: cf40ddb5ccda40eaf4ba112702d3d1f10fe7dc3a113166a10152876483dbe625169393d43638d33bd0b3e43424479e26ad0b160583e2b1dfcf104bb202c6bc8b
|
data/lib/nucop/cli.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
require "thor"
|
2
2
|
require "open3"
|
3
|
+
require "net/http"
|
4
|
+
require "json"
|
3
5
|
|
4
6
|
RUBOCOP_DEFAULT_CONFIG_FILE = ".rubocop.yml"
|
5
7
|
CONFIGURATION_FILEPATH = ".nucop.yml"
|
@@ -17,6 +19,18 @@ module Nucop
|
|
17
19
|
invoke :diff, nil, options.merge(only: cops_to_enforce.join(","))
|
18
20
|
end
|
19
21
|
|
22
|
+
desc "diff_enforced_github", "run RuboCop on the current diff using only the enforced cops (using GitHub to find the files changed)"
|
23
|
+
method_option "github-authorization-token", desc: "a GitHub authorization token for the repository this script is running against"
|
24
|
+
method_option "commit-spec", default: "main", desc: "the commit-ish used to determine the diff."
|
25
|
+
method_option "auto-correct", type: :boolean, default: false, desc: "runs RuboCop with auto-correct option (deprecated)"
|
26
|
+
method_option "autocorrect", type: :boolean, default: false, desc: "runs RuboCop with autocorrect option"
|
27
|
+
method_option "autocorrect-all", type: :boolean, default: false, desc: "runs RuboCop with autocorrect-all option"
|
28
|
+
method_option "junit_report", type: :string, default: nil, desc: "runs RuboCop with junit formatter option"
|
29
|
+
method_option "json", type: :string, default: nil, desc: "Output results as JSON format to the provided file"
|
30
|
+
def diff_enforced_github
|
31
|
+
invoke :diff_github, nil, options.merge(only: cops_to_enforce.join(","))
|
32
|
+
end
|
33
|
+
|
20
34
|
desc "diff", "run RuboCop on the current diff"
|
21
35
|
method_option "commit-spec", default: "origin/main", desc: "the commit used to determine the diff."
|
22
36
|
method_option "only", desc: "run only specified cop(s) and/or cops in the specified departments"
|
@@ -43,7 +57,7 @@ module Nucop
|
|
43
57
|
end
|
44
58
|
end
|
45
59
|
|
46
|
-
if options[:ignore] && File.exist?(options[:diffignore_file]) && !File.
|
60
|
+
if options[:ignore] && File.exist?(options[:diffignore_file]) && !File.empty?(options[:diffignore_file])
|
47
61
|
files, non_ignored_diff_status = Open3.capture2("grep -v -f #{options[:diffignore_file]}", stdin_data: files)
|
48
62
|
|
49
63
|
if non_ignored_diff_status != 0
|
@@ -64,6 +78,77 @@ module Nucop
|
|
64
78
|
exit 0
|
65
79
|
end
|
66
80
|
|
81
|
+
desc "diff_github", "run RuboCop on the current diff (using GitHub to find the files changes)"
|
82
|
+
method_option "github-authorization-token", desc: "a GitHub authorization token for the repository this script is running against"
|
83
|
+
method_option "commit-spec", default: "main", desc: "the commit-ish used to determine the diff."
|
84
|
+
method_option "only", desc: "run only specified cop(s) and/or cops in the specified departments"
|
85
|
+
method_option "auto-correct", type: :boolean, default: false, desc: "runs RuboCop with auto-correct option (deprecated)"
|
86
|
+
method_option "autocorrect", type: :boolean, default: false, desc: "runs RuboCop with autocorrect option"
|
87
|
+
method_option "autocorrect-all", type: :boolean, default: false, desc: "runs RuboCop with autocorrect-all option"
|
88
|
+
method_option "ignore", type: :boolean, default: true, desc: "ignores files specified in #{options[:diffignore_file]}"
|
89
|
+
method_option "added-only", type: :boolean, default: false, desc: "runs RuboCop only on files that have been added (not on files that have been modified)"
|
90
|
+
method_option "exit", type: :boolean, default: true, desc: "disable to prevent task from exiting. Used by other Thor tasks when invoking this task, to prevent parent task from exiting"
|
91
|
+
def diff_github
|
92
|
+
puts "Running on files changed relative to '#{options[:"commit-spec"]}' (specify using the 'commit-spec' option)"
|
93
|
+
diff_head = capture_std_out("git rev-parse HEAD").chomp
|
94
|
+
diff_base = options[:"commit-spec"]
|
95
|
+
repository = capture_std_out("git remote get-url origin | sed 's/git@github.com://; s/.git//'").chomp
|
96
|
+
|
97
|
+
uri = URI("https://api.github.com/repos/#{repository}/compare/#{diff_base}...#{diff_head}")
|
98
|
+
request = Net::HTTP::Get.new(uri)
|
99
|
+
request["Accept"] = "application/vnd.github+json"
|
100
|
+
request["Authorization"] = "Bearer #{options[:"github-authorization-token"]}"
|
101
|
+
request["X-GitHub-Api-Version"] = "2022-11-28"
|
102
|
+
|
103
|
+
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) { |http| http.request(request) }
|
104
|
+
|
105
|
+
if response.code != "200"
|
106
|
+
puts "Error fetching data from Github: #{response.code} -- #{response.body}"
|
107
|
+
return true unless options[:exit]
|
108
|
+
|
109
|
+
exit 0
|
110
|
+
end
|
111
|
+
|
112
|
+
commit_data = JSON.parse(response.body)
|
113
|
+
|
114
|
+
diff_filter = options[:"added-only"] ? proc { |status| status == "added" } : proc { |status| status != "removed" }
|
115
|
+
files = commit_data["files"]
|
116
|
+
.filter { |file_data| diff_filter.call(file_data["status"]) }
|
117
|
+
.pluck("filename")
|
118
|
+
.filter { |file_name| file_name.include?(".rb") }
|
119
|
+
|
120
|
+
if files.empty?
|
121
|
+
if options[:exit]
|
122
|
+
puts "There are no rb files present in diff. Exiting."
|
123
|
+
exit 0
|
124
|
+
else
|
125
|
+
puts "There are no rb files present in diff."
|
126
|
+
return true
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
if options[:ignore] && File.exist?(options[:diffignore_file]) && !File.empty?(options[:diffignore_file])
|
131
|
+
files, non_ignored_diff_status = Open3.capture2("grep -v -f #{options[:diffignore_file]}", stdin_data: files.join("\n"))
|
132
|
+
|
133
|
+
if non_ignored_diff_status != 0
|
134
|
+
if options[:exit]
|
135
|
+
puts "There are no non-ignored rb files present in diff. Exiting."
|
136
|
+
exit 0
|
137
|
+
else
|
138
|
+
puts "There are no non-ignored rb files present in diff."
|
139
|
+
return true
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
no_violations_detected = invoke :rubocop, [multi_line_to_single_line(files)], options
|
145
|
+
|
146
|
+
exit 1 unless no_violations_detected
|
147
|
+
return true unless options[:exit]
|
148
|
+
|
149
|
+
exit 0
|
150
|
+
end
|
151
|
+
|
67
152
|
desc "rubocop", "run RuboCop on files provided"
|
68
153
|
method_option "only", desc: "run only specified cop(s) and/or cops in the specified departments"
|
69
154
|
method_option "auto-correct", type: :boolean, default: false, desc: "runs RuboCop with auto-correct option (deprecated)"
|
data/lib/nucop/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nucop
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Schweier
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-04-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: git_diff_parser
|
@@ -178,7 +178,7 @@ dependencies:
|
|
178
178
|
- - "~>"
|
179
179
|
- !ruby/object:Gem::Version
|
180
180
|
version: '3.12'
|
181
|
-
description:
|
181
|
+
description:
|
182
182
|
email:
|
183
183
|
- jasons@nulogy.com
|
184
184
|
executables:
|
@@ -211,7 +211,7 @@ metadata:
|
|
211
211
|
changelog_uri: https://github.com/nulogy/nucop/blob/master/CHANGELOG.md
|
212
212
|
source_code_uri: https://github.com/nulogy/nucop
|
213
213
|
bug_tracker_uri: https://github.com/nulogy/nucop/issues
|
214
|
-
post_install_message:
|
214
|
+
post_install_message:
|
215
215
|
rdoc_options: []
|
216
216
|
require_paths:
|
217
217
|
- lib
|
@@ -226,8 +226,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
226
226
|
- !ruby/object:Gem::Version
|
227
227
|
version: '0'
|
228
228
|
requirements: []
|
229
|
-
rubygems_version: 3.4.
|
230
|
-
signing_key:
|
229
|
+
rubygems_version: 3.4.7
|
230
|
+
signing_key:
|
231
231
|
specification_version: 4
|
232
232
|
summary: Nulogy's implementation of RuboCop, including custom cops and additional
|
233
233
|
tooling.
|