forked from openshift/sprint_tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
trello
executable file
·563 lines (506 loc) · 20.3 KB
/
trello
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
#!/usr/bin/env ruby
$LOAD_PATH.unshift(File.dirname(__FILE__) + '/lib') unless $LOAD_PATH.include?(File.dirname(__FILE__) + '/lib')
require 'config'
require 'trello_helper'
require 'output_helper'
require 'reports'
require 'report'
require 'erb'
require 'pp'
require 'yaml'
require 'i18n'
require 'commander/import'
Encoding.default_external = "UTF-8"
name="#{__FILE__}"
program :name, "Trello Utilities"
program :version, "1.0.0"
program :description, "An assortment of Trello utilities"
# This loads the conf files and creates new objects based on the specified classes
def load_conf(klass,args,single = false)
if single
klass.new(args)
else
Hash[*args.map do |key,val|
[key,klass.new(val)]
end.flatten]
end
end
def clear_epic_refs(epic_card, trello)
tags = []
epic_card.name.scan(/\[[^\]]+\]/).each do |tag|
if tag != FUTURE_TAG
tags << tag
end
end
trello.clear_checklist_refs(epic_card, EPIC_REFERENCED_STORIES_NAME, tags)
trello.clear_checklist_refs(epic_card, FUTURE_EPIC_REFERENCED_STORIES_NAME, [FUTURE_TAG])
end
$tag_to_label_color = {
'documentation' => 'green',
'tc-approved' => 'yellow',
'no-qe' => 'orange',
'security' => 'red',
'devcut' => 'purple'
}
LINKS = {'roadmap_overview' => 'Roadmap Overview',
'sprints_overview' => 'Sprints Overview',
'previous_sprints_overview' => 'Previous Sprints Overview',
'sprint_schedule' => 'Sprint Schedule'}
EPIC_REFERENCED_STORIES_NAME = "Scenarios"
FUTURE_EPIC_REFERENCED_STORIES_NAME = "Future Scenarios"
FUTURE_TAG = '[future]'
trello = load_conf(TrelloHelper, CONFIG.trello, true)
command :list do |c|
c.syntax = "#{name} list"
c.option "--list LIST_NAME", "Restrict to a particular list"
c.option "--team TEAM_NAME (#{trello.teams.keys.join('|')})", "Restrict to a team"
c.option "--card-ref SCOPE_TEAM_ID", "Get a single card Ex: #{trello.teams.values.first.keys.first}_1"
c.description = "An assortment of Trello queries"
c.action do |args, options|
puts "Organization: #{trello.org.name}"
if options.card_ref
card = trello.card_by_ref(options.card_ref)
if card
trello.print_card(card)
else
puts "#{options.card_ref} is an invalid format!"
exit 1
end
else
if options.team
boards = trello.team_boards(options.team)
else
boards = trello.org_boards
end
boards.each do |board|
puts "\nBoard Name: #{board.name}"
lists = trello.target(board.lists)
if options.list
lists = []
lists.each do |list|
if list.name == options.list
lists = [list]
break
end
end
end
lists.each do |list|
trello.print_list(list)
end
end
end
end
end
command :sprint_identifier do |c|
c.syntax = "#{name} sprint_identifier"
c.description = "Print the sprint identifier"
c.action do |args, options|
$sprint = Sprint.new({:trello => trello})
if $sprint.sprint_card.name =~ /^Sprint (\d+)/
print "2.0.#{$1}"
else
print "unknown"
end
end
end
command :list_invalid_users do |c|
c.syntax = "#{name} list_invalid_users"
c.description = "List the potentially invalid users"
c.action do |args, options|
require 'ldap_helper'
ldap = load_conf(LdapHelper, CONFIG.ldap, true)
puts "Potential Invalid Organization Users:"
valid_user_names = {}
invalid_user_names = ldap.print_invalid_members(trello.org.members, valid_user_names, invalid_user_names)
puts "\n\nPotential Invalid Board Users:"
trello.org_boards.each do |board|
unless board.closed?
puts "\n#{board.name}:"
ldap.print_invalid_members(board.members, valid_user_names, invalid_user_names.clone)
end
end
puts "\n\nValid Logins:"
puts valid_user_names.keys
end
end
command :report do |c|
c.syntax = "#{name} report"
c.option "--report-type NAME" , "Available report types: %s" % CONFIG.reports.keys.join(', ')
c.option "--send-email" , "Send email?"
c.description = "An assortment of Trello reporting utilities"
c.action do |args, options|
options.report_type ||= choose("Report to run?",*CONFIG.reports.keys)
options.report_type = options.report_type.to_sym
if options.date
$date = Date.parse(options.date)
end
heading "Generating Status Report" do
# Read Rally configuration file
_progress "Logging into Trello" do
$sprint = Sprint.new({:trello => trello})
end
# Generate queries
_progress "Generating queries" do
$report_types = load_conf(UserStoryReport,CONFIG.queries)
end
# Generate reports
_progress "Building available reports" do
$reports = load_conf(Report,CONFIG.reports)
end
end
report = $reports[options.report_type]
report.options = options.__hash__
_table(
"Running Report With Options",
report.options.marshal_dump,
{ :capitalize => true, :sort => 0, :separator => ':' }
)
report.send_email
end
end
command :generate_roadmap_overview do |c|
c.syntax = "#{name} generate_roadmap_overview"
c.option "--out OUT_FILE", "The file to output Ex: /tmp/roadmap_overview.html"
c.description = "Generate the overview of the roadmap board"
c.action do |args, options|
options.out ||= '/tmp/roadmap_overview.html'
erb = ERB.new(File.open('templates/roadmap_overview.erb', "rb").read)
File.open(options.out, 'w') {|f| f.write(erb.result(binding)) }
end
end
command :generate_sprints_overview do |c|
c.syntax = "#{name} generate_sprints_overview"
c.option "--out OUT_FILE", "The file to output Ex: /tmp/sprints_overview.html"
c.option "--sprints NUM", "The number of sprints to show"
c.option "--offset NUM", "The number of sprints to offset from the latest"
c.description = "Generate the sprints overview"
c.action do |args, options|
options.out ||= '/tmp/sprints_overview.html'
options.sprints = options.sprints ? options.sprints.to_i : 8
options.offset = options.offset ? options.offset.to_i : 0
erb = ERB.new(File.open('templates/sprints_overview.erb', "rb").read)
File.open(options.out, 'w') {|f| f.write(erb.result(binding)) }
end
end
command :generate_sprint_schedule do |c|
c.syntax = "#{name} generate_sprint_schedule"
c.option "--out OUT_FILE", "The file to output Ex: /tmp/sprint_schedule.html"
c.option "--sprints NUM", "The number of sprints to show"
c.description = "Generate the sprint schedule"
c.action do |args, options|
options.out ||= '/tmp/sprint_schedule.html'
options.sprints = options.sprints ? options.sprints.to_i : 8
$sprint = Sprint.new({:trello => trello})
erb = ERB.new(File.open('templates/sprint_schedule.erb', "rb").read)
File.open(options.out, 'w') {|f| f.write(erb.result(binding)) }
end
end
command :comment do |c|
c.syntax = "#{name} comment"
c.option "--card-ref SCOPE_TEAM_ID", "Get a single card Ex: #{trello.teams.values.first.keys.first}_1"
c.description = "Adds a comment to a trello card"
c.action do |args, options|
comment = args[0]
card = trello.card_by_ref(options.card_ref)
if card
card.add_comment(comment)
else
puts "#{options.card_ref} is an invalid format!"
exit 1
end
end
end
command :update do |c|
c.syntax = "#{name} update"
c.option "--add-task-checklists", "Add task checklists to stories"
c.option "--add-bug-checklists", "Add checklists to stories"
c.option "--add-doc-tasks", "Add documentation tasks to documentation labeled stories"
c.option "--add-doc-checklists", "Add documentation team tasks"
c.option "--add-doc-cards", "Add documentation cards for documentation labeled dev cards"
c.option "--update-bug-tasks", "Update closed/verified bug tasks"
c.option "--update-roadmap", "Update the roadmap board with progress from teams"
c.description = "An assortment of Trello modification utilities"
c.action do |args, options|
doc_descriptions = []
if options.update_roadmap
tag_to_epics = trello.tag_to_epics
trello.roadmap_boards.each do |roadmap_board|
epic_list = trello.epic_list(roadmap_board)
tag_to_epic = {}
epic_list.cards.each do |epic_card|
epic_card.name.scan(/\[[^\]]+\]/).each do |tag|
if tag != FUTURE_TAG
tag_to_epic[tag] = epic_card
end
end
end
puts 'Tags:'
puts tag_to_epic.keys.pretty_inspect
epic_stories_by_epic = {}
(1..2).each do |accepted_pass|
trello.boards.each do |board_id, board|
if roadmap_board.prefs['permissionLevel'] == 'org' || roadmap_board.prefs['permissionLevel'] == board.prefs['permissionLevel']
puts "\nBoard Name: #{board.name}"
all_lists = trello.target(board.lists(:filter => [:all]))
new_list = nil
backlog_list = nil
next_list = nil
in_progress_list = nil
docs_underway_list = nil
complete_list = nil
accepted_list = nil
previous_sprint_lists = []
other_lists = []
all_lists.each do |l|
case l.name
when 'New'
new_list = l
when 'Backlog'
backlog_list = l
when 'Next'
next_list = l
when 'In Progress'
in_progress_list = l
when 'Complete'
complete_list = l
when 'Docs Underway'
docs_underway_list = l
when 'Accepted'
accepted_list = l
when /^Sprint \d+/
previous_sprint_lists << l
else
other_lists << l
end
end
i = 0
lists = []
[accepted_list, complete_list, in_progress_list, next_list, backlog_list, new_list].each do |l|
if !l.nil?
lists[i] = l
i += 1
end
end
previous_sprint_lists = previous_sprint_lists.sort_by { |l| l.name.match('^Sprint (\d+)')[1].to_i }
lists += previous_sprint_lists
lists += other_lists
lists.each do |list|
accepted = (list.name.match('^Sprint \d+') || list.name == 'Accepted') ? true : false
next if (accepted && accepted_pass == 1) || (!accepted && accepted_pass == 2)
cards = trello.list_cards(list)
if !cards.empty?
puts "\n List: #{list.name} (#cards: #{cards.length})"
cards.each_with_index do |card, index|
card_tags = card.name.scan(/\[[^\]]+\]/)
future = card_tags.include?(FUTURE_TAG) ? FUTURE_EPIC_REFERENCED_STORIES_NAME : EPIC_REFERENCED_STORIES_NAME
card_tags.each do |card_tag|
epic = tag_to_epic[card_tag]
if epic
if (roadmap_board.prefs['permissionLevel'] == 'org' && tag_to_epics[card_tag].length == 1) || (roadmap_board.prefs['permissionLevel'] == board.prefs['permissionLevel'])
epic_stories_by_epic[epic.id] = [] unless epic_stories_by_epic[epic.id]
epic_stories_by_epic[epic.id] << [epic, card, list, board, future, accepted]
end
end
end
end
end
end
end
end
end
epic_list.cards.each do |epic_card|
unless epic_stories_by_epic[epic_card.id]
clear_epic_refs(epic_card, trello)
end
end
epic_stories_by_epic.each_value do |epic_stories|
first_epic_story = epic_stories.first
if first_epic_story
clear_epic_refs(first_epic_story[0], trello)
puts "\nAdding cards to #{first_epic_story[0].name}:"
epic_stories.each do |epic_story|
epic = epic_story[0]
card = epic_story[1]
list = epic_story[2]
board = epic_story[3]
future = epic_story[4]
accepted = epic_story[5]
stories_checklist = trello.checklist(epic, future)
if stories_checklist
puts "Adding #{card.url}"
(1..3).each do |i|
begin
stories_checklist.add_item("[#{card.name}](#{card.url}) (#{list.name}) (#{board.name})", accepted, 'bottom')
break
rescue => e
puts "Error adding checklist: #{e.message}"
raise if i == 3
end
end
end
end
end
end
end
end
if options.add_doc_checklists || options.add_doc_cards
lists = trello.target(trello.documentation_board.lists(:filter => [:open]))
lists.each do |list|
cards = trello.list_cards(list)
if !cards.empty?
puts "\n List: #{list.name} (#cards #{cards.length})"
cards.each_with_index do |card, index|
if !(card.name =~ /^Sprint \d+/ && !card.due.nil?)
doc_descriptions << card.desc if options.add_doc_cards
if options.add_doc_checklists
checklists = []
checklists << 'Tasks'
trello.list_checklists(card).each do |checklist|
checklists.delete(checklist.name)
break if checklists.empty?
end if !checklists.empty?
if !checklists.empty?
puts "Adding #{checklists.pretty_inspect.chomp} to #{card.name}"
checklists.each do |checklist_name|
checklist = Trello::Checklist.create({:name => checklist_name, :board_id => trello.documentation_id})
card.add_checklist(checklist)
end
end
end
end
if options.add_doc_checklists
tasks_checklist = trello.checklist(card, 'Tasks')
if tasks_checklist
urh_reminder = "Update Revision History"
found = false
tasks_checklist.items.each do |item|
if item.name.include? urh_reminder
found = true
break
end
end
unless found
puts "Adding revision history reminder: #{card.name}"
tasks_checklist.add_item(urh_reminder, false, 'bottom')
end
end
end
end
end
end
end
if options.add_task_checklists || options.add_bug_checklists || options.update_bug_tasks || options.add_doc_tasks || options.add_doc_cards
bugzilla = nil
if options.update_bug_tasks
require 'bugzilla_helper'
bugzilla = load_conf(BugzillaHelper, CONFIG.bugzilla, true)
end
if options.add_doc_cards && (trello.documentation_board.id != trello.docs_planning_board.id)
lists = trello.target(trello.docs_planning_board.lists(:filter => [:open]))
lists.each do |list|
cards = trello.list_cards(list)
if !cards.empty?
cards.each_with_index do |card, index|
doc_descriptions << card.desc
end
end
end
end
trello.boards.each do |board_id, board|
puts "\nBoard Name: #{board.name}"
lists = trello.target(board.lists(:filter => [:open]))
lists.each do |list|
if list.name == 'In Progress' || list.name == 'Complete' || list.name == 'Docs Underway'
cards = trello.list_cards(list)
if !cards.empty?
puts "\n List: #{list.name} (#cards #{cards.length})"
cards.each_with_index do |card, index|
if options.add_task_checklists || options.add_bug_checklists || options.add_doc_cards
if !(card.name =~ /^Sprint \d+/ && !card.due.nil?)
labels = trello.card_labels(card)
checklists = []
checklists << 'Tasks' if options.add_task_checklists
checklists << 'Bugs' if options.add_bug_checklists && !labels.map{|x| x.name }.include?('no-qe')
if options.add_doc_cards && labels.map{|x| x.name }.include?('documentation') && doc_descriptions.any?
found = false
doc_descriptions.each do |desc|
if desc.include?(card.short_url)
found = true
break
end
end
unless found
name = card.name
if card.name =~ /\((\d+|\?)\)(.*)/
name = $2.strip
end
c = Trello::Card.create(:name => "Document: #{name}", :desc => "Corresponding Development Card: #{card.short_url}", :list_id => trello.documentation_next_list.id)
end
end
trello.list_checklists(card).each do |checklist|
checklists.delete(checklist.name)
break if checklists.empty?
end if !checklists.empty?
if checklists.any?
puts "Adding #{checklists.pretty_inspect.chomp} to #{card.name}"
checklists.each do |checklist_name|
checklist = Trello::Checklist.create({:name => checklist_name, :board_id => board.id})
card.add_checklist(checklist)
end
end
end
end
if options.update_bug_tasks
['Bugs', 'Tasks'].each do |cl|
bugs_checklist = trello.checklist(card, cl)
if bugs_checklist
bugs_checklist.items.each do |item|
item_name = item.name.strip
if item_name =~ /(https?:\/\/bugzilla\.redhat\.com\/[^\?]+\?id=\d+)/
bug_url = $1
status = bugzilla.bug_status_by_url(bug_url)
if status == 'VERIFIED' || status == 'CLOSED'
if item.state == 'incomplete'
puts "Marking complete: #{item_name}"
bugs_checklist.add_item(item_name, true, 'bottom')
bugs_checklist.delete_checklist_item(item.id)
end
elsif status == 'OPEN' || status == 'ASSIGNED'
if item.state == 'complete'
puts "Marking incomplete: #{item_name}"
bugs_checklist.add_item(item_name, false, 'top')
bugs_checklist.delete_checklist_item(item.id)
end
end
end
end
end
end
end
if options.add_doc_tasks
if trello.card_labels(card).map{|label| label.name }.include?("documentation")
tasks_checklist = trello.checklist(card, 'Tasks')
if tasks_checklist
doc_reminder = "Update this card (in the description or in a comment) with details about what needs to be documented. For subjects that have corresponding engineering owned documentation, a pointer to that documentation should suffice."
found = false
tasks_checklist.items.each do |item|
if item.name.include? doc_reminder
found = true
break
end
end
unless found
puts "Adding documentation reminder: #{card.name}"
tasks_checklist.add_item(doc_reminder, false, 'bottom')
end
end
end
end
end
end
end
end
end
end
end
end