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
import json | |
import urlparse | |
import requests | |
from storyboardclient.v1 import client | |
# Trello Constants | |
TRELLO_BOARD_ID = 'TRELLOBOARD_ID' | |
TRELLO_BOARD_JSON = requests.get( | |
'https://api.trello.com/1/boards/{}/lists'.format(TRELLO_BOARD_ID) | |
).json() | |
TRELLO_COLUMN_IDS = set([i['id'] for i in TRELLO_BOARD_JSON]) | |
TRELLO_COLUMNS_HASH = dict( | |
[(i, requests.get('https://api.trello.com/1/lists/{}'.format(i)).json()['name']) | |
for i in TRELLO_COLUMN_IDS] | |
) | |
TRELLO_CARD_HASH = dict( | |
[(i, requests.get('https://api.trello.com/1/lists/{}/cards'.format(i)).json()) | |
for i in TRELLO_COLUMN_IDS] | |
) | |
# Trello and Storyboard compatibility map | |
TRELLO_TO_STORYBOARD_STATUS_MAP = { | |
'incomplete': 'todo', | |
'complete': 'merged' | |
} | |
# Storyboard constants | |
STORYBOARD_API_URL = "https://storyboard.openstack.org/api/v1" | |
STORYBOARD_ACCESS_TOKEN = "TOKEN_STRING" | |
STORYBOARD_WORKBOARD = "TripleO-Ansible Transformation" | |
STORYBOARD_PROJECT_NAME = 'openstack/tripleo-ansible' | |
STORYBOARD_CLIENT = client.Client(STORYBOARD_API_URL, STORYBOARD_ACCESS_TOKEN) | |
STORYBOARD_PROJECT = [ | |
i for i in STORYBOARD_CLIENT.projects.list() | |
if i.name == STORYBOARD_PROJECT_NAME | |
][0] | |
STORYBOARD_API_WORKLISTS_URL = urlparse.urljoin(STORYBOARD_API_URL, '/api/v1/worklists') | |
STORYBOARD_API_BOARDS_URL = urlparse.urljoin(STORYBOARD_API_URL, '/api/v1/boards') | |
STORYBOARD_TASK_HASH = dict() | |
STORYBOARD_HEADERS = { | |
'Authorization': 'Bearer {}'.format(STORYBOARD_ACCESS_TOKEN), | |
'Content-Type': 'application/json;charset=UTF-8' | |
} | |
# Run card to story import | |
for cards in TRELLO_CARD_HASH.values(): | |
for card in cards: | |
story = STORYBOARD_CLIENT.stories.create(title=card['name'], description=card['desc']) | |
print('Story ID "{}" has been created'.format(story.id)) | |
task_ids = STORYBOARD_TASK_HASH[story.id] = card['idList'] | |
for checklist in card['idChecklists']: | |
print('Importing trello checklist "{}" into story'.format(checklist)) | |
for item in requests.get('https://api.trello.com/1/checklists/{}'.format(checklist)).json()['checkItems']: | |
task_ids.append( | |
STORYBOARD_CLIENT.tasks.create( | |
title=item['name'], | |
project_id=STORYBOARD_PROJECT.id, | |
story_id=story.id, | |
status=TRELLO_TO_STORYBOARD_STATUS_MAP[item['state']] | |
).id | |
) | |
print('imported story - "{}"'.format(card['name'])) | |
# Run column to lane import | |
STORYBOARD_WORKLIST_IDS = list() | |
for trello_k, trello_v in TRELLO_COLUMNS_HASH.items(): | |
worklist = STORYBOARD_CLIENT.worklists.create(title=trello_v, automatic=False) | |
STORYBOARD_WORKLIST_IDS.append(worklist.id) | |
print('created worklist "{}"'.format(worklist.id)) | |
for storyboard_k, storyboard_v in STORYBOARD_TASK_HASH.items(): | |
if trello_k == storyboard_v: | |
requests.post( | |
STORYBOARD_API_WORKLISTS_URL + '/{}/items'.format(worklist.id), | |
data=json.dumps({ | |
'item_id': storyboard_k, | |
'item_type': "story", | |
'list_position': 0 | |
}), | |
headers=STORYBOARD_HEADERS | |
) | |
print('Story "{}" assigned to worklist {}'.format(storyboard_k, worklist.id)) | |
requests.post( | |
STORYBOARD_API_BOARDS_URL, | |
data=json.dumps({ | |
"title": STORYBOARD_WORKBOARD, | |
"lanes": [dict(list_id=v, position=k) for k,v in enumerate(STORYBOARD_WORKLIST_IDS)] | |
}), | |
headers=STORYBOARD_HEADERS | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment