-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
codeowners.go
39 lines (33 loc) · 988 Bytes
/
codeowners.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Package codeowners provides funcionality to evaluate CODEOWNERS file.
package codeowners // import "github.com/fmenezes/codeowners"
import (
"strings"
"unicode"
)
// DefaultLocations provides default locations for the CODEOWNERS file
var DefaultLocations = [...]string{"CODEOWNERS", "docs/CODEOWNERS", ".github/CODEOWNERS"}
// sanitiseLine removes all empty space and comments from a given line
func sanitiseLine(line string) string {
i := strings.Index(line, "#")
if i >= 0 {
line = line[:i]
}
return strings.Trim(line, " ")
}
// ParseLine parses a CODEOWNERS line into file pattern and owners
func ParseLine(line string) (string, []string) {
line = sanitiseLine(line)
var previousRune rune
data := strings.FieldsFunc(line, func(r rune) bool {
result := unicode.IsSpace(r) && previousRune != '\\'
previousRune = r
return result
})
if len(data) > 1 {
return data[0], data[1:]
} else if len(data) == 1 {
return data[0], nil
} else {
return "", nil
}
}