Skip to content

Apply RFC0015 branch protection by default #1218

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions orgs/org_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,18 +192,17 @@ def generate_teams(self):

def generate_branch_protection(self):
# basis is static config in self.branch_protection which is never overwritten
# generate RFC0015 branch protection rules for every WG+TOC that opted in
# generate RFC0015 branch protection rules for every WG+TOC by default
for org in OrgGenerator._MANAGED_ORGS:
branch_protection_repos = self.branch_protection["branch-protection"]["orgs"][org]["repos"]
wgs = self.working_groups[org]
if org == self.toc["org"]:
wgs.append(self.toc)
for wg in wgs:
if wg.get("config", {}).get("generate_rfc0015_branch_protection_rules", False): # config is optional
repo_rules = self._generate_wg_branch_protection(wg)
for repo in repo_rules:
if repo not in branch_protection_repos:
branch_protection_repos[repo] = repo_rules[repo]
repo_rules = self._generate_wg_branch_protection(wg)
for repo in repo_rules:
if repo not in branch_protection_repos:
branch_protection_repos[repo] = repo_rules[repo]

def write_org_config(self, path: str):
print(f"Writing org configuration to {path}")
Expand Down
11 changes: 3 additions & 8 deletions orgs/test_org_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,6 @@
bots:
- github: bot-wg1-a5
name: WG3 Area5 Bot
config:
generate_rfc0015_branch_protection_rules: true
"""

wg4_other_org = """
Expand Down Expand Up @@ -206,8 +204,6 @@
- cloudfoundry2/repo3
- cloudfoundry2/repo4
- cloudfoundry/repo5
config:
generate_rfc0015_branch_protection_rules: true
"""

toc = """
Expand All @@ -231,7 +227,6 @@
repositories:
- cloudfoundry/community
config:
generate_rfc0015_branch_protection_rules: true
github_project_sync:
mapping:
cloudfoundry: 31
Expand Down Expand Up @@ -732,8 +727,8 @@ def test_generate_branch_protection(self):
bp_repos = o.branch_protection["branch-protection"]["orgs"]["cloudfoundry"]["repos"]
# TOC and wg3 opted in, wg1 and wg2 not
# note: repo1..4 are shared between wg1 (opt out) and wg3 (opt in) - wg3 wins
self.assertSetEqual({f"repo{i}" for i in range(1, 6)} | {"community"}, set(bp_repos.keys()))
# repo1 has static config that wins over generated branch protection rules
self.assertSetEqual({f"repo{i}" for i in list(range(1, 6)) + [10, 11]} | {"community"}, set(bp_repos.keys()))
# repo1 has static config that wins over generated branch protection rulesp
self.assertTrue(bp_repos["repo1"]["protect"])
self.assertNotIn("required_pull_request_reviews", bp_repos["repo1"])

Expand All @@ -749,7 +744,7 @@ def test_generate_branch_protection_multiple_orgs(self):
bp_repos = o.branch_protection["branch-protection"]["orgs"]["cloudfoundry"]["repos"]
# TOC and wg3 opted in, wg1 and wg2 not
# note: repo1..4 are shared between wg1 (opt out) and wg3 (opt in) - wg3 wins
self.assertSetEqual({f"repo{i}" for i in range(1, 6)} | {"community"}, set(bp_repos.keys()))
self.assertSetEqual({f"repo{i}" for i in list(range(1, 6)) + [10, 11]} | {"community"}, set(bp_repos.keys()))
# repo1 has static config that wins over generated branch protection rules
self.assertTrue(bp_repos["repo1"]["protect"])
self.assertNotIn("required_pull_request_reviews", bp_repos["repo1"])
Expand Down
8 changes: 8 additions & 0 deletions toc/rfc/rfc-0015-branch-protection.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,11 @@ With respect to the approval of pull requests, we propose that the number of app
* 1 approval will be required when a working group has 4 or more people in the approver role.

The automation should allow to override the standard branch protection per respository using a configuration file maintained in this community repository. This allows working group leads e.g. to reduce the number of required approvals if several approvers are temporarily not available.

## Amendments

### Protection by Default

To improve the security posture of the foundation, the branch protection rules defined in this RFC are applied by default to all repositories of all Working Groups. The previous opt-in mechanism via a flag in Working Group charters is removed.

Working Groups can request exceptions for specific repositories by creating a pull request against `orgs/branchprotection.yml`. The pull request description MUST contain a justification for the exception.
2 changes: 0 additions & 2 deletions toc/working-groups/app-runtime-deployments.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,4 @@ areas:
- cloudfoundry/relint-team
- cloudfoundry/runtime-ci
- cloudfoundry/uptimer
config:
generate_rfc0015_branch_protection_rules: true
```
3 changes: 0 additions & 3 deletions toc/working-groups/app-runtime-interfaces.md
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,4 @@ areas:
repositories:
- cloudfoundry/stratos
- cloudfoundry/stratos-buildpack

config:
generate_rfc0015_branch_protection_rules: true
```
1 change: 0 additions & 1 deletion toc/working-groups/app-runtime-platform.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ bots:
- name: Cryogenics CI bot
github: Cryogenics-CI
config:
generate_rfc0015_branch_protection_rules: true
github_project_sync:
mapping:
cloudfoundry: 41
Expand Down
2 changes: 0 additions & 2 deletions toc/working-groups/cf-on-k8s.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ technical_leads:
bots:
- name: korifi-bot
github: korifi-bot
config:
generate_rfc0015_branch_protection_rules: true
areas:
- name: Korifi
approvers:
Expand Down