Skip to content

Commit

Permalink
Merge pull request #1057 from cloudfoundry/github-org-automation
Browse files Browse the repository at this point in the history
Validate repository ownership
  • Loading branch information
beyhan authored Jan 28, 2025
2 parents 64d03e6 + cc92823 commit 0caf07e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
18 changes: 18 additions & 0 deletions org/org_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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()
Expand Down
14 changes: 14 additions & 0 deletions org/test_org_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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"]
Expand Down

0 comments on commit 0caf07e

Please sign in to comment.