Last active
July 20, 2018 11:15
-
-
Save ncolomer/79a08a7d04937563a4cdb0c3b58262e7 to your computer and use it in GitHub Desktop.
Clubhouse Sprint Summarizer
This file contains hidden or 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
#!/usr/bin/env python | |
''' | |
Print all user stories for a given label, grouped by epic. | |
See https://app.clubhouse.io/settings/account/api-tokens to | |
generate your clubhouse api token. | |
You need to run `pip install docopts requests` to be able | |
to execute this binary. | |
Usage: | |
clubhouse <sprint-label> --api-token=<token> | |
Options: | |
-h --help Show this screen. | |
--api-token=<token> The task id of this run. | |
''' | |
import requests | |
from docopt import docopt | |
from collections import defaultdict | |
if __name__ == '__main__': | |
arguments = docopt(__doc__, version='clubhouse 1.0') | |
sprint_label = arguments['<sprint-label>'] | |
clubhouse_api_token = arguments['--api-token'] | |
def get_epic_name(epic_id): | |
if epic_id: | |
params = { 'token': clubhouse_api_token } | |
res = requests.get('https://api.clubhouse.io/api/v2/epics/{}'.format(epic_id), params=params) | |
return res.json().get('name') | |
else: | |
return None | |
def get_stories(label): | |
params = { 'query': 'label:{}'.format(label), 'page_size': '25', 'token': clubhouse_api_token } | |
res = requests.get('https://api.clubhouse.io/api/v2/search/stories', params=params) | |
return [{ | |
'id': story['id'], | |
'label': story['name'], | |
'points': story['estimate'], | |
'epic_id': story['epic_id'] | |
} for story in res.json()['data']] | |
# fetch stories with label | |
sprint_stories = get_stories(sprint_label) | |
# group stories by epic | |
sprint_stories_grouped_by_epic = defaultdict(list) | |
for story in sprint_stories: sprint_stories_grouped_by_epic[story['epic_id']].append(story) | |
# fetch epic details and print stories | |
for epic_id, stories in sprint_stories_grouped_by_epic.items(): | |
print get_epic_name(epic_id) or 'Miscellaneous' | |
for story in stories: print '[{}] {}'.format(story['id'], story['label']) | |
print 'Total sprint points: {}'.format(sum([story['points' ]for story in sprint_stories])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment