[list_changes] Handle non-numeric tags

After we tagged a realease EM git describe on a branch will include that
tag and as it contains a '-' it breaks the partition() we're using to
get the tag[1].

Switch to using a re rather than the simple partition.

(venv) [tony@thor releases]$ ipython
Python 3.7.3 (default, Mar 27 2019, 13:41:07)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.4.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import openstack_releases.cmds.list_changes
In [2]: workdir = '/home/tony/projects/openstack'
In [3]: repo = 'openstack/python-manilaclient'
In [4]: openstack_releases.cmds.list_changes.git_list_existing_branches(workdir, repo)

All Branches with Version Numbers
---------------------------------
feature/add-constraints-support 1.11.0-36-g7134e3c   1.11.0       2 years, 8 months ago
master                         1.27.0-10-g05a3f4d   1.27.0       6 months ago
review/openstack_release_bot/create-stein 1.27.0-2-g31608cf    1.27.0       6 months ago
remotes/gerrit/master          1.27.0-10-g05a3f4d   1.27.0       6 months ago
fatal: ambiguous argument 'ocata': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
remotes/gerrit/stable/ocata    ocata-em-5-g22e9c42  ocata
remotes/gerrit/stable/pike     1.17.4               1.17.4       7 months ago
remotes/gerrit/stable/queens   1.21.1-6-g02d6234    1.21.1       1 year, 1 month ago
remotes/gerrit/stable/rocky    1.24.1-9-g816bfc8    1.24.1       9 months ago
remotes/gerrit/stable/stein    1.27.0-3-g7430f4c    1.27.0       6 months ago
remotes/origin/master          1.27.0-10-g05a3f4d   1.27.0       6 months ago
fatal: ambiguous argument 'ocata': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
remotes/origin/stable/ocata    ocata-em-5-g22e9c42  ocata
remotes/origin/stable/pike     1.17.4               1.17.4       7 months ago
remotes/origin/stable/queens   1.21.1-6-g02d6234    1.21.1       1 year, 1 month ago
remotes/origin/stable/rocky    1.24.1-9-g816bfc8    1.24.1       9 months ago
remotes/origin/stable/stein    1.27.0-3-g7430f4c    1.27.0       6 months ago

In [5]: from imp import reload
In [6]: reload(openstack_releases.cmds.list_changes)
Out[6]: <module 'openstack_releases.cmds.list_changes' from '/home/tony/projects/openstack/openstack/releases/openstack_releases/cmds/list_changes.py'>
In [7]: openstack_releases.cmds.list_changes.git_list_existing_branches(workdir, repo)

All Branches with Version Numbers
---------------------------------
feature/add-constraints-support 1.11.0-36-g7134e3c   1.11.0       2 years, 8 months ago
master                         1.27.0-10-g05a3f4d   1.27.0       6 months ago
review/openstack_release_bot/create-stein 1.27.0-2-g31608cf    1.27.0       6 months ago
remotes/gerrit/master          1.27.0-10-g05a3f4d   1.27.0       6 months ago
remotes/gerrit/stable/ocata    ocata-em-5-g22e9c42  ocata-em     2 years, 3 months ago
remotes/gerrit/stable/pike     1.17.4
remotes/gerrit/stable/queens   1.21.1-6-g02d6234    1.21.1       1 year, 1 month ago
remotes/gerrit/stable/rocky    1.24.1-9-g816bfc8    1.24.1       9 months ago
remotes/gerrit/stable/stein    1.27.0-3-g7430f4c    1.27.0       6 months ago
remotes/origin/master          1.27.0-10-g05a3f4d   1.27.0       6 months ago
remotes/origin/stable/ocata    ocata-em-5-g22e9c42  ocata-em     2 years, 3 months ago
remotes/origin/stable/pike     1.17.4
remotes/origin/stable/queens   1.21.1-6-g02d6234    1.21.1       1 year, 1 month ago
remotes/origin/stable/rocky    1.24.1-9-g816bfc8    1.24.1       9 months ago
remotes/origin/stable/stein    1.27.0-3-g7430f4c    1.27.0       6 months ago

[1] http://logs.openstack.org/75/652775/2/check/releases-tox-list-changes/92b219a/job-output.txt.gz#_2019-04-16_14_25_50_377843

Change-Id: I6a6cf9110a737204e332c60004f72a68b770d1e7
This commit is contained in:
Tony Breeds
2019-04-17 11:15:34 +10:00
committed by Thierry Carrez
parent 78afdabc0c
commit 55fa425cdc

View File

@@ -24,6 +24,7 @@ import json
import logging
import os
import os.path
import re
import shutil
import subprocess
import sys
@@ -80,7 +81,13 @@ def git_list_existing_branches(workdir, repo):
['git', 'describe', branch],
cwd=os.path.join(workdir, repo),
).decode('utf-8').strip()
tag = description.partition('-')[0] # strip to the real tag value
# strip to the real tag value
match = re.match('^(.*)-[0-9]+-g[a-f0-9]+', description,
re.IGNORECASE)
if match:
tag = match.groups()[0]
else:
tag = ''
except subprocess.CalledProcessError as exc:
description = exc.output.decode('utf-8').strip()
tag = ''