-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcodeowners.go
47 lines (38 loc) · 1.02 KB
/
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
40
41
42
43
44
45
46
47
package internal
import (
"bufio"
"fmt"
"os"
"strings"
)
// SearchCodeOwners reads and processes the CODEOWNERS file.
func SearchCodeOwners(file string, verbose bool) error {
if verbose {
fmt.Println(Colorize(fmt.Sprintf("Reading CODEOWNERS file: %s", file), Yellow))
}
// Open the CODEOWNERS file
codeownersFile := file
f, err := os.Open(codeownersFile)
if err != nil {
return fmt.Errorf("could not open CODEOWNERS file: %v", err)
}
defer f.Close()
// Print the file header
fmt.Println(Colorize("CODEOWNERS File:", Green))
// Read the file line by line
scanner := bufio.NewScanner(f)
for scanner.Scan() {
line := scanner.Text()
// Skip empty lines and comments
if strings.TrimSpace(line) == "" || strings.HasPrefix(line, "#") {
continue
}
// Print valid entries
fmt.Println(Colorize(line, Blue))
}
// Handle any errors during file reading
if err := scanner.Err(); err != nil {
return fmt.Errorf("error reading CODEOWNERS file: %v", err)
}
return nil
}