Created
August 13, 2015 00:02
-
-
Save judell/7b8334da209a7561e0e3 to your computer and use it in GitHub Desktop.
trello / github
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 requests, json, re | |
backlog_triage_list = '55c39b276b173fdfaef897f1' | |
backlog_not_prioritized_list = '55a3fb6903a766588973e8c5' | |
backlog_backlog_list = '55796ed5c0e8c6a2f25dba6e' | |
sprint_up_next = '557936eed7f9bf6d2dd1521e' | |
sprint_in_progress = '5578c7a3f955667e94879086' | |
sprint_deployed = '555cab97ea82d6a4151b7f92' | |
sprint_delivered = '555cb1ea055301c6f20e50df' | |
#url = 'https://trello.com/1/authorize?key=%s&name=Hypothesis&expiration=never&response_type=token&scope=read,write' % key | |
def get_github_issues(): | |
gh_nums = get_github_nums_from_trello_cards() | |
labels = ['P2','P3'] | |
for label in labels: | |
url = 'https://api.github.com/repos/hypothesis/h/issues?labels=' + label | |
r = requests.get(url) | |
j = json.loads(r.text) | |
for issue in j: | |
gh_num = str(issue['number']) | |
if gh_num in gh_nums: | |
continue | |
name = '#%s %s' % (gh_num, issue['title'] ) | |
gh_url = 'https://github.com/hypothesis/h/issues/' + gh_num | |
desc = gh_url + '\n\n' + issue['body'] | |
make_trello_card(list, name, desc) | |
def get_github_nums_from_trello_cards(): | |
lists = [backlog_triage_list, backlog_not_prioritized_list, backlog_backlog_list, | |
sprint_up_next, sprint_in_progress, sprint_deployed, sprint_delivered] | |
gh_nums = [] | |
for list in lists: | |
url = 'https://api.trello.com/1/lists/%s?fields=name&cards=open&card_fields=name,closed&key=%s&token=%s' % (list, key, token) | |
r = requests.get(url) | |
j = json.loads(r.text) | |
cards = j['cards'] | |
for card in cards: | |
gh_num = get_gh_num(card) | |
if gh_num is not None: | |
gh_nums.append(gh_num) | |
return gh_nums | |
def get_gh_num(card): | |
m = re.search('^#(\d+)',card['name']) | |
if m is not None: | |
return m.group(1) | |
else: | |
return None | |
def make_trello_card(list, name, desc): | |
url = 'https://api.trello.com/1/cards?key=%s&token=%s&name=Hypothesis' % (key, token) | |
data = { 'idList':backlog_triage_list,'name':name, 'desc':desc } | |
r = requests.post(url, data) | |
get_github_issues() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment