codeowners icon indicating copy to clipboard operation
codeowners copied to clipboard

No owner for specific file

Open leolambertucci opened this issue 3 years ago • 7 comments

if i create a codeowners file like this: CODEOWNERS: /build/logs/log.txt @ghost

owners = CodeOwners(example_file) owners.of("/build/logs/log.txt") it doesnt return any owner

was this supposed to happen?

leolambertucci avatar Jul 25 '22 17:07 leolambertucci

Is the actual text of the file:

/build/logs/log.txt @ghost

or does it include the CODEOWNERS heading as well?

sbdchd avatar Jul 25 '22 21:07 sbdchd

this is the actual text

leolambertucci avatar Jul 26 '22 09:07 leolambertucci

Please ignore my previous comments, it was dumb :) I RTFM, and I now know what is \A and \Z. Sorry about this.

Still, the problem is here: https://github.com/sbdchd/codeowners/blob/master/codeowners/init.py#L48

Instead of:

regex += r"\A" if anchored else r"(?:\A|/)"

it should be:

regex += r"\A/" if anchored else r"(?:\A|/)"

The / is missing from the regex in the current version.

KrystianOcado avatar Jul 26 '22 10:07 KrystianOcado

Maybe this is another case of behavior differing from git?

Git ignore says it doesn't match:

_______________________________________________________________ test_specific_patterns_against_git[single-file regression] _______________________________________________________________

name = 'single-file regression', pattern = '/build/logs/log.txt', paths = {'/build/logs/log.txt': True}

    @pytest.mark.parametrize(
        "name,pattern,paths", GO_CODEOWNER_EXAMPLES, ids=ids_for(GO_CODEOWNER_EXAMPLES)
    )
    def test_specific_patterns_against_git(
        name: str, pattern: str, paths: Dict[str, bool]
    ) -> None:
        """
        Ensure the expected patterns match actual git behavior.
    
        Codeowners is a subset of git ignore behavior so checking against it
        should work in most cases.
        """
        if name == "docs with star":
            pytest.skip("Behaviour for docs-with-star does not match gitignore")
    
        assert paths
        with tempfile.TemporaryDirectory() as directory:
            subprocess.run(["git", "init"], cwd=directory, check=True, capture_output=True)
            (Path(directory) / ".gitignore").write_text(pattern + "\n")
            for path, expected in paths.items():
                res = subprocess.run(
                    ["git", "check-ignore", path], cwd=directory, capture_output=True
                )
                actual = res.returncode == 0
>               assert (
                    actual is expected
                ), f"match for pattern:{pattern} and path:{path} failed, expected: {expected}, actual: {actual}"
E               AssertionError: match for pattern:/build/logs/log.txt and path:/build/logs/log.txt failed, expected: True, actual: False
E               assert False is True

sbdchd avatar Jul 28 '22 01:07 sbdchd

Please ignore my previous comments, it was dumb :) I RTFM, and I now know what is \A and \Z. Sorry about this.

Still, the problem is here: https://github.com/sbdchd/codeowners/blob/master/codeowners/init.py#L48

Instead of:

regex += r"\A" if anchored else r"(?:\A|/)"

it should be:

regex += r"\A/" if anchored else r"(?:\A|/)"

The / is missing from the regex in the current version.

when i replace the regex and execute my code, it gets the file owner. it worked. but the tests are failing. i will try to check the tests and see if I notice anything else

leolambertucci avatar Jul 28 '22 12:07 leolambertucci

For anyone else reading this and wondering how to work around this, I removed the leading / from any file query, and it works. But this fix should be merged if the maintainer is so inclined.

addepar-tg avatar Sep 29 '23 09:09 addepar-tg