caperoma 4.0.1 → 5.0.0
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 +4 -4
- data/Capefile +6 -6
- data/Capefile.template +4 -1
- data/Gemfile +1 -5
- data/Gemfile.lock +3 -45
- data/HELP +84 -13
- data/README.md +165 -29
- data/Rakefile +25 -22
- data/VERSION +1 -1
- data/bin/caperoma +6 -9
- data/caperoma.gemspec +15 -13
- data/config/crontab +0 -2
- data/config/schedule.rb +17 -19
- data/config/unschedule.rb +3 -0
- data/images/circle.png +0 -0
- data/images/report.png +0 -0
- data/lib/caperoma.rb +308 -98
- data/lib/caperoma/models/account.rb +1 -1
- data/lib/caperoma/models/project.rb +1 -2
- data/lib/caperoma/models/report.rb +15 -15
- data/lib/caperoma/models/task.rb +203 -46
- data/lib/caperoma/models/tasks/chore.rb +2 -0
- data/lib/caperoma/models/tasks/feature.rb +1 -0
- data/lib/caperoma/models/tasks/fix.rb +2 -0
- data/lib/caperoma/models/tasks/meeting.rb +2 -0
- data/lib/caperoma/models/tasks/modules/git.rb +94 -15
- data/lib/caperoma/models/tasks/task_with_commit.rb +8 -5
- data/lib/caperoma/models/tasks/task_with_separate_branch.rb +6 -4
- data/spec/caperoma_spec.rb +558 -2
- data/spec/factories/accounts.rb +1 -1
- data/spec/factories/projects.rb +1 -1
- data/spec/factories/report_recipients.rb +1 -1
- data/spec/factories/reports.rb +1 -1
- data/spec/factories/tasks.rb +1 -2
- data/spec/features/command_unknown_spec.rb +0 -1
- data/spec/features/feature_spec.rb +64 -44
- data/spec/features/init_spec.rb +20 -0
- data/spec/features/status_spec.rb +12 -11
- data/spec/models/project_spec.rb +0 -1
- data/spec/models/task_spec.rb +811 -27
- data/spec/models/task_with_commit_spec.rb +0 -4
- data/spec/models/task_with_separate_branch_spec.rb +4 -4
- data/spec/models/three_day_report_spec.rb +2 -3
- data/spec/spec_helper.rb +2 -0
- data/spec/support/capefile_generator.rb +35 -27
- data/spec/support/stubs.rb +7 -74
- metadata +47 -24
- data/lib/caperoma/models/branch.rb +0 -6
- data/lib/caperoma/services/airbrake_email_processor.rb +0 -47
- data/lib/caperoma/services/pivotal_fetcher.rb +0 -108
- data/spec/factories/branches.rb +0 -9
- data/spec/models/branch_spec.rb +0 -8
@@ -3,7 +3,7 @@
|
|
3
3
|
class Account < ApplicationRecord
|
4
4
|
self.inheritance_column = nil
|
5
5
|
|
6
|
-
validates :email, presence: true
|
6
|
+
validates :email, presence: true
|
7
7
|
validates :password, presence: true
|
8
8
|
validates :type, presence: true, inclusion: { in: %w[--jira --pivotal --gmail --git --caperoma] }
|
9
9
|
|
@@ -1,7 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
class Project < ApplicationRecord
|
4
|
-
has_many :branches
|
5
4
|
has_many :chores
|
6
5
|
has_many :bugs
|
7
6
|
has_many :features
|
@@ -9,6 +8,6 @@ class Project < ApplicationRecord
|
|
9
8
|
has_many :fixes
|
10
9
|
|
11
10
|
def folder_path
|
12
|
-
|
11
|
+
(self[:folder_path]).to_s
|
13
12
|
end
|
14
13
|
end
|
@@ -11,18 +11,18 @@ class Report < ApplicationRecord
|
|
11
11
|
after_create :update_content
|
12
12
|
|
13
13
|
def self.schedule
|
14
|
-
# may screw up existing cron tasks
|
15
14
|
puts 'Turning on auto reports'
|
16
15
|
root = File.dirname __dir__
|
17
|
-
|
18
|
-
`crontab #{
|
19
|
-
# > whenever --update-crontab caperoma
|
16
|
+
crontab_config_file = File.join root, '..', '..', 'config', 'schedule.rb'
|
17
|
+
`whenever --update-crontab caperoma --load-file "#{crontab_config_file}"`
|
20
18
|
puts 'Auto reports turned on'
|
21
19
|
end
|
22
20
|
|
23
21
|
def self.unschedule
|
24
22
|
puts 'Turning off auto reports'
|
25
|
-
|
23
|
+
root = File.dirname __dir__
|
24
|
+
crontab_config_file = File.join root, '..', '..', 'config', 'unschedule.rb'
|
25
|
+
`whenever --update-crontab caperoma --load-file "#{crontab_config_file}"`
|
26
26
|
puts 'Auto reports turned off'
|
27
27
|
end
|
28
28
|
|
@@ -124,16 +124,16 @@ class Report < ApplicationRecord
|
|
124
124
|
[
|
125
125
|
"\n",
|
126
126
|
"<h2>Done during #{timeframe}:</h2>",
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
127
|
+
'<br />',
|
128
|
+
'<table style="width: 100%;text-align: left;">',
|
129
|
+
'<thead>',
|
130
|
+
'<tr><th>Jira</th><th>Pivotal</th><th>Title</th><th>Time spent</th></tr>',
|
131
|
+
'</thead>',
|
132
|
+
'<tbody>',
|
133
133
|
reported_tasks_rows,
|
134
|
-
|
135
|
-
|
136
|
-
|
134
|
+
'</tbody>',
|
135
|
+
'</table>',
|
136
|
+
'<br />',
|
137
137
|
"<strong>Total time spent during #{timeframe}:</strong> #{total_time_spent}."
|
138
138
|
].flatten.join("\n")
|
139
139
|
end
|
@@ -143,7 +143,7 @@ class Report < ApplicationRecord
|
|
143
143
|
end
|
144
144
|
|
145
145
|
def table_row(task)
|
146
|
-
'<tr>' + task_row_data(task).collect{|task| '<td>' + task + '</td>' }.join("\n") + '</tr>'
|
146
|
+
'<tr>' + task_row_data(task).collect { |task| '<td>' + task + '</td>' }.join("\n") + '</tr>'
|
147
147
|
end
|
148
148
|
|
149
149
|
def task_row_data(task)
|
data/lib/caperoma/models/task.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
class Task < ActiveRecord::Base
|
3
4
|
include Git
|
4
5
|
|
@@ -10,6 +11,8 @@ class Task < ActiveRecord::Base
|
|
10
11
|
validates :title, presence: true
|
11
12
|
validates :pivotal_id, length: { minimum: 6 }, allow_blank: true, numericality: { only_integer: true }
|
12
13
|
|
14
|
+
validates :additional_time, allow_blank: true, numericality: { only_integer: true }
|
15
|
+
|
13
16
|
before_create :generate_uuid
|
14
17
|
before_create :set_start_time
|
15
18
|
|
@@ -47,30 +50,29 @@ class Task < ActiveRecord::Base
|
|
47
50
|
end
|
48
51
|
|
49
52
|
def self.status
|
50
|
-
if unfinished.
|
51
|
-
puts
|
52
|
-
else
|
53
|
-
unfinished.each do |task|
|
54
|
-
puts
|
53
|
+
if unfinished.empty?
|
54
|
+
puts 'You are not working on anything now.'
|
55
|
+
else
|
56
|
+
unfinished.each do |task|
|
57
|
+
puts 'You are working on: '
|
55
58
|
puts "Title: #{task.title}"
|
56
59
|
puts "Type: #{task.type}"
|
57
|
-
puts "Jira ID: #{task.jira_key}." if task.jira_key.present?
|
60
|
+
puts "Jira ID: #{task.jira_key} (#{task.jira_live_url})." if task.jira_key.present?
|
58
61
|
puts "Pivotal ID: #{task.pivotal_id} (#{task.pivotal_url})" if task.pivotal_id.present?
|
59
62
|
puts "Time spent at the moment: #{task.time_spent_so_far}"
|
63
|
+
puts "Branch with the task: #{task.branch}" if task.branch.present?
|
60
64
|
puts "Pull request will be sent to this branch: #{task.parent_branch}" if task.parent_branch.present?
|
61
65
|
puts "Project location: #{task.project.folder_path}"
|
62
66
|
end
|
63
67
|
end
|
64
68
|
end
|
65
69
|
|
66
|
-
attr_writer :additional_time
|
67
|
-
|
68
70
|
def finish(comment)
|
69
71
|
# full pull request
|
70
72
|
update_attribute(:finished_at, Time.now)
|
71
73
|
close_issue_on_jira
|
72
|
-
log_work_to_jira(comment)
|
73
|
-
finish_on_pivotal if
|
74
|
+
log_work_to_jira(comment) if should_log_work?
|
75
|
+
finish_on_pivotal if finish_on_pivotal?
|
74
76
|
puts time_spent
|
75
77
|
end
|
76
78
|
|
@@ -78,8 +80,8 @@ class Task < ActiveRecord::Base
|
|
78
80
|
# finish with commit & push but without pull request
|
79
81
|
update_attribute(:finished_at, Time.now)
|
80
82
|
close_issue_on_jira
|
81
|
-
log_work_to_jira(comment)
|
82
|
-
finish_on_pivotal if
|
83
|
+
log_work_to_jira(comment) if should_log_work?
|
84
|
+
finish_on_pivotal if finish_on_pivotal?
|
83
85
|
puts time_spent
|
84
86
|
end
|
85
87
|
|
@@ -87,12 +89,12 @@ class Task < ActiveRecord::Base
|
|
87
89
|
# finish without commit or push
|
88
90
|
update_attribute(:finished_at, Time.now)
|
89
91
|
close_issue_on_jira
|
90
|
-
log_work_to_jira(comment)
|
91
|
-
finish_on_pivotal if
|
92
|
+
log_work_to_jira(comment) if should_log_work?
|
93
|
+
finish_on_pivotal if finish_on_pivotal?
|
92
94
|
puts time_spent
|
93
95
|
end
|
94
96
|
|
95
|
-
def abort_without_time(
|
97
|
+
def abort_without_time(_comment)
|
96
98
|
# finish without commit or push
|
97
99
|
update_attribute(:finished_at, Time.now)
|
98
100
|
close_issue_on_jira
|
@@ -100,6 +102,10 @@ class Task < ActiveRecord::Base
|
|
100
102
|
puts time_spent
|
101
103
|
end
|
102
104
|
|
105
|
+
def should_log_work?
|
106
|
+
time_spent_so_far != '0h 0m' && Account.jira.present?
|
107
|
+
end
|
108
|
+
|
103
109
|
def time_spent_so_far
|
104
110
|
result = TimeDifference.between(started_at, Time.now).in_minutes
|
105
111
|
|
@@ -137,19 +143,23 @@ class Task < ActiveRecord::Base
|
|
137
143
|
end
|
138
144
|
|
139
145
|
def create_on_jira?
|
140
|
-
Account.jira.present? &&
|
146
|
+
Account.jira.present? && not_test?
|
141
147
|
end
|
142
148
|
|
143
149
|
def start_on_jira?
|
144
|
-
jira_key.present? && Account.jira.present? &&
|
150
|
+
jira_key.present? && Account.jira.present? && not_test?
|
145
151
|
end
|
146
152
|
|
147
153
|
def create_on_pivotal?
|
148
|
-
pivotal_id.blank? && this_is_a_type_a_user_wants_to_create? && Account.pivotal.present? &&
|
154
|
+
pivotal_id.blank? && this_is_a_type_a_user_wants_to_create? && Account.pivotal.present? && not_test?
|
149
155
|
end
|
150
156
|
|
151
157
|
def start_on_pivotal?
|
152
|
-
pivotal_id.present? && Account.pivotal.present? &&
|
158
|
+
pivotal_id.present? && Account.pivotal.present? && not_test?
|
159
|
+
end
|
160
|
+
|
161
|
+
def finish_on_pivotal?
|
162
|
+
pivotal_id.present? && Account.pivotal.present? && not_test?
|
153
163
|
end
|
154
164
|
|
155
165
|
def this_is_a_type_a_user_wants_to_create?
|
@@ -162,7 +172,7 @@ class Task < ActiveRecord::Base
|
|
162
172
|
|
163
173
|
def set_start_time
|
164
174
|
time = Time.now
|
165
|
-
time -=
|
175
|
+
time -= additional_time.to_i.minutes if additional_time.present?
|
166
176
|
self.started_at = time
|
167
177
|
end
|
168
178
|
|
@@ -171,7 +181,7 @@ class Task < ActiveRecord::Base
|
|
171
181
|
end
|
172
182
|
|
173
183
|
def output_jira_key?
|
174
|
-
jira_key.present? &&
|
184
|
+
jira_key.present? && not_test?
|
175
185
|
end
|
176
186
|
|
177
187
|
def start_issue_on_pivotal_data
|
@@ -182,6 +192,8 @@ class Task < ActiveRecord::Base
|
|
182
192
|
|
183
193
|
def start_issue_on_pivotal
|
184
194
|
if not_test?
|
195
|
+
puts 'Starting the task in Pivotal'
|
196
|
+
|
185
197
|
conn = Faraday.new(url: 'https://www.pivotaltracker.com/') do |c|
|
186
198
|
c.adapter Faraday.default_adapter
|
187
199
|
end
|
@@ -193,7 +205,22 @@ class Task < ActiveRecord::Base
|
|
193
205
|
request.headers['Content-Type'] = 'application/json'
|
194
206
|
request.headers['X-TrackerToken'] = Account.pivotal.password
|
195
207
|
end
|
208
|
+
|
209
|
+
case response.status
|
210
|
+
when 200, 201, 202, 204, 301, 302, 303, 304, 307
|
211
|
+
puts 'Started the task in Pivotal'
|
212
|
+
when 401, 403
|
213
|
+
puts "No access to the task ##{pivotal_id} in Pivotal. Maybe login or api_key are incorrect."
|
214
|
+
when 404
|
215
|
+
puts "A task with ID ##{pivotal_id} is not found in Pivotal."
|
216
|
+
else
|
217
|
+
puts 'Could not start the task in Pivotal.'
|
218
|
+
puts "Error status: #{response.status}"
|
219
|
+
puts "Message from server: #{response.reason_phrase}"
|
220
|
+
end
|
196
221
|
end
|
222
|
+
rescue Faraday::ConnectionFailed
|
223
|
+
puts 'Connection failed. Performing the task without requests to Pivotal.'
|
197
224
|
end
|
198
225
|
|
199
226
|
def finish_on_pivotal_data
|
@@ -204,6 +231,8 @@ class Task < ActiveRecord::Base
|
|
204
231
|
|
205
232
|
def finish_on_pivotal
|
206
233
|
if not_test?
|
234
|
+
puts 'Finishing the task in Pivotal'
|
235
|
+
|
207
236
|
conn = Faraday.new(url: 'https://www.pivotaltracker.com/') do |c|
|
208
237
|
c.adapter Faraday.default_adapter
|
209
238
|
end
|
@@ -215,7 +244,22 @@ class Task < ActiveRecord::Base
|
|
215
244
|
request.headers['Content-Type'] = 'application/json'
|
216
245
|
request.headers['X-TrackerToken'] = Account.pivotal.password
|
217
246
|
end
|
247
|
+
|
248
|
+
case response.status
|
249
|
+
when 200, 201, 202, 204, 301, 302, 303, 304, 307
|
250
|
+
puts 'Finished the task in Pivotal'
|
251
|
+
when 401, 403
|
252
|
+
puts "No access to the task ##{pivotal_id} in Pivotal. Maybe login or api_key are incorrect."
|
253
|
+
when 404
|
254
|
+
puts "A task with ID ##{pivotal_id} is not found in Pivotal."
|
255
|
+
else
|
256
|
+
puts 'Could not finish the task in Pivotal.'
|
257
|
+
puts "Error status: #{response.status}"
|
258
|
+
puts "Message from server: #{response.reason_phrase}"
|
259
|
+
end
|
218
260
|
end
|
261
|
+
rescue Faraday::ConnectionFailed
|
262
|
+
puts 'Connection failed. Performing the task without requests to Pivotal.'
|
219
263
|
end
|
220
264
|
|
221
265
|
def start_issue_on_jira_data
|
@@ -226,18 +270,35 @@ class Task < ActiveRecord::Base
|
|
226
270
|
|
227
271
|
def start_issue_on_jira
|
228
272
|
if not_test?
|
273
|
+
puts 'Starting the issue in Jira'
|
274
|
+
|
229
275
|
conn = Faraday.new(url: project.jira_url) do |c|
|
230
276
|
c.basic_auth(Account.jira.email, Account.jira.password)
|
231
277
|
c.adapter Faraday.default_adapter
|
232
278
|
end
|
233
279
|
|
234
|
-
conn.post do |request|
|
280
|
+
response = conn.post do |request|
|
235
281
|
request.url "rest/api/3/issue/#{jira_key}/transitions"
|
236
282
|
request.body = start_issue_on_jira_data
|
237
283
|
request.headers['User-Agent'] = 'Caperoma'
|
238
284
|
request.headers['Content-Type'] = 'application/json'
|
239
285
|
end
|
286
|
+
|
287
|
+
case response.status
|
288
|
+
when 200, 201, 202, 204, 301, 302, 303, 304, 307
|
289
|
+
puts 'Started the issue in Jira'
|
290
|
+
when 401, 403
|
291
|
+
puts "No access to the task #{jira_key} in Jira. Maybe login or api_key are incorrect."
|
292
|
+
when 404
|
293
|
+
puts "A task with ID #{jira_key} is not found in Jira."
|
294
|
+
else
|
295
|
+
puts 'Could not start the issue in Jira.'
|
296
|
+
puts "Error status: #{response.status}"
|
297
|
+
puts "Message from server: #{response.reason_phrase}"
|
298
|
+
end
|
240
299
|
end
|
300
|
+
rescue Faraday::ConnectionFailed
|
301
|
+
puts 'Connection failed. Performing the task without requests to Jira.'
|
241
302
|
end
|
242
303
|
|
243
304
|
def close_issue_on_jira_data
|
@@ -248,6 +309,8 @@ class Task < ActiveRecord::Base
|
|
248
309
|
|
249
310
|
def close_issue_on_jira
|
250
311
|
if not_test?
|
312
|
+
puts 'Closing the issue in Jira'
|
313
|
+
|
251
314
|
conn = Faraday.new(url: project.jira_url) do |c|
|
252
315
|
c.basic_auth(Account.jira.email, Account.jira.password)
|
253
316
|
c.adapter Faraday.default_adapter
|
@@ -259,7 +322,22 @@ class Task < ActiveRecord::Base
|
|
259
322
|
request.headers['User-Agent'] = 'Caperoma'
|
260
323
|
request.headers['Content-Type'] = 'application/json'
|
261
324
|
end
|
325
|
+
|
326
|
+
case response.status
|
327
|
+
when 200, 201, 202, 204, 301, 302, 303, 304, 307
|
328
|
+
puts 'Closed the issue in Jira'
|
329
|
+
when 401, 403
|
330
|
+
puts "No access to the task #{jira_key} in Jira. Maybe login or api_key are incorrect."
|
331
|
+
when 404
|
332
|
+
puts "A task with ID #{jira_key} is not found in Jira."
|
333
|
+
else
|
334
|
+
puts 'Could not close the issue in Jira.'
|
335
|
+
puts "Error status: #{response.status}"
|
336
|
+
puts "Message from server: #{response.reason_phrase}"
|
337
|
+
end
|
262
338
|
end
|
339
|
+
rescue Faraday::ConnectionFailed
|
340
|
+
puts 'Connection failed. Performing the task without requests to Jira.'
|
263
341
|
end
|
264
342
|
|
265
343
|
def log_work_to_jira_data(comment = 'Done')
|
@@ -272,18 +350,35 @@ class Task < ActiveRecord::Base
|
|
272
350
|
|
273
351
|
def log_work_to_jira(comment = 'Done')
|
274
352
|
if not_test?
|
353
|
+
puts 'Logging work to Jira'
|
354
|
+
|
275
355
|
conn = Faraday.new(url: project.jira_url) do |c|
|
276
356
|
c.basic_auth(Account.jira.email, Account.jira.password)
|
277
357
|
c.adapter Faraday.default_adapter
|
278
358
|
end
|
279
359
|
|
280
|
-
|
360
|
+
response = conn.post do |request|
|
281
361
|
request.url "rest/api/3/issue/#{jira_key}/worklog"
|
282
362
|
request.body = log_work_to_jira_data(comment)
|
283
363
|
request.headers['User-Agent'] = 'Caperoma'
|
284
364
|
request.headers['Content-Type'] = 'application/json'
|
285
365
|
end
|
366
|
+
|
367
|
+
case response.status
|
368
|
+
when 200, 201, 202, 204, 301, 302, 303, 304, 307
|
369
|
+
puts 'Work logged to Jira'
|
370
|
+
when 401, 403
|
371
|
+
puts "No access to the task #{jira_key} in Jira. Maybe login or api_key are incorrect."
|
372
|
+
when 404
|
373
|
+
puts "A task with ID #{jira_key} is not found in Jira."
|
374
|
+
else
|
375
|
+
puts 'Could not log work to Jira.'
|
376
|
+
puts "Error status: #{response.status}"
|
377
|
+
puts "Message from server: #{response.reason_phrase}"
|
378
|
+
end
|
286
379
|
end
|
380
|
+
rescue Faraday::ConnectionFailed
|
381
|
+
puts 'Connection failed. Performing the task without requests to Jira.'
|
287
382
|
end
|
288
383
|
|
289
384
|
def current_time
|
@@ -297,14 +392,17 @@ class Task < ActiveRecord::Base
|
|
297
392
|
def create_issue_on_pivotal_data
|
298
393
|
Jbuilder.encode do |j|
|
299
394
|
j.current_state 'unstarted'
|
300
|
-
j.estimate 1
|
395
|
+
j.estimate pivotal_estimate == 0 ? 1 : pivotal_estimate
|
301
396
|
j.name title.to_s
|
397
|
+
j.description description
|
302
398
|
j.story_type story_type
|
303
399
|
end
|
304
400
|
end
|
305
401
|
|
306
402
|
def create_issue_on_pivotal
|
307
403
|
if not_test?
|
404
|
+
puts 'Creating a task in Pivotal'
|
405
|
+
|
308
406
|
conn = Faraday.new(url: 'https://www.pivotaltracker.com/') do |c|
|
309
407
|
c.adapter Faraday.default_adapter
|
310
408
|
end
|
@@ -317,29 +415,69 @@ class Task < ActiveRecord::Base
|
|
317
415
|
request.headers['X-TrackerToken'] = Account.pivotal.password
|
318
416
|
end
|
319
417
|
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
418
|
+
case response.status
|
419
|
+
when 200, 201, 202, 204, 301, 302, 303, 304, 307
|
420
|
+
puts 'Created the task in Pivotal'
|
421
|
+
result = JSON.parse response.body
|
422
|
+
|
423
|
+
update_attributes(
|
424
|
+
pivotal_id: result['id']
|
425
|
+
)
|
426
|
+
when 401, 403
|
427
|
+
puts "No access to the server. Maybe login, api_key or Pivotal Project ID ##{project.pivotal_tracker_project_id} is incorrect."
|
428
|
+
when 404
|
429
|
+
puts "Resource not found. Maybe Pivotal Project ID ##{project.pivotal_tracker_project_id} is incorrect."
|
430
|
+
else
|
431
|
+
puts 'Could not create the task in Pivotal.'
|
432
|
+
puts "Error status: #{response.status}"
|
433
|
+
puts "Message from server: #{response.reason_phrase}"
|
434
|
+
end
|
325
435
|
end
|
436
|
+
rescue Faraday::ConnectionFailed
|
437
|
+
puts 'Connection failed. Performing the task without requests to Pivotal.'
|
326
438
|
end
|
327
439
|
|
328
440
|
def create_issue_on_jira_data
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
441
|
+
hash = {
|
442
|
+
fields: {
|
443
|
+
summary: title.to_s,
|
444
|
+
issuetype: {
|
445
|
+
id: issue_type
|
446
|
+
},
|
447
|
+
project: {
|
448
|
+
id: project.jira_project_id.to_s
|
449
|
+
},
|
450
|
+
assignee: {
|
451
|
+
name: Account.jira.username
|
452
|
+
}
|
453
|
+
}
|
454
|
+
}
|
455
|
+
|
456
|
+
description_hash = {
|
457
|
+
type: 'doc',
|
458
|
+
version: 1,
|
459
|
+
content: [
|
460
|
+
{
|
461
|
+
type: 'paragraph',
|
462
|
+
content: [
|
463
|
+
{
|
464
|
+
text: description,
|
465
|
+
type: 'text'
|
466
|
+
}
|
467
|
+
]
|
468
|
+
}
|
469
|
+
]
|
470
|
+
}
|
471
|
+
|
472
|
+
hash[:fields][:description] = description_hash if description.present?
|
473
|
+
|
474
|
+
hash.to_json
|
339
475
|
end
|
340
476
|
|
341
477
|
def create_issue_on_jira
|
342
478
|
if not_test?
|
479
|
+
puts 'Creating an issue in Jira'
|
480
|
+
|
343
481
|
conn = Faraday.new(url: project.jira_url) do |c|
|
344
482
|
c.basic_auth(Account.jira.email, Account.jira.password)
|
345
483
|
c.adapter Faraday.default_adapter
|
@@ -352,17 +490,36 @@ class Task < ActiveRecord::Base
|
|
352
490
|
request.headers['Content-Type'] = 'application/json'
|
353
491
|
end
|
354
492
|
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
493
|
+
case response.status
|
494
|
+
when 200, 201, 202, 204, 301, 302, 303, 304, 307
|
495
|
+
puts 'Created the issue in Jira'
|
496
|
+
|
497
|
+
result = JSON.parse response.body
|
498
|
+
|
499
|
+
update_attributes(
|
500
|
+
jira_id: result['id'],
|
501
|
+
jira_key: result['key'],
|
502
|
+
jira_url: result['self']
|
503
|
+
)
|
504
|
+
when 401, 403
|
505
|
+
puts "Forbidden access to the resource in Jira. Maybe login, api_key or Jira project id #{project.jira_project_id} are incorrect."
|
506
|
+
when 404
|
507
|
+
puts "Not found the resource in Jira. Maybe the Jira Project ID #{project.jira_project_id} is incorrect."
|
508
|
+
else
|
509
|
+
puts 'Could not create the issue in Jira.'
|
510
|
+
puts "Error status: #{response.status}"
|
511
|
+
puts "Message from server: #{response.reason_phrase}"
|
512
|
+
end
|
362
513
|
end
|
514
|
+
rescue Faraday::ConnectionFailed
|
515
|
+
puts 'Connection failed. Performing the task without requests to Jira.'
|
363
516
|
end
|
364
517
|
|
365
518
|
def not_test?
|
366
519
|
ENV['CAPEROMA_INTEGRATION_TEST'].blank?
|
367
520
|
end
|
521
|
+
|
522
|
+
def enable_git?
|
523
|
+
ENV['CAPEROMA_TEST'].blank? && ENV['CAPEROMA_INTEGRATION_TEST'].blank?
|
524
|
+
end
|
368
525
|
end
|