tefoji 3.1.0 → 3.2.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: f21e85163dfc8f1b659b53e940406ad91008dad1f0f1d3244418ff67541f89a0
4
- data.tar.gz: b8f8c785e16325f553a62b11bfe92ff5ba9164a37f6045f2468ebfb68152b569
3
+ metadata.gz: 5b78e2ac6210a1adbd94b8ab0613522a8dbf024dccd1ff3e99321a554c7d7ba6
4
+ data.tar.gz: 9aacc9f1a3735955f4b67cd4a804c379b3dfbd8e965fe8a27bca67c9d85ca2d6
5
5
  SHA512:
6
- metadata.gz: da84a77b06069df84270a4a15b3e9d2b7ad851246f25200e147443c8e14b163fb988a386ac0e117f44f3c0a896689baa40b122ad9ef12d0eeec3cee522fb2365
7
- data.tar.gz: 98bfb1f2e0478a2598e892ed656ab5605052b22b146a637bbb18c2b0ad16c7b4b389b1a818cb0c01a157843798b5dec3e2142ef687e3991dc4ebd5dd11427b4b
6
+ metadata.gz: e0522340f64d64008d536b3bd593a230c993b45097b846b9272b73f6e1b592dc56b420026f10b6c7294c3e597f21f411743ca3f330135a6465c6d9f107d7b7dc
7
+ data.tar.gz: 457ca87866b1620062a968df3a0e733c40eb57402fec66848c0e243da51d8dc0da2888d3f7d0842f255c2d1fcbb0668cfefecfc295ae629977d8e1e541ed69ef
@@ -19,7 +19,6 @@ module UserFunctions
19
19
  default
20
20
  jira_project
21
21
  jira_sprint
22
- jira_status
23
22
  jira_team
24
23
  jira_user
25
24
  n_digit_version
@@ -73,21 +72,6 @@ module UserFunctions
73
72
  }
74
73
  end
75
74
 
76
- def jira_statuses
77
- # READY_FOR_ENGINEERING deprecated and translated to ACCEPTED
78
- {
79
- ACCEPTED: 11,
80
- READY_FOR_ENGINEERING: 11,
81
- ON_HOLD: 21,
82
- UNDER_INVESTIGATION: 31,
83
- TESTING: 41,
84
- IN_PROGRESS: 51,
85
- IN_REVIEW: 61,
86
- CLOSED: 71,
87
- CANCELED: 81
88
- }
89
- end
90
-
91
75
  def jira_teams
92
76
  {
93
77
  BOLT: 'Bolt',
@@ -114,10 +98,9 @@ module UserFunctions
114
98
 
115
99
  projects = jira_projects.transform_keys { |k| "#{k.downcase}_project".to_sym }
116
100
  sprints = jira_sprints.transform_keys { |k| "#{k.downcase}_sprint".to_sym }
117
- statuses = jira_statuses.transform_keys { |k| "#{k.downcase}_status".to_sym }
118
101
  teams = jira_teams.transform_keys { |k| "#{k.downcase}_team".to_sym }
119
102
 
120
- variables.merge(**projects, **sprints, **statuses, **teams)
103
+ variables.merge(**projects, **sprints, **teams)
121
104
  end
122
105
 
123
106
  # Takes at least two arguments.
@@ -184,10 +167,6 @@ module UserFunctions
184
167
  _jira_key('sprint', jira_sprints, args[0])
185
168
  end
186
169
 
187
- def jira_status(args)
188
- _jira_key('status', jira_statuses, args[0])
189
- end
190
-
191
170
  def jira_team(args)
192
171
  _jira_key('team', jira_teams, args[0])
193
172
  end
@@ -204,6 +204,31 @@ module Tefoji
204
204
  fatal "Jira account ID not found for #{account_name}"
205
205
  end
206
206
 
207
+ def get_transition_id(issue_key, status)
208
+ transitions_request_path = "issue/#{issue_key}/transitions"
209
+ response = jira_get(transitions_request_path)
210
+
211
+ fatal "Transitions data not found for issue: \"#{issue_key}\"" if response.empty?
212
+
213
+ downcased_status = status.downcase
214
+
215
+ transitions_data = response['transitions']
216
+ transition = transitions_data.find { |transition_data| transition_data['name'].downcase == downcased_status }
217
+
218
+ if transition.nil?
219
+ warn "No transition ID found for issue: \"#{issue_key}\" status: \"#{status}\"\n \
220
+ available transitions: #{transitions_data}"
221
+ return nil
222
+ end
223
+
224
+ transition_id = transition['id']
225
+
226
+ @logger.debug("issue: \"#{issue_key}\" status: \"#{status}\"" \
227
+ "converted to transition ID: \"#{transition_id}\"")
228
+
229
+ return transition_id.to_i
230
+ end
231
+
207
232
  private
208
233
 
209
234
  ## BUG BUG 'type' should ALWAYS be defined but we have a number of assumptions in
@@ -403,12 +428,6 @@ module Tefoji
403
428
  if issue_data['sprint']
404
429
  jira_fields['customfield_10020'] = issue_data['sprint'].to_i
405
430
  end
406
- if issue_data['acceptance']
407
- jira_fields['customfield_10062'] = issue_data['acceptance']
408
- end
409
- if issue_data['release_notes']
410
- jira_fields['customfield_10043'] = { FIELD_VALUE => issue_data['release_notes'] }
411
- end
412
431
 
413
432
  # If a issue has a specified parent issue, prefer that. The parent issue *should* already
414
433
  # be linked to the main epic. Otherwise, we need to set it to have an epic_parent. This can
data/lib/tefoji.rb CHANGED
@@ -42,6 +42,7 @@ module Tefoji
42
42
  @default_target_epic = nil
43
43
  @epic_security = nil
44
44
  @deferral_data = {}
45
+ @transitions_table = {}
45
46
 
46
47
  # Logging
47
48
  @log_level = Logger::INFO
@@ -374,15 +375,17 @@ module Tefoji
374
375
 
375
376
  @template_data['issues'].each do |issue|
376
377
  jira_ready_data, raw_issue_data = prepare_jira_ready_data(issue, issue_defaults)
378
+
377
379
  next if jira_ready_data.nil? || raw_issue_data.nil?
378
380
 
379
381
  response_data = @jira_api.create_issue(jira_ready_data)
380
382
  jira_issue = @jira_api.retrieve_issue(response_data['self'])
381
383
  jira_issue['short_name'] = raw_issue_data['short_name']
384
+ issue_key = jira_issue['key']
382
385
 
383
386
  @logger.info 'Issue %4d: %10s [%s]' % [
384
387
  @issue_counter,
385
- jira_issue['key'],
388
+ issue_key,
386
389
  jira_issue['fields']['summary']
387
390
  ]
388
391
  @issue_counter += 1
@@ -395,6 +398,11 @@ module Tefoji
395
398
  'jira' => jira_issue,
396
399
  'raw' => raw_issue_data
397
400
  }
401
+
402
+ next unless raw_issue_data.key?('status')
403
+
404
+ status = raw_issue_data['status'].value
405
+ @transitions_table[issue_key] = @jira_api.get_transition_id(issue_key, status)
398
406
  end
399
407
  process_deferred_updates
400
408
  end
@@ -562,14 +570,17 @@ module Tefoji
562
570
  next unless raw_issue_data.key?(deferred_tag)
563
571
 
564
572
  issue_key = jira_issue_data['key']
573
+ next unless @transitions_table[issue_key]
574
+
565
575
  new_status = raw_issue_data[deferred_tag].value
576
+ transition_id = @transitions_table[issue_key]
577
+
566
578
  begin
567
- @jira_api.transition(issue_key, new_status)
579
+ @jira_api.transition(issue_key, transition_id)
568
580
  rescue RestClient::BadRequest => e
569
- fatal "setting the status on #{issue_key} to #{new_status} failed: #{e}"
581
+ fatal "setting the status on #{issue_key} to #{new_status} with transition ID #{transition_id} failed: #{e}"
570
582
  end
571
- status_human_readable = jira_statuses.key(new_status.to_i)
572
- @logger.info '%14s: status set to %s' % [issue_key, status_human_readable]
583
+ @logger.info '%14s: status set to "%s"' % [issue_key, new_status]
573
584
  end
574
585
  end
575
586
 
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: 3.1.0
4
+ version: 3.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Puppet By Perforce
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-09-27 00:00:00.000000000 Z
11
+ date: 2023-10-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: debug