Skip to content

Commit

Permalink
fix(parsing): Check for CODEOWNERS files for both GitHub and GitLab (#45
Browse files Browse the repository at this point in the history
)

Fixes #44
  • Loading branch information
heaths authored Oct 25, 2024
1 parent 01f12d1 commit db9c01e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion codeowners.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func dirExists(fsys fs.FS, path string) (bool, error) {
func findCodeownersFile(fsys fs.FS, wd string) (io.Reader, string, error) {
dir := wd
for {
for _, p := range []string{".", "docs", ".github", ".gitlab"} {
for _, p := range []string{".github", ".", "docs", ".gitlab"} {
pth := path.Join(dir, p)
exists, err := dirExists(fsys, pth)
if err != nil {
Expand Down
11 changes: 11 additions & 0 deletions codeowners_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ func TestFindCodeownersFile(t *testing.T) {
"src/.github/CODEOWNERS": &fstest.MapFile{Data: []byte(sample)},
"src/foo/CODEOWNERS": &fstest.MapFile{Data: []byte(sample2)},
"src/foo/qux/docs/CODEOWNERS": &fstest.MapFile{Data: []byte(sample3)},
"src/bar/CODEOWNERS": &fstest.MapFile{Data: []byte(sample2)},
"src/bar/.github/CODEOWNERS": &fstest.MapFile{Data: []byte(sample)},
"src/bar/.gitlab/CODEOWNERS": &fstest.MapFile{Data: []byte(sample3)},
}

r, root, err := findCodeownersFile(fsys, "src")
Expand Down Expand Up @@ -191,6 +194,14 @@ func TestFindCodeownersFile(t *testing.T) {
r, _, err = findCodeownersFile(fsys, ".")
require.NoError(t, err)
assert.Nil(t, r)

r, root, err = findCodeownersFile(fsys, "src/bar")
require.NoError(t, err)
assert.NotNil(t, r)
assert.Equal(t, "src/bar", root)

b, _ = io.ReadAll(r)
assert.Equal(t, sample, string(b))
}

func co(pattern string, owners []string) Codeowner {
Expand Down

0 comments on commit db9c01e

Please sign in to comment.