tefoji 3.1.0 → 3.3.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: 7de8bcf06db002032d9477d09b5db5b033d2e8ccfdd4a23d4593ae3b1905f6ec
4
+ data.tar.gz: 2fa6bcbd050208e764a4be84fb33b5dab452169f170ee532eccc0d39c136fefd
5
5
  SHA512:
6
- metadata.gz: da84a77b06069df84270a4a15b3e9d2b7ad851246f25200e147443c8e14b163fb988a386ac0e117f44f3c0a896689baa40b122ad9ef12d0eeec3cee522fb2365
7
- data.tar.gz: 98bfb1f2e0478a2598e892ed656ab5605052b22b146a637bbb18c2b0ad16c7b4b389b1a818cb0c01a157843798b5dec3e2142ef687e3991dc4ebd5dd11427b4b
6
+ metadata.gz: f3e12ada8d4ea8fcef49e6928dabe30c37a1d431e870a4d898444f58ceb8fba99356acc1243b89b8e3dbc355f307ff560b4d55ff01e963cf0dd747781a99f3df
7
+ data.tar.gz: c51c23d9ceff772762c061f587a6cbb53d1d980d12b09bbc2e12b31361096516a03036a105230a7c528f20eba7a5e242052441b253fdd8cb2ff5fe88342ffc3b
@@ -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
@@ -39,8 +38,8 @@ module UserFunctions
39
38
  CLIENT_TOOLS: 'CT',
40
39
  CODE_MANAGEMENT: 'CODEMGMT',
41
40
  COMMUNITY_PACKAGE_REPO: 'CPR',
42
- DOC: 'DOC',
43
- DOCS: 'DOC',
41
+ DOC: 'PUPDOC',
42
+ DOCS: 'PUPDOC',
44
43
  EZBAKE: 'EZ',
45
44
  FACTER: 'FACT',
46
45
  FORGE_INTERNAL: 'PF',
@@ -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
@@ -0,0 +1,3 @@
1
+ module Tefoji
2
+ VERSION = '3.3.0'
3
+ end
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
 
@@ -721,7 +732,15 @@ module Tefoji
721
732
  single_value = %r{\A%{(.+?)}\Z}.match(value)
722
733
  return @declarations[single_value[1].to_sym] if single_value
723
734
 
724
- return value % @declarations
735
+ return value if @declarations.nil?
736
+
737
+ # Substitute all variables in the string
738
+ variable_substituted_value = value
739
+ @declarations.each_key do |key|
740
+ variable_substituted_value = variable_substituted_value.gsub("%{#{key}}",
741
+ @declarations[key].value.to_s)
742
+ end
743
+ return variable_substituted_value
725
744
  end
726
745
 
727
746
  # Return a list of all the unset variables in a template
metadata CHANGED
@@ -1,150 +1,150 @@
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.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Puppet By Perforce
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-09-27 00:00:00.000000000 Z
11
+ date: 2023-10-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: debug
15
14
  requirement: !ruby/object:Gem::Requirement
16
15
  requirements:
17
16
  - - ">="
18
17
  - !ruby/object:Gem::Version
19
18
  version: 1.0.0
20
- type: :development
19
+ name: debug
21
20
  prerelease: false
21
+ type: :development
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 1.0.0
27
27
  - !ruby/object:Gem::Dependency
28
- name: rake
29
28
  requirement: !ruby/object:Gem::Requirement
30
29
  requirements:
31
30
  - - "~>"
32
31
  - !ruby/object:Gem::Version
33
32
  version: '13.0'
34
- type: :development
33
+ name: rake
35
34
  prerelease: false
35
+ type: :development
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '13.0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: rspec
43
42
  requirement: !ruby/object:Gem::Requirement
44
43
  requirements:
45
44
  - - "~>"
46
45
  - !ruby/object:Gem::Version
47
46
  version: '3.0'
48
- type: :development
47
+ name: rspec
49
48
  prerelease: false
49
+ type: :development
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: rubocop
57
56
  requirement: !ruby/object:Gem::Requirement
58
57
  requirements:
59
58
  - - ">="
60
59
  - !ruby/object:Gem::Version
61
60
  version: '0'
62
- type: :development
61
+ name: rubocop
63
62
  prerelease: false
63
+ type: :development
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: rubocop-rake
71
70
  requirement: !ruby/object:Gem::Requirement
72
71
  requirements:
73
72
  - - ">="
74
73
  - !ruby/object:Gem::Version
75
74
  version: '0'
76
- type: :development
75
+ name: rubocop-rake
77
76
  prerelease: false
77
+ type: :development
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
- name: rubocop-rspec
85
84
  requirement: !ruby/object:Gem::Requirement
86
85
  requirements:
87
86
  - - ">="
88
87
  - !ruby/object:Gem::Version
89
88
  version: '0'
90
- type: :development
89
+ name: rubocop-rspec
91
90
  prerelease: false
91
+ type: :development
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
- name: webmock
99
98
  requirement: !ruby/object:Gem::Requirement
100
99
  requirements:
101
100
  - - ">="
102
101
  - !ruby/object:Gem::Version
103
102
  version: '0'
104
- type: :development
103
+ name: webmock
105
104
  prerelease: false
105
+ type: :development
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  - !ruby/object:Gem::Dependency
112
- name: yard
113
112
  requirement: !ruby/object:Gem::Requirement
114
113
  requirements:
115
114
  - - "~>"
116
115
  - !ruby/object:Gem::Version
117
116
  version: '0.9'
118
- type: :development
117
+ name: yard
119
118
  prerelease: false
119
+ type: :development
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0.9'
125
125
  - !ruby/object:Gem::Dependency
126
- name: docopt
127
126
  requirement: !ruby/object:Gem::Requirement
128
127
  requirements:
129
128
  - - "~>"
130
129
  - !ruby/object:Gem::Version
131
130
  version: '0.6'
132
- type: :runtime
131
+ name: docopt
133
132
  prerelease: false
133
+ type: :runtime
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
136
  - - "~>"
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0.6'
139
139
  - !ruby/object:Gem::Dependency
140
- name: rest-client
141
140
  requirement: !ruby/object:Gem::Requirement
142
141
  requirements:
143
142
  - - "~>"
144
143
  - !ruby/object:Gem::Version
145
144
  version: '2.1'
146
- type: :runtime
145
+ name: rest-client
147
146
  prerelease: false
147
+ type: :runtime
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
150
  - - "~>"
@@ -153,7 +153,7 @@ dependencies:
153
153
  description: 'From a YAML specification, create a batch of Jira issues allowing for
154
154
  variable substitutions.
155
155
 
156
- '
156
+ '
157
157
  email: release@puppet.com
158
158
  executables:
159
159
  - tefoji
@@ -167,6 +167,7 @@ files:
167
167
  - lib/tefoji/cli.rb
168
168
  - lib/tefoji/declared_value.rb
169
169
  - lib/tefoji/jira_api.rb
170
+ - lib/tefoji/version.rb
170
171
  homepage: https://github.com/puppetlabs/tefoji
171
172
  licenses:
172
173
  - Apache-2.0
@@ -174,7 +175,7 @@ metadata:
174
175
  homepage_uri: https://github.com/puppetlabs/tefoji
175
176
  source_code_uri: https://github.com/puppetlabs/tefoji
176
177
  changelog_uri: https://github.com/puppetlabs/tefoji/CHANGELOG.md
177
- post_install_message:
178
+ post_install_message:
178
179
  rdoc_options: []
179
180
  require_paths:
180
181
  - lib
@@ -189,8 +190,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
189
190
  - !ruby/object:Gem::Version
190
191
  version: '0'
191
192
  requirements: []
192
- rubygems_version: 3.0.3
193
- signing_key:
193
+ rubygems_version: 3.3.26
194
+ signing_key:
194
195
  specification_version: 4
195
196
  summary: Generate Jira issues from a YAML specification.
196
197
  test_files: []