diff --git a/openstack_releases/cmds/new_release.py b/openstack_releases/cmds/new_release.py index dbbd47eea0..23a07127c5 100644 --- a/openstack_releases/cmds/new_release.py +++ b/openstack_releases/cmds/new_release.py @@ -104,7 +104,14 @@ def main(): projects = [] for project in last_release['projects']: gitutils.clone_repo(workdir, project['repo']) - sha = gitutils.sha_for_tag(workdir, project['repo'], 'HEAD') + + branches = gitutils.get_branches(workdir, project['repo']) + version = 'origin/stable/%s' % series + if not any(branch for branch in branches + if branch.endswith(version)): + version = 'master' + + sha = gitutils.sha_for_tag(workdir, project['repo'], version) projects.append({ 'repo': project['repo'], 'hash': sha, diff --git a/openstack_releases/gitutils.py b/openstack_releases/gitutils.py index 758298bcfc..ffdf1a46ee 100644 --- a/openstack_releases/gitutils.py +++ b/openstack_releases/gitutils.py @@ -116,3 +116,20 @@ def get_latest_tag(workdir, repo): print('WARNING failed to retrieve latest tag: %s [%s]' % (e, e.output.strip())) return None + + +def get_branches(workdir, repo): + try: + output = subprocess.check_output( + ['git', 'branch', '-a'], + cwd=os.path.join(workdir, repo), + stderr=subprocess.STDOUT, + ).strip() + return [ + branch + for branch in output.split() + ] + except subprocess.CalledProcessError as e: + print('ERROR failed to retrieve list of branches: %s [%s]' % + (e, e.output.strip())) + return []