Skip to content

Instantly share code, notes, and snippets.

@rjmackay
Created November 18, 2014 20:39
Show Gist options
  • Save rjmackay/2c310294d1b8ddce6c00 to your computer and use it in GitHub Desktop.
Save rjmackay/2c310294d1b8ddce6c00 to your computer and use it in GitHub Desktop.
Milestone Board
phabricator==0.4.0
trello==0.9.1
from phabricator import Phabricator
phab = Phabricator()
phab.update_interfaces()
print "Fetching tasks from Phab"
tasks = phab.maniphest.query(projectPHIDs=['PHID-PROJ-rbdn2wck434bye3sjpxc'], status="status-open", limit=3000)
milestones = []
for key in tasks:
task = tasks[key]
#print task['auxiliary']['std:maniphest:ushahidi:task-type'], task['dependsOnTaskPHIDs']
if task['auxiliary']['std:maniphest:ushahidi:task-type'] == 'milestone':
milestones.append(key)
from trello import TrelloApi
#app_key = ''
#token = ''
trello = TrelloApi(app_key, token)
board_id = '546ac22c6578432992606651'
board = trello.boards.get(board_id)
print "Fetching lists from Trello"
tlists = {tl['name'] : tl['id'] for tl in trello.boards.get_list(board_id)}
print "Processing Milestones"
for key in milestones:
milestone = tasks[key]
list_title = milestone['title']
print "Milestone", list_title
# Does the milestone have dependencies?
if len(milestone['dependsOnTaskPHIDs']) > 0:
# Find or create a matching list
if list_title in tlists:
list_id = tlists[list_title]
else:
tlist = trello.boards.new_list(board_id, list_title)
tlists[tlist['name']] = tlist['id']
list_id = tlist['id']
cards = {tl['name'] : tl['id'] for tl in trello.lists.get_card(list_id)}
for phid in milestone['dependsOnTaskPHIDs']:
if phid in tasks:
task = tasks[phid]
card_name = u'{}: {}'.format(task['objectName'], task['title'])
# Is this a new card?
if card_name not in cards:
trello.lists.new_card(list_id, card_name,
u"{0}\n\n{1}".format(task['description'], task['uri'])
)
# or an existing card
else:
# @todo update card
del cards[card_name]
# Remove extra cards
for card in cards:
trello.cards.delete(cards[card])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment