Add StoryBoard filter and tag tools

Based on current Launchpad scripts, these scripts allow to add a tag to
stories, filter out stories with a specific tag

Add relevant sections README

Change-Id: Ifa73a5747afaf02d606e0da5ba12cc361e77c822
This commit is contained in:
Bernard Cafarelli 2018-01-17 15:47:58 +01:00
parent ebe10351b9
commit f4b1854b60
No known key found for this signature in database
GPG Key ID: D148244A3C2462BD
3 changed files with 145 additions and 0 deletions

View File

@ -874,6 +874,34 @@ Example::
This command will add the 'foo-tag' tag to all bugs fixed since 8.0.0.
sb-filter-stories-by-tag.py
---------------------------
Reads the list of StoryBoard story numbers on stdin, filters out stories
matching a tag.
Example::
./bugs-fixed-since.py [...] -sb --start=1.0.0 | \
./sb-filter-stories-by-tag.py in-stable-pike
List stories fixed in master since 1.0.0 that do not have relevant fixes merged
in stable/pike.
sb-tag.py
---------
Appends a tag to stories specified on stdin.
Example::
./bugs-fixed-since.py [...] -sb --start=1.0.0 | \
./sb-tag.py foo-tag
This command will add the 'foo-tag' tag to all stories fixed since 1.0.0.
End of Life
===========

56
sb-filter-stories-by-tag.py Executable file
View File

@ -0,0 +1,56 @@
#!/usr/bin/env python
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
"""
This StoryBoard tool is used to filter out stories by tag.
"""
import argparse
import sys
from storyboardclient.v1 import client
STORY_PREFIX = "storyboard:"
def _parse_args():
parser = argparse.ArgumentParser(
description='Filter out stories with specified tag.')
parser.add_argument(
'tag', nargs='?',
help='Tag to filter')
return parser.parse_args()
def _filter_stories(sb, tag, story_ids):
for story_id in story_ids:
story = sb.stories.get(story_id)
if tag not in story.tags:
yield STORY_PREFIX + story_id
def main():
args = _parse_args()
sb = client.Client("https://storyboard.openstack.org/api/v1")
stories = [line.strip()[len(STORY_PREFIX):]
for line in sys.stdin.readlines()
if line.startswith(STORY_PREFIX)]
for story in _filter_stories(sb, args.tag, stories):
print(story)
if __name__ == '__main__':
main()

61
sb-tag.py Executable file
View File

@ -0,0 +1,61 @@
#!/usr/bin/env python
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
"""
This StoryBoard tool is used to tag stories.
"""
import argparse
import sys
from storyboardclient._apiclient.exceptions import BadRequest
from storyboardclient.v1 import client
STORY_PREFIX = "storyboard:"
def _parse_args():
parser = argparse.ArgumentParser(
description='Tag stories with a tag.')
parser.add_argument(
'--token', required=True,
help='Authentication token, available from ' +
'https://storyboard.openstack.org/#!/profile/tokens')
parser.add_argument(
'tag', help='Tag to use')
return parser.parse_args()
def _tag_story(sb, story_id, tag):
try:
sb.stories.get(story_id).tags_manager.update(tag)
except BadRequest:
# Story alread had a tag, ignoring
pass
def main():
args = _parse_args()
sb = client.Client("https://storyboard.openstack.org/api/v1", args.token)
stories = [line.strip()[len(STORY_PREFIX):]
for line in sys.stdin.readlines()
if line.startswith(STORY_PREFIX)]
for story in stories:
_tag_story(sb, story, args.tag)
if __name__ == '__main__':
main()