-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathexportTrelloToAsana.rb
executable file
·127 lines (95 loc) · 3.01 KB
/
exportTrelloToAsana.rb
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
#!/usr/bin/env ruby
require "rubygems"
require 'trello'
require 'asana'
require 'yaml'
cnf = YAML::load(File.open('config.yml'))
# Trello keys
TRELLO_DEVELOPER_PUBLIC_KEY = cnf['trello']['developer_public_key']
TRELLO_MEMBER_TOKEN = cnf['trello']['member_token']
# Asana keys
ASANA_TOKEN = cnf['asana']['personal_token']
ASANA_ASSIGNEE = 'me'
def get_option_from_list(list, title, attribute)
i=0
arr = Array.new
while i == 0 do
puts title
list.each do |item|
i += 1
puts " #{i}) #{item.send(attribute)}"
arr << item
end
i = gets.chomp.to_i
i = 0 if i <= 0 && i > list.size
end
return arr[i - 1]
end
Trello.configure do |config|
config.developer_public_key = TRELLO_DEVELOPER_PUBLIC_KEY
config.member_token = TRELLO_MEMBER_TOKEN
end
client = Asana::Client.new do |c|
c.authentication :access_token, ASANA_TOKEN
end
workspaces = client.workspaces.find_all
boards = Trello::Board.all
boards.each do |board|
next if board.closed?
puts "\n=== Export Board #{board.name}? [yn]"
next unless gets.chomp == 'y'
# Which workspace to put it in
workspace = get_option_from_list(workspaces,
"Select destination workplace",
"name")
puts "Using workspace #{workspace.name}"
# Which project to associate
projects = client.projects.find_by_workspace(workspace: workspace.id)
project = get_option_from_list(projects,
"Select destination project",
"name")
puts " -- Using project #{project.name} --"
puts ' -- Getting users --'
users = Array.new
users = client.users.find_all(workspace: workspace.id).take(1000) if workspace.name != "Personal Projects"
board.lists.each do |list|
puts " - #{list.name}:"
list.cards.reverse.each do |card|
puts " - Card #{card.name}, Due on #{card.due}"
# Assignee - Try to find by name. Otherwise will be empty
assignee = "me"
if !card.member_ids.empty? then
userList = users.select { |u|
u.name == card.members[0].full_name
}
assignee = userList[0].id unless userList.empty?
end
due_on = card.due.to_date if !card.due.nil?
# Create the task
task = client.tasks.create(workspace: workspace.id,
name: card.name,
notes: card.desc,
due_on: due_on,
assignee: assignee)
#Project
task.add_project(project: project.id)
#Stories / Trello comments
comments = card.actions.select {|a| a.type == 'commentCard'}
comments.each do |c|
task.add_comment(text: c.data['text'])
end
#Subtasks
card.checklists.each do |checklist|
checklist.check_items.each do |checkItem|
task.add_subtask(name: checkItem['name'], completed: checkItem['state'] == "complete")
end
end
end
# Create each list as an aggregator if it has cards in it
if !list.cards.empty? then
task = client.tasks.create(workspace: workspace.id,
name: "#{list.name}:")
task.add_project(project: project.id)
end
end
end