This repository has been archived by the owner on Jul 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
71 lines (56 loc) · 1.63 KB
/
main.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package main
import (
"os"
"github.com/nickw444/collect-owners/usernamedb"
"gopkg.in/alecthomas/kingpin.v2"
"regexp"
)
var Version string
func main() {
var (
app = kingpin.New("Collect Owners", "Walk A Repo and compile a Github CODEOWNERS file").Version(Version)
repo = app.Arg("repo", "Path to repository").Required().String()
contributors = app.Flag("contributors", "Path to contributors file to add to the users DB").String()
excludesRaw = app.Flag("exclude", "Regular expressions of paths to exclude").Strings()
addUnresolved = app.Flag("add-unresolved", "Add ownerships that do not have entries in the users DB as their raw entries within the OWNERS files").Bool()
)
kingpin.MustParse(app.Parse(os.Args[1:]))
var err error
repoRoot := *repo
var dbLoader usernamedb.DBLoader
if *contributors != "" {
dbLoader = &usernamedb.ContributorsFileDBLoader{
Filename: *contributors,
}
} else {
dbLoader = &usernamedb.SimpleDBLoader{}
}
usernameDb := &usernamedb.UsernameDB{
Loader: dbLoader,
AddUnresolved: *addUnresolved,
}
err = usernameDb.Load()
if err != nil {
panic(err)
}
formatter := &OwnersFileFormatter{
UsernameDB: usernameDb,
}
fileProcessor := &OwnersFileProcessor{
RepoRoot: repoRoot,
}
var excludes []*regexp.Regexp
for _, excludeRaw := range *excludesRaw {
excludes = append(excludes, regexp.MustCompile(excludeRaw))
}
treeProvider := OwnersTreeProvider{
ownersFileProcessor: fileProcessor,
RootPath: repoRoot,
Excludes: excludes,
}
rootEnt, err := treeProvider.GetFileTree()
if err != nil {
panic(err)
}
formatter.Format(rootEnt)
}