Last active
April 18, 2017 13:26
-
-
Save dgilperez/9d29f31b524623ecbfbfaa6b106a8aa2 to your computer and use it in GitHub Desktop.
Taiga to Trello - ruby script to import Taiga cards into Trello
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'trello' | |
# Trello.open_public_key_url # copy your public key | |
# Trello.open_authorization_url key: 'yourpublickey' # copy your member token | |
Trello.configure do |config| | |
config.developer_public_key = 'your_public_key' # The "key" from step 1 | |
config.member_token = 'your_member_token' # The token from step 3. | |
end | |
# Locate your board_id to import cards into. | |
# Trello::Board.all.reject(&:closed?).map {|a| [a.id, a.name]} | |
board_id = 'XXXXX' | |
# get some list ids - in this case a Kanban board: | |
# Trello::Board.find(board_id).lists.map {|a| [a.id, a.name]} | |
def backlog_id; 'XXX'; end | |
def testing_id; 'XXX'; end | |
def done_id; 'XXX'; end | |
# Import JSON cards from Taiga. | |
# Asumes you have exported cards from Taiga into a file named taiga_cards.json located in the same folder as this script. | |
file = File.read('./taiga_cards.json') | |
data_hash = JSON.parse(file) | |
cards = data_hash['user_stories'] | |
# adjust attributes to import at will | |
valid_keys = %w(tags status role_points subject description attachments) | |
label_names = cards.map{ |card| card['tags'] }.map{ |tag| JSON.parse(tag) }.flatten.compact.uniq | |
label_names.each do |label_name| | |
Trello::Label.create(name: label_name, board_id: board_id, color: Trello::Label.label_colours.sample) | |
end | |
trello_labels = Trello::Board.find(board_id).labels.map { |label| [label.id, label.name] } | |
cards.each do |card| | |
card_attributes = card.slice(*valid_keys) | |
list_id = list_id_for_status card_attributes['status'] | |
tags = JSON.parse(card_attributes['tags']) | |
labels_list = tags.map{|tag| label_for_name(tag, trello_labels)}.join(',') | |
Trello::Card.create( | |
name: card_attributes['subject'], | |
list_id: list_id, | |
desc: card_attributes['description'], | |
card_labels: labels_list | |
) | |
end | |
def list_id_for_status(status) | |
case status | |
when 'Done' | |
done_id | |
when 'Ready for test' | |
testing_id | |
else | |
backlog_id | |
end | |
end | |
def label_for_name(name, labels) | |
labels.detect{|label| label[1] == name}[0] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment