diff --git a/org/org_management.py b/org/org_management.py index fbc3a5fd4..fcab1637c 100644 --- a/org/org_management.py +++ b/org/org_management.py @@ -85,6 +85,21 @@ def load_from_project(self): if wg: self.working_groups.append(wg) + # rfc-0007-repository-ownership: a repo can't be owned by multiple WGs + def validate_repo_ownership(self) -> bool: + valid = True + repo_owners = {} + for wg in self.working_groups: + wg_name = wg["name"] + wg_repos = set(r for a in wg["areas"] for r in a["repositories"]) + for repo in wg_repos: + if repo in repo_owners: + print(f"ERROR: Repository {repo} is owned by multiple WGs: {repo_owners[repo]}, {wg_name}") + valid = False + else: + repo_owners[repo] = wg_name + return valid + def get_contributors(self) -> Set[str]: return set(self.contributors) @@ -497,6 +512,9 @@ def _kebab_case(name: str) -> str: print("Generating cloudfoundry org configuration.") generator = OrgGenerator() generator.load_from_project() + if not generator.validate_repo_ownership(): + # TODO: fail on error + print("ERROR: Repository ownership is invalid.") generator.generate_org_members() generator.generate_teams() generator.generate_branch_protection() diff --git a/org/test_org_management.py b/org/test_org_management.py index d81f1fda6..20d511b52 100644 --- a/org/test_org_management.py +++ b/org/test_org_management.py @@ -322,6 +322,16 @@ def test_kebab_case(self): OrgGenerator._kebab_case("wg-Foundational Infrastructure-Integrated Databases (Mysql / Postgres)-approvers"), ) + def test_validate_repo_ownership(self): + o = OrgGenerator(static_org_cfg=org_cfg, toc=toc, working_groups=[wg1]) + self.assertTrue(o.validate_repo_ownership()) + o = OrgGenerator(static_org_cfg=org_cfg, toc=toc, working_groups=[wg1, wg2]) + self.assertTrue(o.validate_repo_ownership()) + o = OrgGenerator(static_org_cfg=org_cfg, toc=toc, working_groups=[wg3]) + self.assertTrue(o.validate_repo_ownership()) + o = OrgGenerator(static_org_cfg=org_cfg, toc=toc, working_groups=[wg1, wg2, wg3]) + self.assertFalse(o.validate_repo_ownership()) + def test_generate_wg_teams(self): _wg1 = OrgGenerator._yaml_load(wg1) (name, wg_team) = OrgGenerator._generate_wg_teams(_wg1) @@ -483,6 +493,10 @@ def test_cf_org(self): # branch protection self.assertIn("cloudfoundry", o.branch_protection["branch-protection"]["orgs"]) + # ERROR: Repository cloudfoundry/app-runtime-interfaces-infrastructure is owned by multiple WGs: + # App Runtime Interfaces, Documentation + o.validate_repo_ownership() # TODO: assertTrue when repo ownership is cleaned up + o.generate_org_members() members = o.org_cfg["orgs"]["cloudfoundry"]["members"] admins = o.org_cfg["orgs"]["cloudfoundry"]["admins"]