Show file code owners when viewing a file
A code owners file provides a version controlled way of documenting which groups or individuals are key stakeholders in specific areas of the codebase. These people are likely to be the best people to request a code review from and would likely make the best approvers.
It should be possible to use code owners to automatically suggest, assign and enforce approvals. All these features rely on efficiently checking a file path against the code owners file.
# Example CODEOWNERS file
# This user is the default owner for everything in the repo.
* @user1
# The last matching pattern has the most precedence.
**/repository @user2
*.go @user3
As a first iteration we should build the code owners parser and show the output for a file in the blob viewer.
Proposal
When I view a file in a repository (e.g. https://gitlab.com/gitlab-org/gitlab-ce/blob/master/lib/gitaly/server.rb) I should which users are assigned as code owners.
This first iteration of the CODEOWNERS
parser will only support specify users by handle, not groups or emails.
When viewing a file when browsing a repository:
- Check the current branch for the presence of a
CODEOWNERS
file in the root directory - Check the file being viewed against the
CODEOWNERS
file to generate the list of users who are code owners - Show the list of code owners at the top of the file
The code owners file:
-
follows the formatting conventions of gitignore
-
blank lines match no files and are ignored
A blank line matches no files, so it can serve as a separator for readability.
-
lines preceded by
#
are commentsA line starting with # serves as a comment. Put a backslash ("") in front of the first hash for patterns that begin with a hash.
-
last matching rule has the highest precedence – this means for each file we scan the list top to bottom for every file and users of the last matching rule.
-
rules consist of a pattern and a list of users and groups separated by whitespace
<pattern> <user> <user> ...
-
a user is specified with preceding
@
(e.g.@john
)