nucop 0.7.0 → 0.9.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: 30002f7a5d17b3853feacf67687280bf3367a54ac9cb897cba41e239623eea8b
4
- data.tar.gz: 1c35996b84674d981b12029e80280b344d14582ad8b4e0a879b3209bd35367ea
3
+ metadata.gz: 40456b1522f92b7bf6e329fbfea17e7f791d1ab2ae60a9cefe3bd227001b748b
4
+ data.tar.gz: 15c67e8bfacd08cf148832fa0780f5248955c3f0592584e241f7325560898d50
5
5
  SHA512:
6
- metadata.gz: 9dbab800cda4dd3918162d6e29669467dca2f00a7c01d89a0ba63324452fa936d391fbc0467c968e8dd8134c44f2ee61b9a79d3ab09982beb970a4f8448f2adf
7
- data.tar.gz: 6c196e24daf8a46dd5669147aa4a413ffdd8f56bc5652e3e666c9a001d8908d5a3ad6759cb8d0e30edaaca5923599107255d0b720e0720f5a3b847edf32f70bd
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"
@@ -8,17 +10,33 @@ module Nucop
8
10
  class Cli < Thor
9
11
  desc "diff_enforced", "run RuboCop on the current diff using only the enforced cops"
10
12
  method_option "commit-spec", default: "origin/main", desc: "the commit used to determine the diff."
11
- method_option "auto-correct", type: :boolean, default: false, desc: "runs RuboCop with auto-correct option"
13
+ method_option "auto-correct", type: :boolean, default: false, desc: "runs RuboCop with auto-correct option (deprecated)"
14
+ method_option "autocorrect", type: :boolean, default: false, desc: "runs RuboCop with autocorrect option"
15
+ method_option "autocorrect-all", type: :boolean, default: false, desc: "runs RuboCop with autocorrect-all option"
12
16
  method_option "junit_report", type: :string, default: nil, desc: "runs RuboCop with junit formatter option"
13
17
  method_option "json", type: :string, default: nil, desc: "Output results as JSON format to the provided file"
14
18
  def diff_enforced
15
19
  invoke :diff, nil, options.merge(only: cops_to_enforce.join(","))
16
20
  end
17
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
+
18
34
  desc "diff", "run RuboCop on the current diff"
19
35
  method_option "commit-spec", default: "origin/main", desc: "the commit used to determine the diff."
20
36
  method_option "only", desc: "run only specified cop(s) and/or cops in the specified departments"
21
- method_option "auto-correct", type: :boolean, default: false, desc: "runs RuboCop with auto-correct option"
37
+ method_option "auto-correct", type: :boolean, default: false, desc: "runs RuboCop with auto-correct option (deprecated)"
38
+ method_option "autocorrect", type: :boolean, default: false, desc: "runs RuboCop with autocorrect option"
39
+ method_option "autocorrect-all", type: :boolean, default: false, desc: "runs RuboCop with autocorrect-all option"
22
40
  method_option "ignore", type: :boolean, default: true, desc: "ignores files specified in #{options[:diffignore_file]}"
23
41
  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)"
24
42
  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"
@@ -39,7 +57,7 @@ module Nucop
39
57
  end
40
58
  end
41
59
 
42
- if options[:ignore] && File.exist?(options[:diffignore_file]) && !File.zero?(options[:diffignore_file])
60
+ if options[:ignore] && File.exist?(options[:diffignore_file]) && !File.empty?(options[:diffignore_file])
43
61
  files, non_ignored_diff_status = Open3.capture2("grep -v -f #{options[:diffignore_file]}", stdin_data: files)
44
62
 
45
63
  if non_ignored_diff_status != 0
@@ -60,9 +78,82 @@ module Nucop
60
78
  exit 0
61
79
  end
62
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
+
63
152
  desc "rubocop", "run RuboCop on files provided"
64
153
  method_option "only", desc: "run only specified cop(s) and/or cops in the specified departments"
65
- method_option "auto-correct", type: :boolean, default: false, desc: "runs RuboCop with auto-correct option"
154
+ method_option "auto-correct", type: :boolean, default: false, desc: "runs RuboCop with auto-correct option (deprecated)"
155
+ method_option "autocorrect", type: :boolean, default: false, desc: "runs RuboCop with autocorrect option"
156
+ method_option "autocorrect-all", type: :boolean, default: false, desc: "runs RuboCop with autocorrect-all option"
66
157
  method_option "exclude-backlog", type: :boolean, default: false, desc: "when true, uses config which excludes violations in the RuboCop backlog"
67
158
  def rubocop(files = nil)
68
159
  print_cops_being_run(options[:only])
@@ -86,6 +177,8 @@ module Nucop
86
177
  "--force-exclusion",
87
178
  "--config", config_file,
88
179
  pass_through_option(options, "auto-correct"),
180
+ pass_through_option(options, "autocorrect"),
181
+ pass_through_option(options, "autocorrect-all"),
89
182
  pass_through_flag(options, "only"),
90
183
  files
91
184
  ].join(" ")
data/lib/nucop/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Nucop
2
- VERSION = "0.7.0"
2
+ VERSION = "0.9.0"
3
3
  end
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.7.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-02-27 00:00:00.000000000 Z
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.6
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.