Skip to content

Add block on pending codeowner reviews branch protection #34995

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

Conversation

Naxdy
Copy link
Contributor

@Naxdy Naxdy commented Jul 8, 2025

This commit introduces a new branch protection rule that allows merge blocking if there are pending reviews from one or more code owners (as defined in any valid CODEOWNERS file). This is determined by evaluating each rule present in the CODEOWNERS file individually. For every rule, at least one named code owner (or member of a code owner team) must have given an approving review for merging to be possible.

Closes #32602


This PR does NOT display code owners separately from other reviewers (#28137), as I think it makes sense to do that in a separate PR, as it doesn't require any database migrations.

Screenshot

Pull Request
Branch Protection Rule

Unresolved questions

  • Does this warrant a doc change?

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Jul 8, 2025
@github-actions github-actions bot added modifies/translation modifies/api This PR adds API routes or modifies them modifies/go Pull requests that update Go code modifies/templates This PR modifies the template files modifies/migrations labels Jul 8, 2025
@Naxdy Naxdy force-pushed the work/codeowner-review branch 5 times, most recently from 7ff6bd4 to 7141ade Compare July 8, 2025 13:01
@Naxdy Naxdy marked this pull request as ready for review July 8, 2025 13:02
@Naxdy Naxdy force-pushed the work/codeowner-review branch 2 times, most recently from 39ba543 to 18cce17 Compare July 11, 2025 16:43
@lunny lunny added this to the 1.25.0 milestone Jul 11, 2025
@lunny lunny added the type/enhancement An improvement of existing functionality label Jul 11, 2025
@@ -47,6 +48,147 @@ func IsCodeOwnerFile(f string) bool {
return slices.Contains(codeOwnerFiles, f)
}

func HasAllRequiredCodeownerReviews(ctx context.Context, pb *git_model.ProtectedBranch, pr *issues_model.PullRequest) bool {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A unit test or an integration test is required for this function to ensure its correctness.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I went and amended the existing code owner integration test to also check for branch protection rule enforcement.

@Naxdy Naxdy requested a review from lunny July 11, 2025 21:00
@Naxdy Naxdy force-pushed the work/codeowner-review branch 2 times, most recently from a66bad2 to a5035a7 Compare July 11, 2025 21:22
@Naxdy Naxdy force-pushed the work/codeowner-review branch from a5035a7 to 5df3166 Compare July 12, 2025 08:42
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 modifies/templates This PR modifies the template files modifies/translation type/enhancement An improvement of existing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Code Owners feature not enforceable
3 participants