Skip to content

Conversation

@fwag
Copy link

@fwag fwag commented Nov 3, 2025

In organizations with a large number of repositories, managing branch protection rules on a per-repository basis is not scalable and can lead to security inconsistencies. This pull request introduces organization-level branch protection rules to address this, allowing administrators to define rules that apply to all repositories within an organization.

To enhance security and ensure consistent policy enforcement, organization-level rules are designed to take precedence over repository-level rules. When determining the effective protection for a branch, the system will first look for a matching rule at the organization level. If one is found, it is applied. If not, it falls back to checking for repository-specific rules.

This change includes:

  • Database schema modifications to the protected_branch table to support both owner_id and repo_id, with partial unique indexes to ensure rule name uniqueness at both levels.
  • New API endpoints under /orgs/{org}/branch_protections for creating, reading, updating, and deleting organization-level branch protection rules.
  • Updated logic to prioritize organization-level rules over repository-level rules during branch protection checks.

As I am not deeply familiar with the Gitea codebase and am relatively new to Go, I would greatly appreciate a thorough community review of these changes.

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Nov 3, 2025
@github-actions github-actions bot added modifies/api This PR adds API routes or modifies them modifies/go Pull requests that update Go code modifies/migrations labels Nov 3, 2025
@AdamMajer
Copy link
Contributor

Seems to be related to part of #34816

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. modifies/api This PR adds API routes or modifies them modifies/go Pull requests that update Go code modifies/migrations

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants