From 7b8a06864f84dd5833715e1564a503ca79c1545d Mon Sep 17 00:00:00 2001 From: Naxdy Date: Fri, 31 Jul 2026 12:50:43 +0000 Subject: [PATCH] Add documentation for code owner branch protection (#245) Documentation for https://github.com/go-gitea/gitea/pull/34995 --------- Co-authored-by: bircni Co-authored-by: silverwind <2021+silverwind@noreply.gitea.com> Reviewed-on: https://gitea.com/gitea/docs/pulls/245 Reviewed-by: bircni Co-authored-by: Naxdy --- docs/usage/repository/code-owners.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/docs/usage/repository/code-owners.md b/docs/usage/repository/code-owners.md index 201e4ff9..3e2faa0e 100644 --- a/docs/usage/repository/code-owners.md +++ b/docs/usage/repository/code-owners.md @@ -39,6 +39,9 @@ docs/(aws|google|azure)/[^/]*\\.(md|txt) @user8 @org1/team4 !/assets/.*\\.(bin|exe|msi) @user9 ``` +Code owners listed in this file will automatically be requested to review pull requests +that modify files matching at least one corresponding rule. + ### Escaping You can escape characters `#`, ` ` (space) and `\` with `\`, like: @@ -55,3 +58,27 @@ Some character (`.+*?()|[]{}^$\`) should be escaped with `\\` inside regexp, lik path/\\.with\\.dots path/with\\+plus ``` + +### Branch Protection Rules + +When setting up branch protection rules, you may choose to enforce code owner approval of +modified files. This will block a PR from being merged until at least one code owner +has given approval for every applicable rule listed in the `CODEOWNERS` file. + +For example, say you have the following `CODEOWNERS` file: + +```bash +.*\\.go @Bob +.*\\.md @Sally @Chris +migrations/.* @Alice +``` + +This means that: + +- If your PR modifies any `.go` files, it will require approval from Bob. +- If your PR modifies any `.md` files, it will require approval from _either_ Sally _or_ Chris. +- If your PR modifies any file in the `migrations` directory, it will require approval from Alice. + +These rules are composable. So, for example, if your PR modifies some `.go` files, as well as +some `.md` files, this means it will require approval from Bob, in addition to approval from +one of either Sally or Chris.