Created
August 1, 2018 14:41
-
-
Save rbrady/a1d1151ef7cdd56c56abc64357ceb195 to your computer and use it in GitHub Desktop.
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 itertools | |
import sys | |
from filch import boards | |
from filch import configuration | |
from filch import constants | |
from filch import data | |
from filch import exceptions as peeves | |
BOARD_NAME = "Workflows-DFG-Rocky" | |
DEBUG = True | |
def check_source(card): | |
# get fields dict | |
fields = {field.name: field.value for field in card.customFields} | |
return fields.get('source', None) | |
def find_card_source(card): | |
source = card.desc.split('source: ')[1].strip().split('|') | |
if source: | |
if source[0] == 'bz': | |
# handle for bz | |
return 'https://bugzilla.redhat.com/show_bug.cgi?id=%s' % source[1] | |
elif source[0] == 'bp': | |
# handle for blueprint | |
return card.desc.split('blueprint_url: ')[1].split('spec:')[0] | |
elif source[0] == 'bug': | |
# handle for bug | |
return 'https://bugs.launchpad.net/bugs/%s' % source[1] | |
else: | |
return None | |
if __name__ == '__main__': | |
try: | |
config = configuration.get_config() | |
except Exception as err: | |
print(err) | |
sys.exit(1) | |
board_manager = boards.BoardManager(config['trello'], BOARD_NAME) | |
board_fields = board_manager.get_custom_fields() | |
source_field_id = [d for d in board_fields if d['name'] == 'source'][0][ | |
'id'] | |
lists = [item for item in board_manager.board.open_lists() if | |
item.name in ['Bugs', 'Features', 'In Progress', 'Complete']] | |
for listitem in lists: | |
for card in listitem.list_cards(): | |
if not check_source(card): | |
card_source = find_card_source(card) | |
if DEBUG: | |
print('Adding %s to %s' % (card_source, card.shortUrl)) | |
else: | |
board_manager.set_custom_field( | |
card.id, source_field_id, {'text': card_source}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment