From 1227800a3759175b9686a83474a11ea2bf0771f5 Mon Sep 17 00:00:00 2001 From: Doug Hellmann Date: Tue, 16 Aug 2016 12:11:02 -0400 Subject: [PATCH] fix tag detection Use a separate URL for testing a tag from testing a SHA, since sometimes the latter does not work for tags. Change-Id: I01e71df99b0ab81f171f9e69e5190164e20f5106 Signed-off-by: Doug Hellmann --- openstack_releases/cmds/validate.py | 8 ++++---- openstack_releases/gitutils.py | 21 +++++++++++++++++++-- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/openstack_releases/cmds/validate.py b/openstack_releases/cmds/validate.py index 9fdba867aa..01e776b5c3 100644 --- a/openstack_releases/cmds/validate.py +++ b/openstack_releases/cmds/validate.py @@ -243,7 +243,7 @@ def main(): # import history and sometimes we want to make new # releases. print('version %s ' % release['version'], end='') - version_exists = gitutils.commit_exists( + version_exists = gitutils.tag_exists( project['repo'], release['version'], ) gitutils.clone_repo(workdir, project['repo']) @@ -254,9 +254,9 @@ def main(): release['version'], ) if actual_sha == project['hash']: - print('found and matches SHA') + print('found and SHAs match, ') else: - print('found DIFFERENT %r' % actual_sha) + print('found DIFFERENT %r, ' % actual_sha) errors.append( ('Version %s in %s is on ' 'commit %s instead of %s') % @@ -265,7 +265,7 @@ def main(): actual_sha, project['hash'])) else: - print('NEW ', end='') + print('NEW VERSION, ', end='') new_releases[release['version']] = release if not prev_version: print() diff --git a/openstack_releases/gitutils.py b/openstack_releases/gitutils.py index 6c46ec5b10..e9dd172fad 100644 --- a/openstack_releases/gitutils.py +++ b/openstack_releases/gitutils.py @@ -22,7 +22,8 @@ import requests from requests.packages import urllib3 urllib3.disable_warnings() -CGIT_TEMPLATE = 'http://git.openstack.org/cgit/%s/commit/?id=%s' +CGIT_SHA_TEMPLATE = 'http://git.openstack.org/cgit/%s/commit/?id=%s' +CGIT_TAG_TEMPLATE = 'http://git.openstack.org/cgit/%s/tag/?h=%s' def find_modified_deliverable_files(): @@ -46,7 +47,23 @@ def commit_exists(repo, ref): someone to fool the check. """ - url = CGIT_TEMPLATE % (repo, ref) + url = CGIT_SHA_TEMPLATE % (repo, ref) + response = requests.get(url) + missing_commit = ( + (response.status_code // 100 != 2) or 'Bad object id' in response.text + ) + return not missing_commit + + +def tag_exists(repo, ref): + """Return boolean specifying whether the reference exists in the repository. + + Uses a cgit query instead of looking locally to avoid cloning a + repository or having Depends-On settings in a commit message allow + someone to fool the check. + + """ + url = CGIT_TAG_TEMPLATE % (repo, ref) response = requests.get(url) missing_commit = ( (response.status_code // 100 != 2) or 'Bad object id' in response.text