forked from goborrega/TrelloToAsana
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexportTrelloToAsana.rb
147 lines (112 loc) · 3.51 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/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_API_KEY = cnf['asana']['api_key']
ASANA_ASSIGNEE = 'me'
def get_option_from_list(list, title, attribute)
i=0
while i == 0 do
puts title
list.each do |item|
i += 1
puts " #{i}) #{item.send(attribute)}"
end
i = gets.chomp.to_i
i = 0 if i <= 0 && i > list.size
end
return i - 1
end
Trello.configure do |config|
config.developer_public_key = TRELLO_DEVELOPER_PUBLIC_KEY
config.member_token = TRELLO_MEMBER_TOKEN
end
Asana.configure do |client|
client.api_key = ASANA_API_KEY
end
workspaces = Asana::Workspace.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 = workspaces[get_option_from_list(workspaces,
"Select destination workplace",
"name")]
puts "Using workspace #{workspace.name}"
# Which project to associate
project = workspace.projects[get_option_from_list(workspace.projects,
"Select destination project",
"name")]
puts " -- Using project #{project.name} --"
puts ' -- Getting users --'
users = workspace.users
trello_members = Trello::Organization.find("labcoop").members
board.lists.each do |list|
puts " - #{list.name}:"
list.cards.reverse.each do |card|
puts " - Card #{card.name}, Due on #{card.due}"
# Create the task
t = Asana::Task.new
t.name = card.name
t.notes = card.desc
t.due_on = card.due.to_date if !card.due.nil?
# Assignee - Try to find by name. Otherwise will be empty
t.assignee = nil
if !card.member_ids.empty? then
userList = users.select { |u|
u.name == card.members[0].full_name
}
t.assignee = userList[0].id unless userList.empty?
member_names = card.member_ids.map { |member_id|
idx = trello_members.index { |m|
m.id == member_id
}
name = nil
if idx != nil
name = trello_members[idx].full_name
end
name
}
trello_member_names = member_names.join(", ")
t.notes = "Trello members: #{trello_member_names}\n\n#{t.notes}"
end
task = workspace.create_task(t.attributes)
#Project
task.add_project(project.id)
#Stories / Trello comments
comments = card.actions.select {|a| a.type == 'commentCard'}.reverse
comments.each do |c|
idx = trello_members.index { |m|
m.id == c.member_creator_id
}
commenter_name = '?'
if idx != nil
commenter_name = trello_members[idx].full_name
end
task.create_story({:text => "#{commenter_name} commented:\n #{c.data['text']}"})
end
#Subtasks
card.checklists.each do |checklist|
checklist.check_items.each do |checkItem|
st = Asana::Task.new
st.name = checkItem['name']
st.assignee = nil
task.create_subtask(st.attributes)
end
end
end
# Create each list as an aggregator if it has cards in it
if !list.cards.empty? then
task = workspace.create_task({name: "#{list.name}:", assignee: nil})
task.add_project(project.id)
end
end
end