Skip to content

Commit 9e60517

Browse files
committed
add footer+gitCommit, sorting for 'appears on'
Signed-off-by: Ahmet Alp Balkan <ahmetb@google.com>
1 parent 29df140 commit 9e60517

2 files changed

Lines changed: 19 additions & 5 deletions

File tree

main.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"io/ioutil"
1111
"net/http"
1212
"os"
13+
"os/exec"
1314
"path/filepath"
1415
"reflect"
1516
"regexp"
@@ -393,6 +394,7 @@ func typeReferences(t *types.Type, c generatorConfig, references map[*types.Type
393394
for k := range m {
394395
out = append(out, k)
395396
}
397+
sortTypes(out)
396398
return out
397399
}
398400

@@ -401,16 +403,20 @@ func sortedTypes(typs map[string]*types.Type) []*types.Type {
401403
for _, t := range typs {
402404
out = append(out, t)
403405
}
404-
sort.Slice(out, func(i, j int) bool {
405-
t1, t2 := out[i], out[j]
406+
sortTypes(out)
407+
return out
408+
}
409+
410+
func sortTypes(typs []*types.Type) {
411+
sort.Slice(typs, func(i, j int) bool {
412+
t1, t2 := typs[i], typs[j]
406413
if isExportedType(t1) && !isExportedType(t2) {
407414
return true
408415
} else if !isExportedType(t1) && isExportedType(t2) {
409416
return false
410417
}
411418
return t1.Name.Name < t2.Name.Name
412419
})
413-
return out
414420
}
415421

416422
func visibleTypes(in []*types.Type, c generatorConfig) []*types.Type {
@@ -464,6 +470,8 @@ func apiVersionMap(pkgs []*types.Package) (map[string]string, error) {
464470
func render(w io.Writer, pkgs []*types.Package, config generatorConfig) error {
465471
references := findTypeReferences(pkgs)
466472

473+
gitCommit, _ := exec.Command("git", "rev-parse", "--short", "HEAD").Output()
474+
467475
apiVersions, err := apiVersionMap(pkgs)
468476
if err != nil {
469477
return errors.Wrap(err, "failed to infer apiVersions")
@@ -500,7 +508,8 @@ func render(w io.Writer, pkgs []*types.Package, config generatorConfig) error {
500508
}
501509

502510
return errors.Wrap(t.ExecuteTemplate(w, "packages", map[string]interface{}{
503-
"packages": pkgs,
504-
"config": config,
511+
"packages": pkgs,
512+
"config": config,
513+
"gitCommit": strings.TrimSpace(string(gitCommit)),
505514
}), "template execution error")
506515
}

template/pkg.tpl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,9 @@ table, td, th {
5252
<hr/>
5353
{{ end }}
5454

55+
<p><em>
56+
Generated with <code>gen-crd-api-reference-docs</code>
57+
{{ with .gitCommit }} on git commit <code>{{ . }}</code>{{end}}.
58+
</em></p>
59+
5560
{{ end }}

0 commit comments

Comments
 (0)