From 79ab61d56caa904ac8ee1fee710cb20488c6db36 Mon Sep 17 00:00:00 2001 From: rossella Date: Tue, 22 Mar 2016 15:38:52 +0000 Subject: [PATCH] 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 --- tools/milestone-review-dash.py | 39 +++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/tools/milestone-review-dash.py b/tools/milestone-review-dash.py index a4897100bf5..bc26729fc64 100755 --- a/tools/milestone-review-dash.py +++ b/tools/milestone-review-dash.py @@ -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'] -if not is_milestone_valid(neutron, milestone): - sys.exit() + +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