Skip to content

Commit

Permalink
feat: introduces asciidoc format
Browse files Browse the repository at this point in the history
  • Loading branch information
bartoszmajsak committed Dec 5, 2019
1 parent 78bb79b commit 5ab151d
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 25 deletions.
8 changes: 7 additions & 1 deletion pkg/cmd/generate/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ func NewCmd() *cobra.Command {
var (
from,
repo,
format,
tag string
)
generateCmd := &cobra.Command{
Expand All @@ -26,7 +27,11 @@ func NewCmd() *cobra.Command {
RunE: func(cmd *cobra.Command, args []string) error { //nolint[:unparam]
pullRequests := fetchRelatedPRs(repo, from)
sortDependencyPRs(pullRequests)
t, err := template.New("changelog").Parse(Default)
tpl := Default
if cmd.Flag("format").Value.String() == "adoc" {
tpl = DefaultAdoc
}
t, err := template.New("changelog").Parse(tpl)
if err != nil {
return err
}
Expand All @@ -38,6 +43,7 @@ func NewCmd() *cobra.Command {
}

generateCmd.Flags().StringVarP(&tag, "tag", "t", "UNRELEASED", "tag used for current release")
generateCmd.Flags().StringVar(&format, "format", "md", "format of generated release notes")
generateCmd.Flags().StringVarP(&from, "from", "f", "", "from for which changelog should be generated")
generateCmd.Flags().StringVarP(&repo, "repository", "r", "", "repository URL")

Expand Down
60 changes: 36 additions & 24 deletions pkg/cmd/generate/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,101 +8,113 @@ type Changelog struct {
}

const Default = `
### New features
{{- with $prs := (index .PullRequests "enhancement") -}}
{{ if $prs }}
### New features
{{range $pr := $prs }}
* {{$pr.Title}} ([#{{$pr.Number}}]({{$pr.Permalink}})), by [@{{$pr.Author}}](https://github.com/{{$pr.Author}})
{{- end -}}
{{ end }}
### Bug fixes
{{ end }}
{{- with $prs := (index .PullRequests "bug") -}}
{{ if $prs }}
### Bug fixes
{{range $pr := $prs }}
* {{$pr.Title}} ([#{{$pr.Number}}]({{$pr.Permalink}})), by [@{{$pr.Author}}](https://github.com/{{$pr.Author}})
{{- end -}}
{{ end }}
### Dependencies update
{{ end }}
{{- with $prs := (index .PullRequests "dependencies") -}}
{{ if $prs }}
### Dependencies update
{{range $pr := $prs }}
* {{$pr.Title}} ([#{{$pr.Number}}]({{$pr.Permalink}}))
{{- end -}}
{{ end }}
### Project infrastructure
{{ end }}
{{- with $prs := (index .PullRequests "infra") -}}
{{ if $prs }}
### Project infrastructure
{{range $pr := $prs }}
* {{$pr.Title}} ([#{{$pr.Number}}]({{$pr.Permalink}})), by [@{{$pr.Author}}](https://github.com/{{$pr.Author}})
{{- end -}}
{{ end }}
### Testing
{{ end }}
{{- with $prs := (index .PullRequests "test-infra") -}}
{{ if $prs }}
### Testing
{{range $pr := $prs }}
* {{$pr.Title}} ([#{{$pr.Number}}]({{$pr.Permalink}})), by [@{{$pr.Author}}](https://github.com/{{$pr.Author}})
{{- end -}}
{{ end }}
{{ end }}
{{- with $prs := (index .PullRequests "misc") -}}
{{ if $prs }}
### Misc
{{- with $prs := (index .PullRequests "uncategorized") -}}
{{range $pr := $prs }}
* {{$pr.Title}} ([#{{$pr.Number}}]({{$pr.Permalink}})), by [@{{$pr.Author}}](https://github.com/{{$pr.Author}})
{{- end -}}
{{ end }}
{{ end }}
`

const DefaultAdoc = `
=== New features
{{- with $prs := (index .PullRequests "enhancement") -}}
{{ if $prs }}
=== New features
{{range $pr := $prs }}
* {{$pr.Title}} ({{$pr.Permalink}}[#{{$pr.Number}}]), by https://github.com/{{$pr.Author}}[@{{$pr.Author}}]
{{- end -}}
{{ end }}
=== Bug fixes
{{ end }}
{{- with $prs := (index .PullRequests "bug") -}}
{{ if $prs }}
=== Bug fixes
{{range $pr := $prs }}
* {{$pr.Title}} ({{$pr.Permalink}}[#{{$pr.Number}}]), by https://github.com/{{$pr.Author}}[@{{$pr.Author}}]
{{- end -}}
{{ end }}
=== Dependencies update
{{ end }}
{{- with $prs := (index .PullRequests "dependencies") -}}
{{ if $prs }}
=== Dependencies update
{{range $pr := $prs }}
* {{$pr.Title}} ({{$pr.Permalink}}[#{{$pr.Number}}])
{{- end -}}
{{ end }}
=== Project infrastructure
{{ end }}
{{- with $prs := (index .PullRequests "infra") -}}
{{ if $prs }}
=== Project infrastructure
{{range $pr := $prs }}
* {{$pr.Title}} ({{$pr.Permalink}}[#{{$pr.Number}}]), by https://github.com/{{$pr.Author}}[@{{$pr.Author}}]
{{- end -}}
{{ end }}
=== Testing
{{ end }}
{{- with $prs := (index .PullRequests "test-infra") -}}
{{ if $prs }}
=== Testing
{{range $pr := $prs }}
* {{$pr.Title}} ({{$pr.Permalink}}[#{{$pr.Number}}]), by https://github.com/{{$pr.Author}}[@{{$pr.Author}}]
{{- end -}}
{{ end }}
{{ end }}
{{- with $prs := (index .PullRequests "misc") -}}
{{ if $prs }}
=== Misc
{{- with $prs := (index .PullRequests "uncategorized") -}}
{{range $pr := $prs }}
* {{$pr.Title}} ([#{{$pr.Number}}]({{$pr.Permalink}})), by [@{{$pr.Author}}](https://github.com/{{$pr.Author}})
{{- end -}}
{{ end }}
{{ end }}
`

0 comments on commit 5ab151d

Please sign in to comment.