import the latest version of governance module from release-tools
Copy the file in until we can release it as a library. Change-Id: Icac44268654e2d494e670e0532d6a4f2fde69e97 Signed-off-by: Doug Hellmann <doug@doughellmann.com>
This commit is contained in:
parent
f02a3b34b1
commit
10f0d13a5d
@ -33,6 +33,20 @@ def get_team_data(url=PROJECTS_LIST):
|
||||
return yaml.load(r.text)
|
||||
|
||||
|
||||
def get_repo_owner(team_data, repo_name):
|
||||
"""Return the name of the team that owns the repository.
|
||||
|
||||
:param team_data: The result of calling :func:`get_team_data`
|
||||
:param repo_name: Long name of the repository, such as 'openstack/nova'.
|
||||
|
||||
"""
|
||||
for team, info in team_data.items():
|
||||
for dname, dinfo in info.get('deliverables', {}).items():
|
||||
if repo_name in dinfo.get('repos', []):
|
||||
return team
|
||||
raise ValueError('Repository %s not found in governance list' % repo_name)
|
||||
|
||||
|
||||
class Team(object):
|
||||
def __init__(self, name, data):
|
||||
self.name = name
|
||||
@ -57,6 +71,13 @@ class Deliverable(object):
|
||||
for rn in self.data.get('repos', [])
|
||||
}
|
||||
|
||||
@property
|
||||
def type(self):
|
||||
for t in self.tags:
|
||||
if t.startswith('type:'):
|
||||
return t.partition(':')[-1]
|
||||
return 'unknown'
|
||||
|
||||
@property
|
||||
def tags(self):
|
||||
return set(self.data.get('tags', [])).union(self.team.tags)
|
||||
@ -73,5 +94,46 @@ class Repository(object):
|
||||
|
||||
@property
|
||||
def code_related(self):
|
||||
return (not (self.name.endswith('-specs') or
|
||||
'cookiecutter' in self.name))
|
||||
return not (self.name.endswith('-specs') or
|
||||
'cookiecutter' in self.name)
|
||||
|
||||
|
||||
def get_repositories(team_data, team_name=None, deliverable_name=None,
|
||||
tags=[], code_only=False):
|
||||
"""Return a sequence of repositories, possibly filtered.
|
||||
|
||||
:param team_data: The result of calling :func:`get_team_data`
|
||||
:param team_name: The name of the team owning the repositories. Can be
|
||||
None.
|
||||
:para deliverable_name: The name of the deliverable to which all
|
||||
repos should belong.
|
||||
:param tags: The names of any tags the repositories should
|
||||
have. Can be empty.
|
||||
:param code_only: Boolean indicating whether to return only code
|
||||
repositories (ignoring specs and cookiecutter templates).
|
||||
|
||||
"""
|
||||
if tags:
|
||||
tags = set(tags)
|
||||
if team_name:
|
||||
try:
|
||||
teams = [Team(team_name, team_data[team_name])]
|
||||
except KeyError:
|
||||
raise RuntimeError('No team %r found in %r' %
|
||||
(team_name, list(team_data.keys())))
|
||||
else:
|
||||
teams = [Team(n, i) for n, i in team_data.items()]
|
||||
for team in teams:
|
||||
if deliverable_name and deliverable_name not in team.deliverables:
|
||||
continue
|
||||
if deliverable_name:
|
||||
deliverables = [team.deliverables[deliverable_name]]
|
||||
else:
|
||||
deliverables = team.deliverables.values()
|
||||
for deliverable in deliverables:
|
||||
for repository in deliverable.repositories.values():
|
||||
if tags and not tags.issubset(repository.tags):
|
||||
continue
|
||||
if code_only and not repository.code_related:
|
||||
continue
|
||||
yield repository
|
||||
|
Loading…
Reference in New Issue
Block a user