Code Owners
This feature is available in the Enterprise version, as well as on gitflic.ru
The Code Owners feature allows you to specify users (code owners) responsible for specific parts of the codebase or certain project files. Using this functionality enables you to automatically request approvals for merges if the changes affect files or directories that have assigned code owners.
To use this feature, create a CODEOWNERS
file in the root of the repository to specify ownership rules for files and sections of the project. Each repository can only have one CODEOWNERS
file. To enable the feature, select the corresponding option on the branch protection page. This feature works independently from merge request approval rules, but all requirements specified in the merge request settings are still taken into account.
Configuring the CODEOWNERS File
The CODEOWNERS
file uses a defined syntax to set ownership rules. Each line in the file is a rule and specifies a path or file pattern for one or more owners.
Key elements:
- File path patterns: specific files or paths
- Code owners: use @username to specify users
- Comments: lines starting with
#
are ignored - Sections: optional groups of rules defined with
[Section name]
Examples of rule combinations
# Code owners for the file named filename
filename @alias1 @alias2
# Code owners for all files in the repository
** @alias1 @alias2
# Code owners for all .java files in the root of the repository
**.java @alias1 @alias2
# Code owners for the directory directoryName in the root of the repository
directoryName/** @alias1 @alias2
# Code owners for the main directory located anywhere in the repository
**/main/** @alias1 @alias2
# Code owners in the Main section, where the main directory is in the root of the repository
[Main section]
main/** @alias1 @alias2
Examples of matching patterns and the path to test.py
In the
Result
column, the rule trigger for the file is indicated when usingCODEOWNERS
Path Pattern | Example file path | Result |
---|---|---|
**/pic/** |
pic/target/com/test.py | true |
/pic/** |
pic/target/com/test.py | true |
**/com/** |
pic/target/com/test.py | true |
com/** |
pic/target/com/test.py | false |
**/**.py |
pic/target/com/test.py | true |
**.py |
pic/target/com/test.py | false |
**/pic/** |
pic/target/com/test.py | true |
pic/* |
pic/test.py | true |
pic/* |
pic/target/test.py | false |
** |
pic/target/com/test.py | true |
Example of a CODEOWNERS file
# Code owners for all java files in the repository in the [Java owners] section
[Java owners]
**/**.java @alias1 @alias2
# Code owners for all .md files in the root of the repository in the [DOCUMENTATION] section
[DOCUMENTATION]
**.md @alias1
Automated translation!
This page was translated using automatic translation tools. The text may contain inaccuracies.