Skip to content

Instantly share code, notes, and snippets.

@RickyCook
Last active December 29, 2015 16:39
Show Gist options
  • Save RickyCook/7698843 to your computer and use it in GitHub Desktop.
Save RickyCook/7698843 to your computer and use it in GitHub Desktop.
Pivotal Tracer story fix
#!/usr/bin/python
import re
import requests
DEBUG = True
PROJECT_ID = ''
TOKEN = ''
LIST_URL = 'https://www.pivotaltracker.com/services/v5/projects/%s/stories' % PROJECT_ID
STORY_URL = 'https://www.pivotaltracker.com/services/v5/projects/%s/stories/%%s' % PROJECT_ID
r = requests.get(LIST_URL,
params={'limit': 10000},
headers={'X-TrackerToken': TOKEN},
)
regex = re.compile(r'^As a_\s*([^_]+?)\s*_I want_\s*([^_]+?)\s*_So that_\s*([^_]+?)\s*$')
for story in (v for v in r.json() if v['story_type'] == 'feature'):
matches = regex.match(story['description'])
if not matches:
continue
new_description = "_As a_ %s\n_I want_ %s\n_So that_ %s" % matches.groups()
if DEBUG:
print story['description']
print new_description
print
else:
r = requests.put(STORY_URL % story['id'],
headers={'X-TrackerToken': TOKEN,
'Content-Type': 'application/json'},
data=json.dumps({'description': new_description}))
print "Updated %s" % story['url']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment