move story functions to their own module

Move find_or_create_story and refactor it to let us have a find_story
function.

Change-Id: Ieb03dced4d614ab784869f1d83a4767e13eaa8e4
Signed-off-by: Doug Hellmann <doug@doughellmann.com>
This commit is contained in:
Doug Hellmann 2018-08-01 11:02:35 -04:00
parent 4fbf1078eb
commit 5e9ca4d108
2 changed files with 24 additions and 18 deletions

View File

@ -71,22 +71,6 @@ def _find_project(sbc, name):
raise ValueError('Could not find project {}'.format(name))
def _find_or_create_story(sbc, title, description):
LOG.info('searching for existing stories like {!r}'.format(title))
existing = sbc.stories.get_all(title=title)
if not existing:
LOG.info('creating new story')
story = sbc.stories.create(
title=title,
description=description,
)
LOG.info('created story {}'.format(story.id))
else:
story = existing[0]
LOG.info('found existing story {}'.format(story.id))
return story
def _update_tags(sbc, story, tag):
tags = set(story.tags or [])
if tag in tags:
@ -211,7 +195,7 @@ def main():
LOG.info('using specified story')
story = sbc.stories.get(args.story)
else:
story = _find_or_create_story(
story = storyboard.find_or_create_story(
sbc=sbc,
title=goal_info['title'],
description=full_description,
@ -244,7 +228,7 @@ def main():
for project_name in project_names:
deliverables = project_info[project_name]['deliverables'].items()
story = _find_or_create_story(
story = storyboard.find_or_create_story(
sbc=sbc,
title='{}: {}'.format(project_name, goal_info['title']),
description=(goal_info['description'] +

View File

@ -74,3 +74,25 @@ def get_client(config):
LOG.info('Connecting to storyboard at {}'.format(storyboard_url))
return client.Client(storyboard_url, access_token, verify=verify)
def find_story(sbc, title):
LOG.info('searching for existing stories like {!r}'.format(title))
existing = sbc.stories.get_all(title=title)
if existing:
story = existing[0]
LOG.info('found existing story {}'.format(story.id))
return story
return None
def find_or_create_story(sbc, title, description):
story = find_story(sbc, title)
if not story:
LOG.info('creating new story')
story = sbc.stories.create(
title=title,
description=description,
)
LOG.info('created story {}'.format(story.id))
return story