milestone-review-dash detect current milestone

This patch makes the milestone arg optional. If it's not passed
the script will detect and use the current milestone.
This is required to run this script in a periodic job, since infra
won't accept hard-code parameters.

Change-Id: I8c2ffbc68fd36759924e9ab2a1eb64be390d4756
This commit is contained in:
rossella 2016-03-22 15:38:52 +00:00
parent 76df414d7a
commit 79ab61d56c

View File

@ -28,6 +28,20 @@ def is_milestone_valid(project, name):
return False
def get_current_milestone(project):
series = project.get_timeline()['entries']
current_milestone = ""
for s in series:
if s['is_development_focus']:
for landmark in s['landmarks']:
#landmark with a date set are past milestones
if not landmark['date']:
if (landmark['name'] < current_milestone or
not current_milestone):
current_milestone = landmark['name']
return current_milestone
def _search_task(project, **kwargs):
bugs = project.searchTasks(**kwargs)
if not bugs:
@ -105,23 +119,28 @@ parser = argparse.ArgumentParser(
' folder that you can serve as input for gerrit-dash-creator.'
' The output of the script can be used to query Gerrit'
' directly.')
parser.add_argument('milestone', type=str, help='The release milestone')
parser.add_argument('-m', '--milestone', type=str,
help='The release milestone')
parser.add_argument('-o', '--output', type=str, help='Output file')
args = parser.parse_args()
milestone = args.milestone
if args.output:
file_name = args.output
else:
file_name = milestone + '.dash'
cachedir = "~/.launchpadlib/cache/"
launchpad = Launchpad.login_anonymously('just testing', 'production', cachedir,
version="devel")
neutron = launchpad.projects['neutron']
neutron_client = launchpad.projects['python-neutronclient']
args = parser.parse_args()
if args.milestone:
milestone = args.milestone
if not is_milestone_valid(neutron, milestone):
sys.exit()
else:
milestone = get_current_milestone(neutron)
if args.output:
file_name = args.output
else:
file_name = milestone + '.dash'
with open(file_name, 'w') as f:
title = "[dashboard]\ntitle = Neutron %s Review Inbox\n" % milestone