diff --git a/config.example.yaml b/config.example.yaml index 69950bb..1187fe0 100644 --- a/config.example.yaml +++ b/config.example.yaml @@ -1,6 +1,6 @@ changelogs: - kind: github - dir: dist + dir: dist/0.1 formats: - extension: asciidoc frontmatters: | @@ -24,13 +24,53 @@ changelogs: title: "Index Changelog" --- spec: - # No release - # owner: updatecli-test - #owner: olblak - #repository: nocode owner: updatecli repository: udash versionfilter: kind: semver pattern: ~0.1 + - kind: github + dir: dist/0.2 + formats: + - extension: asciidoc + frontmatters: | + --- + title: "{{ .Changelog.Name }}" + date: {{ .Changelog.PublishedAt }} + --- + filetemplate: | + {{ .FrontMatters }} + // Disclaimer: this file is generated, do not edit it manually. + + --- + {{ if .Changelog.DescriptionHTML }} + ++++ + + {{ .Changelog.DescriptionHTML }} + + ++++ + {{ else if .Changelog.Description}} + {{ .Changelog.Description }} + {{ end}} + --- + indexfrontmatters: | + --- + title: "Index Changelog" + --- + indexfiletemplate: | + {{ .FrontMatters }} + // Disclaimer: this file is generated, do not edit it manually. + [cols="1,1,1" options="header" frame="ends" grid="rows"] + |=== + | Name | Author | Published Time + {{ range $pos, $release := .Changelogs }} + | link:{{ $release.Tag }}[{{ $release.Name}}{{ if (eq $pos 0) }}(latest){{ end}}] | {{ $release.Author }} | {{ $release.PublishedAt }} + {{ end }} + |=== + spec: + owner: updatecli + repository: udash + versionfilter: + kind: semver + pattern: ~0.2 diff --git a/internal/core/changelog/config.go b/internal/core/changelog/config.go index ce59a24..7bb0299 100644 --- a/internal/core/changelog/config.go +++ b/internal/core/changelog/config.go @@ -28,38 +28,25 @@ var ( nameAsciidoc = "asciidoc" ) -/* -Config contains various information used to configure the way changelogs are retrieved -*/ +// Config contains various information used to configure the way changelogs are retrieved type Config struct { - /* - Name specifies the name of the changelog to retrieve. It is only used for identification purposes. - */ + // Name specifies the name of the changelog to retrieve. It is only used for identification purposes. Name string - /* - dir specifies the directory where changelog files will be repost. - */ + // dir specifies the directory where changelog files will be repost. Dir string - /* - kind specifies the kind of changelog to retrieve. - - accepted values: - * github - */ + // kind specifies the kind of changelog to retrieve. + // + // accepted values: + // * github + // Kind string - /* - format specifies the format of the changelog to generate. - */ + // format specifies the format of the changelog to generate. Formats []ConfigFormat - /* - spec specifies the configuration input for a specific kind of changelog. - */ + // spec specifies the configuration input for a specific kind of changelog. Spec interface{} } -/* -Sanitize ensures that the configuration is valid and that all required fields are set. -*/ +// Sanitize ensures that the configuration is valid and that all required fields are set. func (c *Config) Sanitize(configFile string) error { if c.Name != "" { @@ -101,9 +88,7 @@ func (c *Config) Sanitize(configFile string) error { return nil } -/* -SaveToDisk saves one changelog per file per format to disk -*/ +// SaveToDisk saves one changelog per file per format to disk func (c Config) SaveToDisk(changelogs []Spec) error { fmt.Println("Generating changelogs") @@ -134,7 +119,7 @@ func (c Config) SaveToDisk(changelogs []Spec) error { defaultChangelogDir, changelogs[i].Tag+".adoc", ) - if err = toAsciidocFile(data, filename); err != nil { + if err = toAsciidocFile(data, filename, format.FileTemplate); err != nil { fmt.Printf("creating asciidoc file %s: %v", filename, err) continue } @@ -156,7 +141,7 @@ func (c Config) SaveToDisk(changelogs []Spec) error { defaultChangelogDir, changelogs[i].Tag+".md", ) - if err = toMarkdownFile(data, filename); err != nil { + if err = toMarkdownFile(data, filename, format.FileTemplate); err != nil { fmt.Printf("creating markdown file %s: %v", filename, err) continue } @@ -205,8 +190,9 @@ func (c Config) SaveIndexToDisk(changelogs []Spec) error { switch format.Extension { case nameAsciidoc: + indexFileName := format.IndexFileName + ".adoc" - if err := toIndexAsciidocFile(data, filepath.Join(c.Dir, indexFileName)); err != nil { + if err := toIndexAsciidocFile(data, filepath.Join(c.Dir, indexFileName), format.IndexFileTemplate); err != nil { fmt.Printf("creating index asciidoc file %s: %v\n", filepath.Join(c.Dir, indexFileName), err) } @@ -235,7 +221,7 @@ func (c Config) SaveIndexToDisk(changelogs []Spec) error { case nameMarkdown: indexFileName := format.IndexFileName + ".md" - if err := toIndexMarkdownFile(data, filepath.Join(c.Dir, indexFileName)); err != nil { + if err := toIndexMarkdownFile(data, filepath.Join(c.Dir, indexFileName), format.IndexFileTemplate); err != nil { fmt.Printf("creating index markdown file %s: %v", filepath.Join(c.Dir, indexFileName), err) continue } diff --git a/internal/core/changelog/configFormat.go b/internal/core/changelog/configFormat.go index 833e993..66b612a 100644 --- a/internal/core/changelog/configFormat.go +++ b/internal/core/changelog/configFormat.go @@ -11,30 +11,45 @@ var ( ) type ConfigFormat struct { - /* - Extension is the file extension used for the changelog file. - accepted values: - * markdown - * json - - default: - * markdown - */ + // + // Extension is the file extension used for the changelog file. + // + // accepted values: + // * markdown + // * json + // * asciidoc + // + // default: markdown + // Extension string - /* - indexFileName is the name of the index file name without the extension. - - default: - * _index - */ + // FileTemplate is the template used to generate the changelog file + // + // default: depends on the extension + // + // remark: This setting is useless for json files + // + FileTemplate string + // indexFileName is the name of the index file name without the extension. + // + // default: '_index' + // IndexFileName string - /* - indexFrontMatters is the front matters using yaml syntax to add to the index file. - */ + // IndexFileTemplate is the template used to generate the index file + // + // default: depends on the extension + // + // remark: This setting is useless for json files + // + IndexFileTemplate string + // indexFrontMatters is the front matters using yaml syntax to add to the index file. + // + // default: empty + // IndexFrontMatters string - /* - frontmatters is the front matters using yaml syntax to add to the changelog file. - */ + // frontmatters is the front matters using yaml syntax to add to the changelog file. + // + // default: empty + // FrontMatters string } diff --git a/internal/core/changelog/format_asciidoc.go b/internal/core/changelog/format_asciidoc.go index 7aa3bbc..6fc9c76 100644 --- a/internal/core/changelog/format_asciidoc.go +++ b/internal/core/changelog/format_asciidoc.go @@ -62,9 +62,13 @@ __Information retrieved from link:{{ .Changelog.URL }}[here]__ ` ) -func toAsciidocFile(data ReleaseData, filename string) error { +func toAsciidocFile(data ReleaseData, filename string, fileTemplate string) error { - tmpl, err := template.New("asciidoc").Parse(asciidocTemplate) + if fileTemplate == "" { + fileTemplate = asciidocTemplate + } + + tmpl, err := template.New("asciidoc").Parse(fileTemplate) if err != nil { return fmt.Errorf("parsing template: %v", err) } @@ -83,11 +87,15 @@ func toAsciidocFile(data ReleaseData, filename string) error { return nil } -func toIndexAsciidocFile(data IndexData, filename string) error { +func toIndexAsciidocFile(data IndexData, filename string, fileTemplate string) error { + + if fileTemplate == "" { + fileTemplate = indexAsciidocTemplate + } tmpl, err := template.New("asciidoc"). Funcs(sprig.FuncMap()). - Parse(indexAsciidocTemplate) + Parse(fileTemplate) if err != nil { return fmt.Errorf("parsing template: %v", err) } diff --git a/internal/core/changelog/format_markdown.go b/internal/core/changelog/format_markdown.go index 30db1ef..cb8a32f 100644 --- a/internal/core/changelog/format_markdown.go +++ b/internal/core/changelog/format_markdown.go @@ -44,11 +44,15 @@ var ( ` ) -func toMarkdownFile(data ReleaseData, filename string) error { +func toMarkdownFile(data ReleaseData, filename string, fileTemplate string) error { + + if fileTemplate == "" { + fileTemplate = markdownTemplate + } tmpl, err := template.New("markdown"). Funcs(sprig.FuncMap()). - Parse(markdownTemplate) + Parse(fileTemplate) if err != nil { return fmt.Errorf("parsing template: %v", err) } @@ -67,9 +71,13 @@ func toMarkdownFile(data ReleaseData, filename string) error { return nil } -func toIndexMarkdownFile(data IndexData, filename string) error { +func toIndexMarkdownFile(data IndexData, filename string, fileTemplate string) error { + + if fileTemplate == "" { + fileTemplate = indexMarkownTemplate + } - tmpl, err := template.New("markdown").Parse(indexMarkownTemplate) + tmpl, err := template.New("markdown").Parse(fileTemplate) if err != nil { return fmt.Errorf("parsing template: %v", err) }