func()

in internal/changelog/renderer.go [39:138]


func (r Renderer) Render() error {
	log.Printf("render changelog for version: %s\n", r.changelog.Version)

	tpl, err := r.Template()
	if err != nil {
		log.Fatal(err)
	}

	type TemplateData struct {
		Component string
		Version   string
		Changelog Changelog
		Kinds     map[Kind]bool

		BreakingChange map[string][]Entry
		Deprecation    map[string][]Entry
		BugFix         map[string][]Entry
		Enhancement    map[string][]Entry
		Feature        map[string][]Entry
		KnownIssue     map[string][]Entry
		Security       map[string][]Entry
		Upgrade        map[string][]Entry
		Other          map[string][]Entry
	}

	td := TemplateData{
		buildTitleByComponents(r.changelog.Entries), r.changelog.Version, r.changelog,
		collectKinds(r.changelog.Entries),
		collectByKindMap(r.changelog.Entries, BreakingChange),
		collectByKindMap(r.changelog.Entries, Deprecation),
		collectByKindMap(r.changelog.Entries, BugFix),
		collectByKindMap(r.changelog.Entries, Enhancement),
		collectByKindMap(r.changelog.Entries, Feature),
		collectByKindMap(r.changelog.Entries, KnownIssue),
		collectByKindMap(r.changelog.Entries, Security),
		collectByKindMap(r.changelog.Entries, Upgrade),
		collectByKindMap(r.changelog.Entries, Other),
	}

	tmpl, err := template.New("release-notes").
		Funcs(template.FuncMap{
			"crossreferenceList": func(ids []string) string {
				return strings.Join(ids, "-")
			},
			// nolint:staticcheck // ignoring for now, supports for multiple component is not implemented
			"linkPRSource": func(component string, ids []string) string {
				res := make([]string, len(ids))

				for i, id := range ids {
					res[i] = fmt.Sprintf("{%s-pull}%v[#%v]", component, id, id)
				}

				return strings.Join(res, " ")
			},
			// nolint:staticcheck // ignoring for now, supports for multiple component is not implemented
			"linkIssueSource": func(component string, ids []string) string {
				res := make([]string, len(ids))

				for i, id := range ids {
					res[i] = fmt.Sprintf("{%s-issue}%v[#%v]", component, id, id)
				}

				return strings.Join(res, " ")
			},
			// Capitalize sentence and ensure ends with .
			"beautify": func(s1 string) string {
				s2 := strings.Builder{}
				s2.WriteString(cases.Title(language.English).String(s1))
				if !strings.HasSuffix(s1, ".") {
					s2.WriteString(".")
				}
				return s2.String()
			},
			// Ensure components have section styling
			"header2": func(s1 string) string {
				s2 := strings.Builder{}
				s2.WriteString(s1)
				if !strings.HasSuffix(s1, "::") && s1 != "" {
					s2.WriteString("::")
				}
				return s2.String()
			},
		}).
		Parse(string(tpl))
	if err != nil {
		panic(err)
	}

	var data bytes.Buffer

	err = tmpl.Execute(&data, td)
	if err != nil {
		panic(err)
	}

	outFile := path.Join(r.dest, fmt.Sprintf("%s.asciidoc", r.changelog.Version))
	log.Printf("saving changelog in %s\n", outFile)

	return afero.WriteFile(r.fs, outFile, data.Bytes(), changelogFilePerm)
}