update handling of branches in list-changes

Use the existing heuristic to try to check out the right branch, but
then look at the available branches and if we find a stable branch
with the right series name check that out explicitly and use that name
for the branch so that the gerrit queries include the right
patches. This allows us to see patches on stable branches during the
release candidate period, for example.

Change-Id: Ie7a389acb3d912767a8e35dd0dd86053feb7b3d0
Signed-off-by: Doug Hellmann <doug@doughellmann.com>
This commit is contained in:
Doug Hellmann 2017-08-22 15:48:17 -04:00
parent c8f6ed41f4
commit 4d808671b6
2 changed files with 50 additions and 7 deletions

View File

@ -258,11 +258,6 @@ def main():
else:
print('no team name given, cannot report on governance status')
if series == defaults.RELEASE:
branch = 'master'
else:
branch = 'stable/' + series
# If there are no releases listed, this is probably a new
# deliverable file for initializing a new series. We don't
# need to list its changes.
@ -290,17 +285,49 @@ def main():
print('%s %s exists on git server already' %
(project['repo'], new_release['version']))
# Decide which branch we're going to try to clone. We need
# the repo checked out before we can tell if the stable
# branch really exists, but zuul-cloner will fall back to
# master if it doesn't.
if series in (defaults.RELEASE, '_independent'):
clone_branch = 'master'
else:
clone_branch = 'stable/' + series
# Check out the code.
print('\nChecking out repository {}'.format(project['repo']))
print('\nChecking out repository {} to {}'.format(
project['repo'], clone_branch))
subprocess.check_call(
['zuul-cloner',
'--branch', branch,
'--branch', clone_branch,
'--workspace', workdir,
'git://git.openstack.org',
project['repo'],
]
)
# Determine which branch we should actually be looking
# at. Assume any series for which there is no stable
# branch will be on 'master'.
if gitutils.stable_branch_exists(workdir, project['repo'], series):
branch = 'stable/' + series
else:
branch = 'master'
if branch != clone_branch:
# Check out the repo again to the right branch if we
# didn't get it the first time.
print('\nUpdating repository {} to {}'.format(
project['repo'], branch))
subprocess.check_call(
['zuul-cloner',
'--branch', branch,
'--workspace', workdir,
'git://git.openstack.org',
project['repo'],
]
)
# look at the previous tag for the parent of the commit
# getting the new release
previous_tag = gitutils.get_latest_tag(

View File

@ -120,6 +120,22 @@ def _filter_branches(output):
]
def stable_branch_exists(workdir, repo, series):
"Does the stable/series branch exist?"
remote_match = 'remotes/origin/stable/%s' % series
try:
containing_branches = _filter_branches(
subprocess.check_output(
['git', 'branch', '-a'],
cwd=os.path.join(workdir, repo),
).decode('utf-8')
)
return (remote_match in containing_branches)
except subprocess.CalledProcessError as e:
print('ERROR checking for branch: %s [%s]' % (e, e.output.strip()))
return False
def check_branch_sha(workdir, repo, series, master, sha):
"""Check if the SHA is in the targeted branch.