Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore GitLab sections #20

Merged
merged 2 commits into from
Jul 8, 2023
Merged

Ignore GitLab sections #20

merged 2 commits into from
Jul 8, 2023

Conversation

matteosilv
Copy link
Contributor

GitLab-flavored CODEOWNERS style supports sections within [] characters.

This change ignores them as it is for comments.

@hairyhenderson
Copy link
Owner

Thanks @matteosilv!

Looking at the GitHub CODEOWNERS syntax doc the only mention of [] I can see is a warning that those characters are not supported for pattern-matching.

So, I think this remains compatible with both.

@hairyhenderson
Copy link
Owner

@matteosilv would you be able to add some tests to cover this functionality?

@matteosilv
Copy link
Contributor Author

@hairyhenderson never had time to do that sorry. Hopefully I can add test ASAP

@SirUli
Copy link

SirUli commented Jul 7, 2023

@matteosilv @hairyhenderson Testing could be something like this:

diff --git a/codeowners_test.go b/codeowners_test.go
index a1b6620..4f81770 100644
--- a/codeowners_test.go
+++ b/codeowners_test.go
@@ -24,6 +24,10 @@ var (
 docs/**        @org/docteam @joe`
        sample2 = `* @hairyhenderson`
        sample3 = `baz/* @baz @qux`
+        sample4 = `[test]
+*       @everyone
+[test2][2]
+*/foo   @everyoneelse`
 
        codeowners []Codeowner
 )
@@ -40,6 +44,17 @@ func TestParseCodeowners(t *testing.T) {
        assert.Equal(t, expected, c)
 }
 
+func TestParseCodeownersSections(t *testing.T) {
+        t.Parallel()
+        r := bytes.NewBufferString(sample4)
+        c := parseCodeowners(r)
+        expected := []Codeowner{
+                co("*", []string{"@everyone"}),
+                co("*/foo", []string{"@everyoneelse"}),
+        }
+        assert.Equal(t, expected, c)
+}
+
 func BenchmarkParseCodeowners(b *testing.B) {
        r := bytes.NewBufferString(sample)
        var c []Codeowner

At least for me that solves the testing part of it. Hopefully you'll be able to push this for a release then :)

@hairyhenderson
Copy link
Owner

Thanks for taking the time to work that out, @SirUli!

matteosilv and others added 2 commits July 8, 2023 15:40
GitLab-flavored CODEOWNERS style supports sections within [] characters.

This change ignores them as it is for comments.
Signed-off-by: Dave Henderson <dhenderson@gmail.com>
@hairyhenderson hairyhenderson enabled auto-merge (rebase) July 8, 2023 19:41
@hairyhenderson hairyhenderson added the enhancement New feature or request label Jul 8, 2023
@hairyhenderson hairyhenderson merged commit e3921c7 into hairyhenderson:main Jul 8, 2023
4 of 5 checks passed
@SirUli
Copy link

SirUli commented Jul 9, 2023

Awesome, thanks! Are you planning on creating a release sometime soon?

@hairyhenderson
Copy link
Owner

@SirUli yes I will - just needed to sort a few other things out first

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants