Skip to content

Instantly share code, notes, and snippets.

@paulmooring
Created February 12, 2014 20:30
Show Gist options
  • Save paulmooring/8963906 to your computer and use it in GitHub Desktop.
Save paulmooring/8963906 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'json'
require 'leankitkanban'
require 'trello'
require 'pp'
require 'pry'
def get_json_card(card)
card[:name] = "From Trello" unless card.key? :name
card[:desc] = "No description" unless card.key? :desc
raise ArgumentError, "':type_id' is required for method `get_json_card`" unless card.key? :type_id
card[:sev_id] = 1 unless card.key? :sev_id
card[:due] = Date.today.next_week unless card.key? :due
card[:cos] = '' unless card.key? :cos
card[:id] = 0 unless card.key? :id
"{\"Title\":\"#{card[:name]}\",\"Description\":\"#{card[:desc]}\"," +
"\"TypeId\":#{card[:type_id]},\"Priority\":#{card[:sev_id]},\"Size\":1," +
"\"IsBlocked\":false,\"BlockReason\":\"\",\"DueDate\":" +
"\"#{card[:due].mday}/#{card[:due].mon}/#{card[:due].year}\"," +
"\"ExternalSystemName\":\"Trello\",\"ExternalSystemUrl\":\"http://trello.com\"," +
"\"Tags\":\"Trello\",\"ClassOfServiceID\":\"#{card[:cos]}\"," +
"\"ExternalCardID\":\"#{card[:id]}\"}"
end
def get_identifiers(board)
if @lk_board_ident.nil?
board_identifiers = LeanKitKanban::Board.get_identifiers(board['Id']).first
identifiers = Hash.new
identifiers[:types] = Hash.new
identifiers[:sever] = Hash.new
identifiers[:class] = Hash.new
board_identifiers["CardTypes"].each do |type|
name = type['Name'].downcase
identifiers[:types][name] = type['Id']
end
board_identifiers["Priorities"].each do |sev|
name = sev['Name'].downcase
identifiers[:sever][name] = sev['Id']
end
board_identifiers["ClassesOfService"].each do |cos|
name = cos['Name'].downcase
identifiers[:class][name] = cos['Id']
end
@lk_board_ident = identifiers
end
@lk_board_ident
end
def lane_maps
@lane_maps ||= {
@trello_lanes['IT OPS Backlog'] => nil,
@trello_lanes['OPS Backlog'] => nil,
@trello_lanes['Gathering Requirements (4)'] => @lk_lanes['Gathering'],
@trello_lanes['Requirements Gathered (shared w/ Gathering)'] => @lk_lanes['Ready'],
@trello_lanes['In Progress (6)'] => @lk_lanes['In Progress'],
@trello_lanes['Done'] => @lk_lanes['Done']
}
end
def trello_to_lk(trello_card, trello_board, lk_board)
date = trello_card.due.nil? ? Date.today.next_week : trello_card.due.to_date
card_json = get_json_card({
:name => trello_card.name,
:desc => trello_card.desc,
:type_id => get_identifiers(lk_board)[:types]['project'],
:due => date,
:cos => get_identifiers(lk_board)[:class]['standard'],
:id => trello_card.id
})
puts "LeanKitKanban::Card.add(#{lk_board['Id']}, #{lane_maps[trello_card.list_id]}, 1, #{card_json})"
binding.pry
end
config = JSON.parse(File.read("#{File.dirname(__FILE__)}/config"))
LeanKitKanban::Config.email = config['leankit']['email']
LeanKitKanban::Config.password = config['leankit']['password']
LeanKitKanban::Config.account = config['leankit']['account']
# Redefining constants is dangerous, blah blah blah...
original_verb = $VERBOSE
$VERBOSE = nil
Trello::Authorization.send(:remove_const, :AuthPolicy)
Trello::Authorization.const_set :AuthPolicy, Trello::Authorization::OAuthPolicy
$VERBOSE = original_verb
trello_cred = Trello::Authorization::OAuthCredential.new config['trello']['dev_public_key']
Trello::Authorization::OAuthPolicy.consumer_credential = trello_cred
Trello::Authorization::OAuthPolicy.token = Trello::Authorization::OAuthCredential.new config['trello']['access_token_key'], nil
lk_board = LeanKitKanban::Board.find( LeanKitKanban::Board.all.first.select do |board|
board['Title'] == "Ops"
end.first['Id'] ).first
@lk_lanes = Hash.new
lk_board['Lanes'].each {|lane| @lk_lanes[lane['Title']] = lane['Id']}
trello_board = Trello::Board.all.select {|b| b.name == "Ops Projects"}.first
trello_cards = trello_board.cards
@trello_lanes = Hash.new
trello_board.lists.each{|list| @trello_lanes[list.id] = list.name}
#trello_cards.each do |card|
# puts trello_to_json(card, lk_board)
#end
trello_to_lk(trello_cards.first, trello_board, lk_board)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment