Skip to content

Commit

Permalink
Support rendering description for breaking changes and known issues (#…
Browse files Browse the repository at this point in the history
…129)

* changelog: add newlines for readability

* changelog: add crossreferenceList template Fn

* changelog: support description in rendered changelog

* changelog: test description presence

* fragment: note when description is rendered

* add fragment

* fragment: update fragment in test
  • Loading branch information
endorama authored Jan 9, 2023
1 parent 517e3be commit 9c133b6
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 7 deletions.
32 changes: 32 additions & 0 deletions changelog/fragments/1673258661-Support-rendering-description.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Kind can be one of:
# - breaking-change: a change to previously-documented behavior
# - deprecation: functionality that is being removed in a later release
# - bug-fix: fixes a problem in a previous version
# - enhancement: extends functionality but does not break or fix existing behavior
# - feature: new functionality
# - known-issue: problems that we are aware of in a given version
# - security: impacts on the security of a product or a user’s deployment.
# - upgrade: important information for someone upgrading from a prior version
# - other: does not fit into any of the other categories
kind: feature

# Change summary; a 80ish characters long description of the change.
summary: Support rendering description for breaking changes and known issues.

# Long description; in case the summary is not enough to describe the change
# this field accommodate a description without length limits.
# NOTE: This field will be rendered only for breaking-change and known-issue kinds at the moment.
#description:

# Affected component; a word indicating the component this changeset affects.
component:

# PR number; optional; the PR number that added the changeset.
# If not present is automatically filled by the tooling finding the PR where this changelog fragment has been added.
# NOTE: the tooling supports backports, so it's able to fill the original PR number instead of the backport PR number.
# Please provide it if you are adding a fragment for a different PR.
#pr: 1234

# Issue number; optional; the GitHub issue related to this changeset (either closes or is part of).
# If not present is automatically filled by the tooling with the issue linked to the PR number.
#issue: 1234
24 changes: 21 additions & 3 deletions internal/assets/asciidoc-template.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Review important information about the {{.Component}} {{.Version}} release.
{{- end }}
{{- end }}
{{- end }}

{{ if .BreakingChange -}}
[discrete]
[[breaking-changes-{{.Version}}]]
Expand All @@ -30,10 +31,17 @@ impact to your application.
{{ range $k, $v := .BreakingChange }}
{{ $k | header2}}
{{ range $item := $v }}
* {{ $item.Summary | beautify }} {{ linkPRSource $item.Component $item.LinkedPR }} {{ linkIssueSource $item.Component $item.LinkedIssue }}
[discrete]
[[breaking-{{crossreferenceList $item.LinkedPR}}]]
.{{ $item.Summary | beautify }} {{ linkPRSource $item.Component $item.LinkedPR }} {{ linkIssueSource $item.Component $item.LinkedIssue }}
[%collapsible]
====
{{ $item.Description }}
====
{{- end }}
{{- end }}
{{- end }}

{{ if .KnownIssue -}}
[discrete]
[[known-issues-{{.Version}}]]
Expand All @@ -43,10 +51,17 @@ impact to your application.
{{ range $k, $v := .KnownIssue }}
{{ $k | header2}}
{{ range $item := $v }}
* {{ $item.Summary | beautify }} {{ linkPRSource $item.Component $item.LinkedPR }} {{ linkIssueSource $item.Component $item.LinkedIssue }}
[discrete]
[[known-issue-issue-{{crossreferenceList $item.LinkedIssue}}]]
.{{ $item.Summary | beautify }} {{ linkPRSource $item.Component $item.LinkedPR }} {{ linkIssueSource $item.Component $item.LinkedIssue }}
[%collapsible]
====
{{ $item.Description }}
====
{{- end }}
{{- end }}
{{- end }}

{{ if .Deprecation -}}
[discrete]
[[deprecations-{{.Version}}]]
Expand All @@ -64,6 +79,7 @@ upgrade to {{.Version}}.
{{- end }}
{{- end }}
{{- end }}

{{ if .Feature -}}
[discrete]
[[new-features-{{.Version}}]]
Expand All @@ -78,6 +94,7 @@ The {{.Version}} release adds the following new and notable features.
{{- end }}
{{- end }}
{{- end }}

{{ if .Enhancement }}
[discrete]
[[enhancements-{{.Version}}]]
Expand All @@ -90,6 +107,7 @@ The {{.Version}} release adds the following new and notable features.
{{- end }}
{{- end }}
{{- end }}

{{ if .BugFix }}
[discrete]
[[bug-fixes-{{.Version}}]]
Expand All @@ -103,4 +121,4 @@ The {{.Version}} release adds the following new and notable features.
{{- end }}
{{- end }}

// end {{.Version}} relnotes
// end {{.Version}} relnotes
1 change: 1 addition & 0 deletions internal/changelog/fragment/creator_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ summary: foobar

# Long description; in case the summary is not enough to describe the change
# this field accommodate a description without length limits.
# NOTE: This field will be rendered only for breaking-change and known-issue kinds at the moment.
#description:

# Affected component; a word indicating the component this changeset affects.
Expand Down
1 change: 1 addition & 0 deletions internal/changelog/fragment/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ summary: {{.Summary}}

# Long description; in case the summary is not enough to describe the change
# this field accommodate a description without length limits.
# NOTE: This field will be rendered only for breaking-change and known-issue kinds at the moment.
#description:

# Affected component; a word indicating the component this changeset affects.
Expand Down
3 changes: 3 additions & 0 deletions internal/changelog/renderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ func (r Renderer) Render() error {

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))
Expand Down
9 changes: 5 additions & 4 deletions internal/changelog/renderer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,11 @@ func TestRenderer(t *testing.T) {
switch e.Kind {
// NOTE: this is the list of kinds of entries we expect to see
// in the rendered changelog (not all kinds are expected)
case changelog.BreakingChange, changelog.Deprecation,
changelog.BugFix, changelog.Enhancement,
changelog.Feature, changelog.KnownIssue,
changelog.Security:
case changelog.BreakingChange, changelog.KnownIssue:
require.Contains(t, strings.ToLower(string(out)), e.Summary)
require.Contains(t, string(out), e.Description)
case changelog.Deprecation, changelog.BugFix, changelog.Enhancement,
changelog.Feature, changelog.Security:
require.Contains(t, strings.ToLower(string(out)), e.Summary)
default:
require.NotContains(t, strings.ToLower(string(out)), e.Summary)
Expand Down
3 changes: 3 additions & 0 deletions internal/changelog/testdata/1648040928-breaking-change.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
kind: breaking-change
summary: a breaking change
description: This paragraph to describe details and impact of this breaking change
pr: 1234
component: whatever
3 changes: 3 additions & 0 deletions internal/changelog/testdata/1648040928-known-issue.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
kind: known-issue
summary: a known issue
description: This paragraph to describe details and impact of this known issue
issue: 1234
component: whatever

0 comments on commit 9c133b6

Please sign in to comment.