class TrelloChangelog
Public Class Methods
new(options)
click to toggle source
# File lib/trello-changelog.rb, line 8 def initialize(options) @options = options.with_indifferent_access load_config_file configure_trello start_date(@options[:start_date]) end
Public Instance Methods
archived_done_tickets()
click to toggle source
# File lib/trello-changelog/tickets.rb, line 24 def archived_done_tickets @archived_done_tickets ||= board.cards( { filter: :all } ).select { |card| card.creation_date >= start_date }.select { |card| card.list_id == done_list.id }.select { |card| card.closed == true } end
archived_tickets()
click to toggle source
# File lib/trello-changelog/tickets.rb, line 20 def archived_tickets @archived_tickets ||= board.cards( { filter: :all } ).select { |card| card.creation_date >= start_date }.select { |card| card.closed == true } - archived_done_tickets end
archived_tickets_count()
click to toggle source
# File lib/trello-changelog/tickets.rb, line 36 def archived_tickets_count archived_tickets.count end
board()
click to toggle source
# File lib/trello-changelog/tickets.rb, line 4 def board @board ||= Trello::Board.find(@config[:board]) end
build_labels()
click to toggle source
# File lib/trello-changelog/printers.rb, line 27 def build_labels for label_name in @config[:labels] do tickets_label_name = done_tickets.select { |ticket| ticket.labels.select { |label| label.name == label_name}.count > 0 } @output << "\n## #{label_name}:\n\n" tickets_label_name.each do |ticket| @output << " * [#{ticket.name}](#{ticket.url})\n" end @output << 'n.a.' if tickets_label_name.count == 0 end end
build_output()
click to toggle source
# File lib/trello-changelog/printers.rb, line 8 def build_output @output = "" build_summary build_labels build_unlabeled @output end
build_summary()
click to toggle source
# File lib/trello-changelog/printers.rb, line 17 def build_summary @output << "# Start date: #{start_date}\n\n" @output << "Created Trello items since #{start_date}: #{new_tickets_count}\n\n" @output << "Finished Trello items since #{start_date}: #{done_tickets_count}\n\n" @output << "Archived Trello items since #{start_date}: #{archived_tickets_count}\n\n" @output << "Summary: #{new_tickets_count} tickets in, #{done_tickets_count + archived_tickets_count} tickets out\n\n" end
build_unlabeled()
click to toggle source
# File lib/trello-changelog/printers.rb, line 38 def build_unlabeled # We only list the cards that have none of the configured labels @unlabeled_done_tickets = done_tickets.select { |ticket| (ticket.labels.map(&:name) & @config[:labels]).empty? } @output << "\n## Other\n\n" @unlabeled_done_tickets.each do |ticket| @output << " * [#{ticket.name}](#{ticket.url})\n" end end
done_list()
click to toggle source
# File lib/trello-changelog/tickets.rb, line 8 def done_list @done_list ||= board.lists.select { |list| list.name == @config[:done_list_name] }.last end
done_tickets()
click to toggle source
# File lib/trello-changelog/tickets.rb, line 16 def done_tickets @done_tickets ||= board.cards.select { |card| card.list_id == done_list.id } end
done_tickets_count()
click to toggle source
# File lib/trello-changelog/tickets.rb, line 32 def done_tickets_count done_tickets.count end
new_tickets()
click to toggle source
# File lib/trello-changelog/tickets.rb, line 12 def new_tickets @new_tickets ||= board.cards.select { |card| card.creation_date >= start_date} end
new_tickets_count()
click to toggle source
# File lib/trello-changelog/tickets.rb, line 28 def new_tickets_count new_tickets.count end
print()
click to toggle source
# File lib/trello-changelog/printers.rb, line 4 def print puts build_output end
Private Instance Methods
configure_trello()
click to toggle source
# File lib/trello-changelog/config.rb, line 24 def configure_trello Trello.configure do |trello_config| trello_config.developer_public_key = @config[:devkey] trello_config.member_token = @config[:mem_token] end end
load_config_file()
click to toggle source
# File lib/trello-changelog/config.rb, line 4 def load_config_file @config = HashWithIndifferentAccess.new(labels: []) if %w(devkey mem_token board done_list_name).all? { |key| @options.has_key?(key) } puts "Config set via cli, ~/.trello-changelog.rb not loaded" @options.each { |key, value| @config[key] = value } return true end begin require '~/.trello-changelog.rb' @config[:devkey] = Variables::DEVKEY @config[:mem_token] = Variables::MEM_TOKEN @config[:board] = Variables::BOARD @config[:done_list_name] = Variables::DONE_LIST_NAME @config[:labels] = Variables::LABELS || [] rescue LoadError puts 'File: ".trello-changelog.rb" was not found in your home directory! See README on Github.' exit end end
start_date(start_date=@start_date)
click to toggle source
# File lib/trello-changelog/config.rb, line 31 def start_date(start_date=@start_date) @start_date ||= \ if(start_date == nil) Date.today - 6 else begin Date.parse(start_date) rescue ArgumentError puts 'The start date syntax is wrong. Possible correct syntax are:'\ 'YYYY-MM-DD, DD-MM-YYYY, YYYY/MM/DD, DD/MM/YYYY, ... . Please try again.' exit end end end