From 540c96d173ce7cc86d7f16debb25552a8f85158c Mon Sep 17 00:00:00 2001 From: Joe Gordon Date: Wed, 15 Apr 2015 17:41:40 -0700 Subject: [PATCH] Add check for 'release:has-stable-branches' repo based tag validation that checks for the existence of a branch named stable/kilo. Change-Id: Icd88d94f8e2fe8c75553cb02d150eaa07b73aacb --- tools/stable.py | 51 ++++++++++++++++++++++++++++++++++++++++++ tools/validate_tags.py | 2 ++ 2 files changed, 53 insertions(+) create mode 100644 tools/stable.py diff --git a/tools/stable.py b/tools/stable.py new file mode 100644 index 000000000..b765dccc5 --- /dev/null +++ b/tools/stable.py @@ -0,0 +1,51 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import json +import urllib + +import requests + +import base + +# Specify stable branch to look for. Some repos contain stable branches +# but not for the most recent release. +# TODO(jogo): figure out to stop hard coding this. +latest_stable_branch = "kilo" + + +class ValidateStableBranches(base.ValidatorBase): + + @staticmethod + def has_stable_branch(repo): + response = requests.get( + 'https://review.openstack.org:443/projects/%s/branches' % + urllib.quote_plus(repo)) + # strip off first few chars because 'the JSON response body starts with + # a magic prefix line that must be stripped before feeding the rest of + # the response body to a JSON parser' + # https://review.openstack.org/Documentation/rest-api.html + branches = json.loads(response.text[4:]) + for branch in branches: + if branch['ref'].startswith("refs/heads/stable/%s" % + latest_stable_branch): + return True + return False + + @staticmethod + def validate(repo): + """Return True of team should contain the tag get_tag_name()""" + return ValidateStableBranches.has_stable_branch(repo) + + @staticmethod + def get_tag_name(): + return "release:has-stable-branches" diff --git a/tools/validate_tags.py b/tools/validate_tags.py index 1766e61fc..0e2b56179 100755 --- a/tools/validate_tags.py +++ b/tools/validate_tags.py @@ -22,6 +22,7 @@ and reorder projects.yaml """ import diversity +import stable import requests import yaml @@ -37,6 +38,7 @@ team_validators = [ # List of modules to validate repository based tags repo_validators = [ + stable.ValidateStableBranches, ]