Skip to content

Commit cda4043

Browse files
authored
Merge pull request #1148 from j0n3lson/fr-use-templates
Follow up to PR#1008: Lazy loading of format spec and Sorting Notes
2 parents 336be0f + 1709ca0 commit cda4043

File tree

17 files changed

+481
-282
lines changed

17 files changed

+481
-282
lines changed

cmd/krel/cmd/changelog.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ func generateReleaseNotes(opts *changelogOptions, branch, startRev, endRev strin
262262
return "", errors.Wrapf(err, "creating release note document")
263263
}
264264

265+
//nolint:golint,deprecated // RenderMarkdown is soft deprecated and will be removed in #1019. Use RenderMarkdownTemplate
265266
markdown, err := doc.RenderMarkdown(
266267
opts.bucket, opts.tars, notesOptions.StartRev, notesOptions.EndRev,
267268
)

cmd/krel/cmd/release_notes.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,7 @@ func releaseNotesFrom(startTag string) (*releaseNotesResult, error) {
361361
}
362362

363363
// Create the markdown
364+
//nolint:golint,deprecated // RenderMarkdown is soft deprecated and will be removed in #1019. Use RenderMarkdownTemplate
364365
markdown, err := doc.RenderMarkdown(
365366
"", "", notesOptions.StartRev, notesOptions.EndRev,
366367
)

cmd/release-notes/README.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -69,28 +69,28 @@ level=debug timestamp=2019-07-30T04:02:44.3716249Z caller=notes.go:497 msg="Excl
6969

7070
## Options
7171

72-
| Flag | Env Variable | Default Value | Required | Description |
73-
| ----------------------- | --------------- | ------------------ | -------- | --------------------------------------------------------------------------------------------------------------------------------- |
72+
| Flag | Env Variable | Default Value | Required | Description |
73+
| ----------------------- | --------------- | ------------------- | -------- | --------------------------------------------------------------------------------------------------------------------------------- |
7474
| **GITHUB REPO OPTIONS** |
75-
| | GITHUB_TOKEN | | Yes | A personal GitHub access token |
76-
| github-org | GITHUB_ORG | kubernetes | Yes | Name of GitHub organization |
77-
| github-repo | GITHUB_REPO | kubernetes | Yes | Name of GitHub repository |
78-
| required-author | REQUIRED_AUTHOR | k8s-ci-robot | Yes | Only commits from this GitHub user are considered. Set to empty string to include all users |
79-
| branch | BRANCH | master | Yes | The GitHub repository branch to scrape |
80-
| start-sha | START_SHA | | Yes | The commit hash to start processing from (inclusive) |
81-
| end-sha | END_SHA | | Yes | The commit hash to end processing at (inclusive) |
82-
| repo-path | REPO_PATH | /tmp/k8s-repo | No | Path to a local Kubernetes repository, used only for tag discovery |
83-
| start-rev | START_REV | | No | The git revision to start at. Can be used as alternative to start-sha |
84-
| env-rev | END_REV | | No | The git revision to end at. Can be used as alternative to end-sha |
85-
| discover | DISCOVER | none | No | The revision discovery mode for automatic revision retrieval (options: none, mergebase-to-latest, patch-to-patch, minor-to-minor) |
86-
| release-bucket | RELEASE_BUCKET | kubernetes-release | No | Specify gs bucket to point to in generated notes (default "kubernetes-release") |
87-
| release-tars | RELEASE_TARS | | No | Directory of tars to sha512 sum for display |
75+
| | GITHUB_TOKEN | | Yes | A personal GitHub access token |
76+
| github-org | GITHUB_ORG | kubernetes | Yes | Name of GitHub organization |
77+
| github-repo | GITHUB_REPO | kubernetes | Yes | Name of GitHub repository |
78+
| required-author | REQUIRED_AUTHOR | k8s-ci-robot | Yes | Only commits from this GitHub user are considered. Set to empty string to include all users |
79+
| branch | BRANCH | master | Yes | The GitHub repository branch to scrape |
80+
| start-sha | START_SHA | | Yes | The commit hash to start processing from (inclusive) |
81+
| end-sha | END_SHA | | Yes | The commit hash to end processing at (inclusive) |
82+
| repo-path | REPO_PATH | /tmp/k8s-repo | No | Path to a local Kubernetes repository, used only for tag discovery |
83+
| start-rev | START_REV | | No | The git revision to start at. Can be used as alternative to start-sha |
84+
| env-rev | END_REV | | No | The git revision to end at. Can be used as alternative to end-sha |
85+
| discover | DISCOVER | none | No | The revision discovery mode for automatic revision retrieval (options: none, mergebase-to-latest, patch-to-patch, minor-to-minor) |
86+
| release-bucket | RELEASE_BUCKET | kubernetes-release | No | Specify gs bucket to point to in generated notes (default "kubernetes-release") |
87+
| release-tars | RELEASE_TARS | | No | Directory of tars to sha512 sum for display |
8888
| **OUTPUT OPTIONS** |
89-
| output | OUTPUT | | No | The path where the release notes will be written |
90-
| format | FORMAT | markdown | Yes | The format for notes output (options: markdown, json, go-template:path/to/template.file) |
91-
| release-version | RELEASE_VERSION | | No | The release version to tag the notes with |
89+
| output | OUTPUT | | No | The path where the release notes will be written |
90+
| format | FORMAT | go-template:default | Yes | The format for notes output (options: json, go-template:path/to/template.file) |
91+
| release-version | RELEASE_VERSION | | No | The release version to tag the notes with |
9292
| **LOG OPTIONS** |
93-
| debug | DEBUG | false | No | Enable debug logging (options: true, false) |
93+
| debug | DEBUG | false | No | Enable debug logging (options: true, false) |
9494

9595
## Building From Source
9696

cmd/release-notes/main.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,14 @@ func init() {
142142
cmd.PersistentFlags().StringVar(
143143
&opts.Format,
144144
"format",
145-
util.EnvDefault("FORMAT", "go-template:default"),
145+
util.EnvDefault("FORMAT", options.FormatSpecDefaultGoTemplate),
146146
fmt.Sprintf("The format for notes output (options: %s)",
147-
strings.Join([]string{"markdown", "json", "go-template:default"}, ", "),
147+
strings.Join([]string{
148+
options.FormatSpecNone,
149+
options.FormatSpecMarkdown, //nolint:golint,deprecated // This option internally corresponds to options.FormatSpecGoTemplateDefault
150+
options.FormatSpecJSON,
151+
options.FormatSpecDefaultGoTemplate,
152+
}, ", "),
148153
),
149154
)
150155

@@ -281,9 +286,7 @@ func WriteReleaseNotes(releaseNotes notes.ReleaseNotes, history notes.ReleaseNot
281286
if err := enc.Encode(releaseNotes); err != nil {
282287
return errors.Wrapf(err, "encoding JSON output")
283288
}
284-
case strings.Contains(format, "go-template"):
285-
goTemplate := strings.Split(format, ":")[1]
286-
289+
case strings.HasPrefix(format, "go-template:"):
287290
doc, err := document.CreateDocument(releaseNotes, history)
288291
if err != nil {
289292
return errors.Wrapf(err, "creating release note document")
@@ -294,9 +297,9 @@ func WriteReleaseNotes(releaseNotes notes.ReleaseNotes, history notes.ReleaseNot
294297
doc.PreviousRevision = opts.StartRev
295298
doc.CurrentRevision = opts.EndRev
296299

297-
markdown, err := doc.RenderMarkdownTemplate(opts.ReleaseBucket, opts.ReleaseTars, goTemplate)
300+
markdown, err := doc.RenderMarkdownTemplate(opts.ReleaseBucket, opts.ReleaseTars, opts.Format)
298301
if err != nil {
299-
return errors.Wrapf(err, "rendering release note document to markdown")
302+
return errors.Wrapf(err, "rendering release note document with template")
300303
}
301304

302305
if opts.TableOfContents {

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ require (
1010
github.com/golangci/golangci-lint v1.23.3
1111
github.com/google/go-github/v29 v29.0.3
1212
github.com/google/uuid v1.1.1
13-
github.com/kr/pretty v0.1.0
13+
github.com/kylelemons/godebug v1.1.0
1414
github.com/maxbrunsfeld/counterfeiter/v6 v6.2.2
1515
github.com/nozzle/throttler v0.0.0-20180817012639-2ea982251481
1616
github.com/pkg/errors v0.9.1

go.sum

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ github.com/gliderlabs/ssh v0.2.2 h1:6zsha5zo/TWhRhwqCD3+EarCAgZ2yN28ipRnGPnwkI0=
6464
github.com/gliderlabs/ssh v0.2.2/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0=
6565
github.com/go-critic/go-critic v0.4.1 h1:4DTQfT1wWwLg/hzxwD9bkdhDQrdJtxe6DUTadPlrIeE=
6666
github.com/go-critic/go-critic v0.4.1/go.mod h1:7/14rZGnZbY6E38VEGk2kVhoq6itzc1E68facVDK23g=
67+
github.com/go-kit/kit v0.8.0 h1:Wz+5lgoB0kkuqLEc6NVmwRknTKP6dTGbSqvhZtBI/j0=
6768
github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
6869
github.com/go-lintpack/lintpack v0.5.2 h1:DI5mA3+eKdWeJ40nU4d6Wc26qmdG8RCi/btYq0TuRN0=
6970
github.com/go-lintpack/lintpack v0.5.2/go.mod h1:NwZuYi2nUHho8XEIZ6SIxihrnPoqBTDqfpXvXAN0sXM=
@@ -226,6 +227,8 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
226227
github.com/kr/pty v1.1.8/go.mod h1:O1sed60cT9XZ5uDucP5qwvh+TE3NnUj51EiZO/lmSfw=
227228
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
228229
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
230+
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
231+
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
229232
github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
230233
github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
231234
github.com/logrusorgru/aurora v0.0.0-20181002194514-a7b3b318ed4e/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4=

pkg/notes/document/BUILD.bazel

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
22

33
go_library(
44
name = "go_default_library",
5-
srcs = ["document.go"],
5+
srcs = [
6+
"document.go",
7+
"template.go",
8+
],
69
importpath = "k8s.io/release/pkg/notes/document",
710
visibility = ["//visibility:public"],
811
deps = [
912
"//pkg/notes:go_default_library",
13+
"//pkg/notes/options:go_default_library",
1014
"//pkg/release:go_default_library",
1115
"@com_github_pkg_errors//:go_default_library",
1216
],
@@ -15,12 +19,12 @@ go_library(
1519
go_test(
1620
name = "go_default_test",
1721
srcs = ["document_test.go"],
18-
data = glob(["testdata/**"]),
22+
data = [":testdata"],
1923
embed = [":go_default_library"],
2024
deps = [
21-
"//pkg/notes/internal:go_default_library",
25+
"//pkg/notes/options:go_default_library",
2226
"//pkg/release:go_default_library",
23-
"@com_github_kr_pretty//:go_default_library",
27+
"@com_github_kylelemons_godebug//diff:go_default_library",
2428
"@com_github_stretchr_testify//require:go_default_library",
2529
"@io_bazel_rules_go//go/tools/bazel:go_default_library",
2630
],
@@ -39,3 +43,9 @@ filegroup(
3943
tags = ["automanaged"],
4044
visibility = ["//visibility:public"],
4145
)
46+
47+
filegroup(
48+
name = "testdata",
49+
srcs = glob(["testdata/**"]),
50+
visibility = ["//visibility:private"],
51+
)

0 commit comments

Comments
 (0)