This repository has been archived by the owner on Aug 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexporter.py
65 lines (50 loc) · 2.48 KB
/
exporter.py
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
import os, sys, requests, time
import utils as utils
from models.issue import Issue
def show_findings(labels, milestones, columns, opened, closed):
print(" Found {:4d} active label(s)".format(len(labels)))
print(" Found {:4d} milestone(s)".format(len(milestones)))
print(" Found {:4d} active columns(s)".format(len(columns)))
print(" Found {:4d} open issue(s)".format(len(opened)))
print(" Found {:4d} closed issue(s)".format(len(closed)))
def export_trello(config, boards, out_path):
print("Exporting boards from Trello...")
exported = []
params = {'key': config['key'], 'token': config['token']}
for board in boards:
print(" Exporting board '{}'...".format(board['name']))
board_url = "{}/boards/{}".format(config['url'], board['id']['trello'])
resp_board = requests.get(board_url, params=params).json()
labels = []
resp_labels = requests.get(board_url + "/labels", params=params).json()
for l in [x for x in resp_labels if x['id'] != '']:
labels.append({k: l[k] for k in ['name','id','color'] if k in l})
resp_cols = requests.get(board_url + "/lists", params=params).json()
columns = [{'name': c['name'], 'id': c['id']} for c in resp_cols if not c['closed']]
milestones = [] # trello has no milestones. See misc/approx_milestones.py
opened = requests.get(board_url, params={**params, **{"cards":"visible"}}).json()["cards"]
closed = requests.get(board_url, params={**params, **{"cards":"closed"}}).json()["cards"]
show_findings(labels, [], columns, opened, closed)
issues = []
[issues.append(Issue(o, 'trello').__dict__) for o in opened]
[issues.append(Issue(c, 'trello').__dict__) for c in closed]
exported.append({
'name': board['name'],
'id': resp_board['id'],
'labels': labels,
'milestones': milestones,
'columns': columns,
'issues': issues
})
return exported
def main():
exported = {}
config = utils.read_file_json("./config.json")
boards, out_path = config['boards'], config['export']
target = 'trello' # TODO: Make CLI
if target == 'trello':
exported = export_trello(config['trello'], boards, out_path)
else:
raise Exception("Unsupported target '{}'".format(target))
utils.write_file_json("{}{}export.json".format(out_path, os.sep), exported)
if __name__ == "__main__":main()