Skip to content

Clear branch protection rules when protected_branches is removed - #121

Merged
Humbedooh merged 1 commit into
apache:mainfrom
ppkarwasz:feat/clear-removed-branch-protection
Aug 13, 2026
Merged

Clear branch protection rules when protected_branches is removed#121
Humbedooh merged 1 commit into
apache:mainfrom
ppkarwasz:feat/clear-removed-branch-protection

Conversation

@ppkarwasz

Copy link
Copy Markdown
Member

Summary

Removing the protected_branches key from .asf.yaml previously left all existing branch protection rules in place; only the explicit protected_branches: ~ form cleared them. The branch_protection directive now consults the cached previous configuration (previous_yaml), mirroring what the rulesets directive already does: if the key was present in the previously applied .asf.yaml but is now absent, the previously configured branch protection rules are removed.

Motivation

Classic branch protection rules and rulesets can be active on the same repository at the same time; GitHub evaluates both and applies the most restrictive result. A project migrating from protected_branches to rulesets will therefore typically delete the protected_branches key, and would previously end up with stale branch protection rules layered on top of the new rulesets. The rulesets key already handled removal correctly, so this closes the gap on the branch protection side.

Changes

  • branch_protection.py: the early return now also checks previous_yaml; when the key was previously configured but is now absent, the directive falls through with an empty branch map and the existing removal loop un-protects all live-protected branches, exactly as protected_branches: ~ does. This is a one-time cleanup, since the configuration cache is rewritten after each run.
  • tests/github_branch_protection.py (new file, there were no branch protection tests before): covers removed-key cleanup, absent-key-with-no-history performing no API calls, the ~ regression path, noop mode, and a non-dict previous_yaml.
  • README.md: documents that removing the section has the same effect as setting it to ~ (as long as the github: section still contains other configuration) and notes the coexistence semantics of branch protection and rulesets.

Limitations

If the entire github: block is deleted, the GitHub feature never runs at all, so no cleanup of any kind can happen. This is a pre-existing limitation of the top-level feature dispatch and applies equally to rulesets; it is out of scope here.

Previously, removing the protected_branches key from .asf.yaml left all
existing branch protection rules in place; only the explicit
"protected_branches: ~" form cleared them. The directive now consults
the cached previous configuration, mirroring the rulesets directive: if
the key was present in the previously applied .asf.yaml but is now
absent, the previously configured branch protection rules are removed.

Classic branch protection and rulesets can be active at the same time
in GitHub (the most restrictive result applies), so each key needs its
own cleanup path. Rulesets already handled removal correctly.

Assisted-By: Claude Fable 5 <noreply@anthropic.com>
@Humbedooh
Humbedooh merged commit 32076d4 into apache:main Aug 13, 2026
5 checks passed
@ppkarwasz
ppkarwasz deleted the feat/clear-removed-branch-protection branch August 13, 2026 09:23
ppkarwasz added a commit to apache/logging-parent that referenced this pull request Aug 16, 2026
ppkarwasz added a commit to apache/logging-parent that referenced this pull request Aug 16, 2026
* Switch to GitHub Rulesets (second attempt)

The first attempt (#456) had to be reverted in #471 because a bug in ASFYaml made the resulting rulesets impossible to modify or remove through `.asf.yaml`. We rolled back to the legacy `protected_branches` configuration.

apache/infrastructure-asfyaml#93 has now landed and addresses the underlying issues (broken `app_slug` resolution, silent REST API failures, missing `refs/heads/` / `refs/tags/` prefixing), so we can move back to Rulesets.

The benefits over `protected_branches` remain:

- Tag references can also be protected (see the new `rel/*` ruleset).
- A single ruleset can target a glob of refs (e.g. `gha/*`) instead of one branch at a time.
- Rules are publicly visible at https://github.com/apache/logging-parent/rules, so we can verify that the effective rules are those configured and third parties can audit the project's protection policy too.

* fix: use raw syntax for tags

* fix: remove `protected_branches`

No longer needed since apache/infrastructure-asfyaml#121 was merged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants