tefoji 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/tefoji/cli.rb +1 -1
  3. data/lib/tefoji.rb +26 -20
  4. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b048f1a4325a22d2fa736626f148827792639424d448ccc0d5a09250e250bdfa
4
- data.tar.gz: 8350c3e8d0fdf3ad2ecfdf922ef654b37ddd86f9e44b4358cc713bf54cb462b8
3
+ metadata.gz: 427d2dac516388b9bfe1db4ce55a164621c0530d30a9a79ce322fe098372d3a4
4
+ data.tar.gz: 756adc133f20f25d43f422149df86e17c685a741c10801150092ffd633265bf6
5
5
  SHA512:
6
- metadata.gz: fd6187add4fe25d2ea7ebcc3aadc8346cfbfeae133e1fc4c366dad99395cfcbddd0aa6c024caa9f86676651037dcacdf0f1092a98ab0a2d1cc74a9033ab7dd7c
7
- data.tar.gz: 2d5fe6518a6a174aeb033e006fa92b168f5115bb4526cb7dbbce2b177ac185bb79b795fcf7e43e86e63f063150bb5e5e6ad2fee28f17251010bbe2d319efd4c7
6
+ metadata.gz: 42c08df5f8727ad1b052b780478d1f66022a35eb2148001f5576eb41874a6334028a91552f02729d526ff96b9c1774606c8cbdc8666e2f83289ae9663ff8ab01
7
+ data.tar.gz: 1eb096e1869ae3bcedfebb77aacd69b4241d9f0062625850cbd8b1f3ecc4b04325c8e12eaa114ad6083f084b65e59029e46e26cfe0628f31543f049a01730483
data/lib/tefoji/cli.rb CHANGED
@@ -6,7 +6,7 @@ require 'yaml'
6
6
  module Tefoji
7
7
  class CLI
8
8
  DEFAULT_JIRA_URL = 'https://tickets.puppetlabs.com'
9
- JIRA_TEST_URL = 'https://jira-app-test-1.ops.puppetlabs.net/'
9
+ JIRA_TEST_URL = 'https://jira-app-test-1.ops.puppetlabs.net'
10
10
  DEFAULT_JIRA_AUTH_FILE = "#{ENV['HOME']}/.tefoji-auth.yaml"
11
11
  JIRA_CLOUD_URLS = [
12
12
  'https://puppet.atlassian.net'
data/lib/tefoji.rb CHANGED
@@ -18,6 +18,8 @@ module Tefoji
18
18
  include Logging
19
19
  include UserFunctions
20
20
 
21
+ attr_accessor :template_data, :jira_api
22
+
21
23
  # @param [Hash] user_options options provided by the user through the CLI.
22
24
  # @see CLI
23
25
  def initialize(user_options = {}, log_location = $stderr)
@@ -41,6 +43,7 @@ module Tefoji
41
43
  @feature_issue = nil
42
44
  @default_target_epic = nil
43
45
  @epic_security = nil
46
+ @deferral_data = {}
44
47
 
45
48
  # Logging
46
49
  @log_level = Logger::INFO
@@ -282,8 +285,6 @@ module Tefoji
282
285
  @jira_api.save_authentication(@jira_auth_file, @jira_cloud)
283
286
  end
284
287
 
285
- private
286
-
287
288
  # Generate a feature, a list of epics, and associated issues
288
289
  def generate_feature_with_issues
289
290
  @feature_issue = generate_feature
@@ -300,7 +301,13 @@ module Tefoji
300
301
  feature = variable_substitute(feature_to_do)
301
302
  feature['type'] = JiraApi::ISSUE_NEW_FEATURE
302
303
 
304
+ short_name = feature['short_name'] || feature['summary']
305
+
303
306
  @feature_issue = @jira_api.create_issue(feature, @jira_cloud)
307
+ @deferral_data[short_name.to_s] = {
308
+ 'jira' => @feature_issue,
309
+ 'raw' => feature
310
+ }
304
311
  @logger.info "Feature issue: #{@feature_issue['key']}"
305
312
  @feature_issue
306
313
  end
@@ -366,6 +373,10 @@ module Tefoji
366
373
  epic_issue['short_name'] = short_name
367
374
  @logger.info 'Epic: %16s [%s]' % [epic_issue['key'], short_name]
368
375
  @jira_api.link_issues(@feature_issue['key'], epic_issue['key']) if @feature_issue
376
+ @deferral_data[short_name.to_s] = {
377
+ 'jira' => epic_issue,
378
+ 'raw' => epic
379
+ }
369
380
  epic_issue
370
381
  end
371
382
  end
@@ -385,10 +396,6 @@ module Tefoji
385
396
  # Iterate through all issues in the template, creating each one in Jira.
386
397
  # Link the issues back to their epic, if required
387
398
  def generate_ordinary_issues
388
- # Need to keep a map of tefoji data and associated responses from Jira to perform
389
- # deferred updates, like blocked_by or watchers
390
- deferral_data = {}
391
-
392
399
  issue_defaults = {}
393
400
  if @template_data.key?('issue_defaults')
394
401
  issue_defaults = variable_substitute(@template_data['issue_defaults'])
@@ -417,12 +424,12 @@ module Tefoji
417
424
 
418
425
  # deferral_data is kept to match the jira raw request data to the jira response data.
419
426
  # This is needed so that deferred actions (like 'blocked_by') can be correctly mapped.
420
- deferral_data[raw_issue_data['short_name'].to_s] = {
427
+ @deferral_data[raw_issue_data['short_name'].to_s] = {
421
428
  'jira' => jira_issue,
422
429
  'raw' => raw_issue_data
423
430
  }
424
431
  end
425
- process_deferred_updates(deferral_data)
432
+ process_deferred_updates
426
433
  end
427
434
 
428
435
  # Transform the tefoji issue data and tefoji issue_defaults into a hash that is ready to
@@ -538,16 +545,16 @@ module Tefoji
538
545
  #
539
546
  # @param deferral_data [Hash] raw template and jira response data
540
547
  # @see generate_ordinary_issues
541
- def process_deferred_updates(deferral_data)
548
+ def process_deferred_updates
542
549
  ## Find deferred tags in the jira_epic_issues and do the required work
543
550
  deferred_tags.each do |deferred_tag|
544
551
  case deferred_tag
545
552
  when 'blocked_by'
546
- process_blocked_by(deferral_data)
553
+ process_blocked_by
547
554
  when 'status'
548
- process_status(deferral_data)
555
+ process_status
549
556
  when 'watchers'
550
- process_watchers(deferral_data)
557
+ process_watchers
551
558
  else
552
559
  raise "Unimplemented deferred_tag: #{deferred_tag}"
553
560
  end
@@ -557,10 +564,10 @@ module Tefoji
557
564
  ## The process_* methods have repeated code. This could be cleaned up
558
565
  ## with some well-thought-through functional techniques. Since the list
559
566
  ## of methods is short, I'll pass on that for now.
560
- def process_blocked_by(deferral_data)
567
+ def process_blocked_by
561
568
  deferred_tag = 'blocked_by'
562
569
 
563
- deferral_data.each_value do |deferral_hash|
570
+ @deferral_data.each_value do |deferral_hash|
564
571
  raw_issue_data = deferral_hash['raw']
565
572
  jira_issue_data = deferral_hash['jira']
566
573
  next unless raw_issue_data.key?(deferred_tag)
@@ -568,10 +575,9 @@ module Tefoji
568
575
  target_issues = [raw_issue_data[deferred_tag].value].flatten
569
576
  target_issues.each do |target_issue_name|
570
577
  this_issue_key = jira_issue_data['key']
571
-
572
578
  # If we skipped creating the target issue because of a 'conditional',
573
579
  # don't try to link to it.
574
- target_issue_key = deferral_data.dig(target_issue_name, 'jira', 'key')
580
+ target_issue_key = @deferral_data.dig(target_issue_name, 'jira', 'key')
575
581
  next if target_issue_key.nil?
576
582
 
577
583
  @jira_api.link_issues(target_issue_key, this_issue_key)
@@ -580,10 +586,10 @@ module Tefoji
580
586
  end
581
587
  end
582
588
 
583
- def process_status(deferral_data)
589
+ def process_status
584
590
  deferred_tag = 'status'
585
591
 
586
- deferral_data.each_value do |deferral_hash|
592
+ @deferral_data.each_value do |deferral_hash|
587
593
  raw_issue_data = deferral_hash['raw']
588
594
  jira_issue_data = deferral_hash['jira']
589
595
  next unless raw_issue_data.key?(deferred_tag)
@@ -600,10 +606,10 @@ module Tefoji
600
606
  end
601
607
  end
602
608
 
603
- def process_watchers(deferral_data)
609
+ def process_watchers
604
610
  deferred_tag = 'watchers'
605
611
 
606
- deferral_data.each_value do |deferral_hash|
612
+ @deferral_data.each_value do |deferral_hash|
607
613
  raw_issue_data = deferral_hash['raw']
608
614
  jira_issue_data = deferral_hash['jira']
609
615
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tefoji
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Puppet Labs
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-05-17 00:00:00.000000000 Z
11
+ date: 2023-06-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry-byebug
@@ -196,7 +196,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
196
196
  requirements:
197
197
  - - ">="
198
198
  - !ruby/object:Gem::Version
199
- version: 2.6.0
199
+ version: 2.7.0
200
200
  required_rubygems_version: !ruby/object:Gem::Requirement
201
201
  requirements:
202
202
  - - ">="