abide_dev_utils 0.17.1 → 0.17.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ba0491c8fbcaa0a69015c410a2aa7e61ac61e6b30caca6fb5b334d22fd77069c
4
- data.tar.gz: 119c837a5ea897957e63744ec3f38a7567222d7dbb5b952302ec71cd70aafc24
3
+ metadata.gz: 69b32737c24844c999bd460d836d6eef7d87be94363c4b2ba277807042b646a5
4
+ data.tar.gz: a391723e49202b26efbf77b24e5ae65a4114889eb56c8c1428784d6da84be0b8
5
5
  SHA512:
6
- metadata.gz: 492066b562bee8dd3c3d3b465396a569d66a66200018bb74e606c8f3a78320853ecc71a8f30ee0c4f18194dbdc0d8679ff8c32fd38fbaf7936267eae1b35d5eb
7
- data.tar.gz: 2766d7c84c887b573cd9cb23f5d2aa869a4f238e5208ab2377832827e88d44056d180226a31c93ee242ed954d6aaf65b0e075d282b65ba53ea475ae1adb8e45a
6
+ metadata.gz: f30ad258bce39e8a9801440998ad6f4fd80caced6779f0836c288434539acb817e8d31e221cc143b2e5b431e193333d84f211cd47d18449a0d1d5abaa7be0811
7
+ data.tar.gz: adfeaa5dc2da9bb80f6da347115bf4f102387fd936763f0c7ac0a74e3c146b6d84e7a4c00b81bc32c6fad923871d86af8e609b8c346c2f18d7a57ad4a04ba019
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- abide_dev_utils (0.17.1)
4
+ abide_dev_utils (0.17.2)
5
5
  cmdparse (~> 3.0)
6
6
  facterdb (>= 1.21)
7
7
  google-cloud-storage (~> 1.34)
@@ -163,6 +163,11 @@ module Abide
163
163
  long_desc(CMD_LONG)
164
164
  argument_desc(PATH1: 'An XCCDF file', PATH2: 'An XCCDF file', PROJECT: 'A Jira project')
165
165
  options.on('-d', '--dry-run', 'Print to console instead of saving objects') { |_| @data[:dry_run] = true }
166
+ options.on('-z', '--print-only', 'Prints a list of issues that would be created. Implies dry-run, and auto-approve, but less verbose than --dry-run.') do
167
+ @data[:print_only] = true
168
+ @data[:dry_run] = true
169
+ @data[:auto_approve] = true
170
+ end
166
171
  options.on('-y', '--yes', 'Automatically approve all yes / no prompts') { |_| @data[:auto_approve] = true }
167
172
  options.on('-e [EPIC]', '--epic [EPIC]', 'If given, tasks will be created and assigned to this epic. Takes form <PROJECT>-<NUM>') { |e| @data[:epic] = e }
168
173
  options.on('-p [PROFILE]', '--profile', 'Only diff rules belonging to the matching profile. Takes a string that is treated as RegExp') do |x|
@@ -188,8 +193,9 @@ module Abide
188
193
  path2,
189
194
  epic: @data[:epic],
190
195
  dry_run: @data[:dry_run],
196
+ print_only: @data[:print_only],
191
197
  auto_approve: @data[:auto_approve],
192
- diff_opts: @data[:diff_opts],
198
+ diff_opts: @data[:diff_opts] || {},
193
199
  )
194
200
  end
195
201
  end
@@ -172,18 +172,18 @@ module AbideDevUtils
172
172
  exit(0)
173
173
  end
174
174
 
175
- def self.new_issues_from_xccdf_diff(project, xccdf1_path, xccdf2_path, epic: nil, dry_run: false, auto_approve: false, diff_opts: {})
175
+ def self.new_issues_from_xccdf_diff(project, xccdf1_path, xccdf2_path, epic: nil, dry_run: false, print_only: false, auto_approve: false, diff_opts: {})
176
176
  require 'abide_dev_utils/xccdf/diff'
177
177
  diff = AbideDevUtils::XCCDF::Diff::BenchmarkDiff.new(xccdf1_path, xccdf2_path, diff_opts)
178
178
  client(dry_run: dry_run) # Initializes the client if needed
179
179
  i_attrs = client.helper.all_project_issues_attrs(project)
180
180
  # We need to get the actual epic Issue object, or create it if it doesn't exist
181
181
  epic = if epic.nil?
182
- new_epic_summary = "#{COV_PARENT_SUMMARY_PREFIX}#{xccdf.title}"
182
+ new_epic_summary = "#{COV_PARENT_SUMMARY_PREFIX}#{diff.this.title}: #{diff.this.version} -> #{diff.other.version}"
183
183
  if client.helper.summary_exist?(new_epic_summary, i_attrs)
184
184
  client.find(:issue, new_epic_summary)
185
185
  else
186
- unless AbideDevUtils::Prompt.yes_no("#{dr_prefix(dry_run)}Create new epic '#{new_epic_summary}'?")
186
+ unless AbideDevUtils::Prompt.yes_no("#{dr_prefix(dry_run)}Create new epic '#{new_epic_summary}'?", auto_approve: auto_approve)
187
187
  AbideDevUtils::Output.simple("#{dr_prefix(dry_run)}Aborting")
188
188
  exit(0)
189
189
  end
@@ -202,30 +202,57 @@ module AbideDevUtils
202
202
  sum = "Add rule #{v[:number]} - #{v[:title]}"
203
203
  sum = "#{sum[0..60]}..." if sum.length > 60
204
204
  to_create[sum] = <<~DESC
205
- Rule #{v[:number]} - #{v[:title]} is added with #{diff.other.title} #{diff.other.version}
205
+ Rule #{v[:number]} - #{v[:title]} is added
206
+
207
+ * From:
208
+ * Benchmark: #{diff.this.title} #{diff.this.version}
209
+ * To:
210
+ * Benchmark: #{diff.other.title} #{diff.other.version}
206
211
  DESC
207
212
  when :removed
208
213
  sum = "Remove rule #{v[:number]} - #{v[:title]}"
209
214
  sum = "#{sum[0..60]}..." if sum.length > 60
210
215
  to_create[sum] = <<~DESC
211
- Rule #{v[:number]} - #{v[:title]} is removed from #{diff.this.title} #{diff.this.version}
216
+ Remove rule #{v[:number]} - #{v[:title]}
217
+
218
+ * From:
219
+ * Benchmark: #{diff.this.title} #{diff.this.version}
220
+ * To:
221
+ * Benchmark: #{diff.other.title} #{diff.other.version}
212
222
  DESC
213
223
  else
214
- sum = "Update rule \"#{v[:from]}\""
224
+ sum = "Changed rule \"#{v[:from]}\""
215
225
  sum = "#{sum[0..60]}..." if sum.length > 60
216
226
  to_create[sum] = <<~DESC
217
- Rule #{v[:from]} is updated in #{diff.other.title} #{diff.other.version}:
218
- #{v[:changes].collect { |k, v| "#{k}: #{v}" }.join("\n")}
227
+ #{v[:changes].collect { |ck, cv| "Property \"#{ck}\" changed: \"#{cv.last}\" changed to \"#{cv.first}\"" }.join("\n ")}
228
+
229
+ * From:
230
+ * Rule: #{v[:from]}
231
+ * Benchmark: #{diff.this.title} #{diff.this.version}
232
+ * To:
233
+ * Rule: #{v[:to]}
234
+ * Benchmark: #{diff.other.title} #{diff.other.version}
219
235
  DESC
220
236
  end
221
237
  end
222
238
  end
223
239
  approved_create = {}
224
240
  to_create.each do |summary, description|
225
- if AbideDevUtils::Prompt.yes_no("#{dr_prefix(dry_run)}Create new issue '#{summary}' with description:\n#{description}", auto_approve: auto_approve)
241
+ section_header = "#{dr_prefix(dry_run)}NEW ISSUE"
242
+ prompt_msg = <<~PROMPT
243
+ #{AbideDevUtils::Output.simple_section_separator(section_header, width: 90)}
244
+ Title: '#{summary}'
245
+ Description:
246
+ #{description}
247
+ PROMPT
248
+ if print_only
249
+ AbideDevUtils::Output.simple(prompt_msg)
250
+ elsif AbideDevUtils::Prompt.yes_no("#{prompt_msg.strip}\nCreate?", auto_approve: auto_approve)
226
251
  approved_create[summary] = description
227
252
  end
228
253
  end
254
+ return if approved_create.empty?
255
+
229
256
  AbideDevUtils::Output.simple("#{dr_prefix(dry_run)}Creating #{approved_create.keys.count} new Jira issues")
230
257
  progress = AbideDevUtils::Output.progress(title: "#{dr_prefix(dry_run)}Creating issues",
231
258
  total: approved_create.keys.count,
@@ -27,6 +27,10 @@ module AbideDevUtils
27
27
  end
28
28
  end
29
29
 
30
+ def self.print(msg, stream: $stdout, **_)
31
+ stream.print msg
32
+ end
33
+
30
34
  def self.text(msg, console: false, file: nil, **_)
31
35
  simple(msg) if console
32
36
  FWRITER.write_text(msg, file: file) unless file.nil?
@@ -1,25 +1,30 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'io/console'
4
+ require_relative 'output'
4
5
 
5
6
  module AbideDevUtils
6
7
  module Prompt
7
- def self.yes_no(msg, auto_approve: false)
8
- return true if auto_approve
9
-
10
- print "#{msg} (Y/n): "
8
+ def self.yes_no(msg, auto_approve: false, stream: $stdout)
9
+ prompt_msg = "#{msg} (Y/n): "
10
+ if auto_approve
11
+ AbideDevUtils::Output.simple("#{prompt_msg}Y", stream: stream)
12
+ return true
13
+ end
14
+
15
+ AbideDevUtils::Output.print(prompt_msg, stream: stream)
11
16
  return true if $stdin.cooked(&:gets).match?(/^[Yy].*/)
12
17
 
13
18
  false
14
19
  end
15
20
 
16
- def self.single_line(msg)
17
- print "#{msg}: "
21
+ def self.single_line(msg, stream: $stdout)
22
+ AbideDevUtils::Output.print("#{msg}: ", stream: stream)
18
23
  $stdin.cooked(&:gets).chomp
19
24
  end
20
25
 
21
- def self.username
22
- print 'Username: '
26
+ def self.username(stream: $stdout)
27
+ AbideDevUtils::Output.print('Username: ', stream: stream)
23
28
  $stdin.cooked(&:gets).chomp
24
29
  end
25
30
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AbideDevUtils
4
- VERSION = "0.17.1"
4
+ VERSION = "0.17.2"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: abide_dev_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.17.1
4
+ version: 0.17.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - abide-team
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-11-03 00:00:00.000000000 Z
11
+ date: 2023-11-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -469,7 +469,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
469
469
  - !ruby/object:Gem::Version
470
470
  version: '0'
471
471
  requirements: []
472
- rubygems_version: 3.4.18
472
+ rubygems_version: 3.4.22
473
473
  signing_key:
474
474
  specification_version: 4
475
475
  summary: Helper utilities for developing compliance Puppet code