From 9278edee45d2f20d4236358af04c77f296e4c925 Mon Sep 17 00:00:00 2001 From: Steve Dignam Date: Tue, 16 Mar 2021 18:05:55 -0400 Subject: [PATCH] add: ignore gitlab's code owner sections (#23) Doesn't add support, but ignores gitlab's sections related: https://github.com/sbdchd/codeowners/issues/20 --- codeowners/__init__.py | 8 +++++++- codeowners/test_codeowners.py | 11 +++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/codeowners/__init__.py b/codeowners/__init__.py index fa03a79..a79eed5 100644 --- a/codeowners/__init__.py +++ b/codeowners/__init__.py @@ -115,7 +115,13 @@ class CodeOwners: def __init__(self, text: str) -> None: paths: List[Tuple[Pattern[str], List[OwnerTuple]]] = [] for line in text.splitlines(): - if line == "" or line.startswith("#"): + line = line.strip() + if ( + line == "" + or line.startswith("#") + or (line.startswith("[") and line.endswith("]")) + or (line.startswith("^[") and line.endswith("]")) + ): continue elements = iter(line.split()) path = next(elements, None) diff --git a/codeowners/test_codeowners.py b/codeowners/test_codeowners.py index 721bb0e..ead9d18 100644 --- a/codeowners/test_codeowners.py +++ b/codeowners/test_codeowners.py @@ -39,10 +39,21 @@ # `docs/build-app/troubleshooting.md`. docs/* docs@example.com +# Let's test GitLab's premium feature of sections +# see https://docs.gitlab.com/ee/user/project/code_owners.html#code-owners-sections +[First team] + +[Another team trailing whitespace] + # In this example, @octocat owns any file in an apps directory # anywhere in your repository. apps/ @octocat +# Now, optional approval rule for GitLab's sections +^[Second team] + +^[Second team trailing whitespace] + # In this example, @doctocat owns any file in the `/docs` # directory in the root of your repository. /docs/ @doctocat