summaryrefslogtreecommitdiff
path: root/generator
diff options
context:
space:
mode:
Diffstat (limited to 'generator')
-rw-r--r--generator/aliases.tmpl13
-rw-r--r--generator/app.go25
-rw-r--r--generator/app_test.go40
3 files changed, 53 insertions, 25 deletions
diff --git a/generator/aliases.tmpl b/generator/aliases.tmpl
new file mode 100644
index 00000000..32c71cc6
--- /dev/null
+++ b/generator/aliases.tmpl
@@ -0,0 +1,13 @@
+aliases:
+ {{- range .Sigs}}
+ {{.Dir}}-leads:
+ {{- range .Leads}}
+ - {{.GitHub}}
+ {{- end}}
+ {{- end}}
+ {{- range .WorkingGroups}}
+ {{.Dir}}-leads:
+ {{- range .Leads}}
+ - {{.GitHub}}
+ {{- end}}
+ {{- end}}
diff --git a/generator/app.go b/generator/app.go
index 79e08cd3..3f75e65b 100644
--- a/generator/app.go
+++ b/generator/app.go
@@ -31,12 +31,14 @@ import (
)
const (
- readmeTemplate = "readme.tmpl"
- listTemplate = "list.tmpl"
- headerTemplate = "header.tmpl"
+ readmeTemplate = "readme.tmpl"
+ listTemplate = "list.tmpl"
+ aliasesTemplate = "aliases.tmpl"
+ headerTemplate = "header.tmpl"
sigsYamlFile = "sigs.yaml"
sigListOutput = "sig-list.md"
+ aliasesOutput = "OWNERS_ALIASES"
indexFilename = "README.md"
beginMarker = "<!-- BEGIN CUSTOM CONTENT -->"
@@ -154,7 +156,7 @@ func tzUrlEncode(tz string) string {
return strings.Replace(url.QueryEscape(tz), "+", "%20", -1)
}
-func writeTemplate(templatePath, outputPath string, data interface{}) error {
+func writeTemplate(templatePath, outputPath string, customContent bool, data interface{}) error {
// set up template
t, err := template.New(filepath.Base(templatePath)).
Funcs(funcMap).
@@ -194,7 +196,9 @@ func writeTemplate(templatePath, outputPath string, data interface{}) error {
}
// custom content block
- writeCustomContentBlock(f, content)
+ if customContent {
+ writeCustomContentBlock(f, content)
+ }
return nil
}
@@ -230,7 +234,7 @@ func createGroupReadme(groups []Group, prefix string) error {
outputPath := filepath.Join(outputDir, indexFilename)
readmePath := filepath.Join(baseGeneratorDir, templateDir, fmt.Sprintf("%s_%s", prefix, readmeTemplate))
- if err := writeTemplate(readmePath, outputPath, group); err != nil {
+ if err := writeTemplate(readmePath, outputPath, true, group); err != nil {
return err
}
}
@@ -270,7 +274,14 @@ func main() {
fmt.Println("Generating sig-list.md")
outputPath := filepath.Join(baseGeneratorDir, sigListOutput)
- err = writeTemplate(filepath.Join(baseGeneratorDir, templateDir, listTemplate), outputPath, ctx)
+ err = writeTemplate(filepath.Join(baseGeneratorDir, templateDir, listTemplate), outputPath, true, ctx)
+ if err != nil {
+ log.Fatal(err)
+ }
+
+ fmt.Println("Generating OWNERS_ALIASES")
+ outputPath = filepath.Join(baseGeneratorDir, aliasesOutput)
+ err = writeTemplate(filepath.Join(baseGeneratorDir, templateDir, aliasesTemplate), outputPath, false, ctx)
if err != nil {
log.Fatal(err)
}
diff --git a/generator/app_test.go b/generator/app_test.go
index 965e0d47..038e470d 100644
--- a/generator/app_test.go
+++ b/generator/app_test.go
@@ -94,34 +94,38 @@ content!
`
cases := []struct {
- templatePath string
- outputPath string
- data map[string]string
- expectErr bool
- expected string
+ templatePath string
+ outputPath string
+ data map[string]string
+ expectErr bool
+ customContent bool
+ expected string
}{
{
- templatePath: "./testdata/non_existent_template.tmpl",
- expectErr: true,
+ templatePath: "./testdata/non_existent_template.tmpl",
+ expectErr: true,
+ customContent: true,
},
{
- templatePath: "./testdata/example.tmpl",
- outputPath: "/tmp/non_existing_path.md",
- expectErr: false,
- data: map[string]string{"Message": "Hello!"},
- expected: "Hello!",
+ templatePath: "./testdata/example.tmpl",
+ outputPath: "/tmp/non_existing_path.md",
+ expectErr: false,
+ customContent: true,
+ data: map[string]string{"Message": "Hello!"},
+ expected: "Hello!",
},
{
- templatePath: "./testdata/example.tmpl",
- outputPath: "./testdata/example.md",
- expectErr: false,
- data: map[string]string{"Message": "Hello!"},
- expected: customContent,
+ templatePath: "./testdata/example.tmpl",
+ outputPath: "./testdata/example.md",
+ expectErr: false,
+ customContent: true,
+ data: map[string]string{"Message": "Hello!"},
+ expected: customContent,
},
}
for _, c := range cases {
- err := writeTemplate(c.templatePath, c.outputPath, c.data)
+ err := writeTemplate(c.templatePath, c.outputPath, c.customContent, c.data)
if err != nil && c.expectErr == false {
t.Fatalf("Received unexpected error for %s: %v", c.templatePath, err)
}