Skip to content

Commit

Permalink
Merge pull request #1148 from j0n3lson/fr-use-templates
Browse files Browse the repository at this point in the history
Follow up to PR#1008: Lazy loading of format spec and Sorting Notes
  • Loading branch information
k8s-ci-robot authored Mar 14, 2020
2 parents 336be0f + 1709ca0 commit cda4043
Show file tree
Hide file tree
Showing 17 changed files with 481 additions and 282 deletions.
1 change: 1 addition & 0 deletions cmd/krel/cmd/changelog.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ func generateReleaseNotes(opts *changelogOptions, branch, startRev, endRev strin
return "", errors.Wrapf(err, "creating release note document")
}

//nolint:golint,deprecated // RenderMarkdown is soft deprecated and will be removed in #1019. Use RenderMarkdownTemplate
markdown, err := doc.RenderMarkdown(
opts.bucket, opts.tars, notesOptions.StartRev, notesOptions.EndRev,
)
Expand Down
1 change: 1 addition & 0 deletions cmd/krel/cmd/release_notes.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@ func releaseNotesFrom(startTag string) (*releaseNotesResult, error) {
}

// Create the markdown
//nolint:golint,deprecated // RenderMarkdown is soft deprecated and will be removed in #1019. Use RenderMarkdownTemplate
markdown, err := doc.RenderMarkdown(
"", "", notesOptions.StartRev, notesOptions.EndRev,
)
Expand Down
38 changes: 19 additions & 19 deletions cmd/release-notes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,28 +69,28 @@ level=debug timestamp=2019-07-30T04:02:44.3716249Z caller=notes.go:497 msg="Excl

## Options

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

## Building From Source

Expand Down
17 changes: 10 additions & 7 deletions cmd/release-notes/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,14 @@ func init() {
cmd.PersistentFlags().StringVar(
&opts.Format,
"format",
util.EnvDefault("FORMAT", "go-template:default"),
util.EnvDefault("FORMAT", options.FormatSpecDefaultGoTemplate),
fmt.Sprintf("The format for notes output (options: %s)",
strings.Join([]string{"markdown", "json", "go-template:default"}, ", "),
strings.Join([]string{
options.FormatSpecNone,
options.FormatSpecMarkdown, //nolint:golint,deprecated // This option internally corresponds to options.FormatSpecGoTemplateDefault
options.FormatSpecJSON,
options.FormatSpecDefaultGoTemplate,
}, ", "),
),
)

Expand Down Expand Up @@ -281,9 +286,7 @@ func WriteReleaseNotes(releaseNotes notes.ReleaseNotes, history notes.ReleaseNot
if err := enc.Encode(releaseNotes); err != nil {
return errors.Wrapf(err, "encoding JSON output")
}
case strings.Contains(format, "go-template"):
goTemplate := strings.Split(format, ":")[1]

case strings.HasPrefix(format, "go-template:"):
doc, err := document.CreateDocument(releaseNotes, history)
if err != nil {
return errors.Wrapf(err, "creating release note document")
Expand All @@ -294,9 +297,9 @@ func WriteReleaseNotes(releaseNotes notes.ReleaseNotes, history notes.ReleaseNot
doc.PreviousRevision = opts.StartRev
doc.CurrentRevision = opts.EndRev

markdown, err := doc.RenderMarkdownTemplate(opts.ReleaseBucket, opts.ReleaseTars, goTemplate)
markdown, err := doc.RenderMarkdownTemplate(opts.ReleaseBucket, opts.ReleaseTars, opts.Format)
if err != nil {
return errors.Wrapf(err, "rendering release note document to markdown")
return errors.Wrapf(err, "rendering release note document with template")
}

if opts.TableOfContents {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/golangci/golangci-lint v1.23.3
github.com/google/go-github/v29 v29.0.3
github.com/google/uuid v1.1.1
github.com/kr/pretty v0.1.0
github.com/kylelemons/godebug v1.1.0
github.com/maxbrunsfeld/counterfeiter/v6 v6.2.2
github.com/nozzle/throttler v0.0.0-20180817012639-2ea982251481
github.com/pkg/errors v0.9.1
Expand Down
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ github.com/gliderlabs/ssh v0.2.2 h1:6zsha5zo/TWhRhwqCD3+EarCAgZ2yN28ipRnGPnwkI0=
github.com/gliderlabs/ssh v0.2.2/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0=
github.com/go-critic/go-critic v0.4.1 h1:4DTQfT1wWwLg/hzxwD9bkdhDQrdJtxe6DUTadPlrIeE=
github.com/go-critic/go-critic v0.4.1/go.mod h1:7/14rZGnZbY6E38VEGk2kVhoq6itzc1E68facVDK23g=
github.com/go-kit/kit v0.8.0 h1:Wz+5lgoB0kkuqLEc6NVmwRknTKP6dTGbSqvhZtBI/j0=
github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
github.com/go-lintpack/lintpack v0.5.2 h1:DI5mA3+eKdWeJ40nU4d6Wc26qmdG8RCi/btYq0TuRN0=
github.com/go-lintpack/lintpack v0.5.2/go.mod h1:NwZuYi2nUHho8XEIZ6SIxihrnPoqBTDqfpXvXAN0sXM=
Expand Down Expand Up @@ -226,6 +227,8 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/pty v1.1.8/go.mod h1:O1sed60cT9XZ5uDucP5qwvh+TE3NnUj51EiZO/lmSfw=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/logrusorgru/aurora v0.0.0-20181002194514-a7b3b318ed4e/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4=
Expand Down
18 changes: 14 additions & 4 deletions pkg/notes/document/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")

go_library(
name = "go_default_library",
srcs = ["document.go"],
srcs = [
"document.go",
"template.go",
],
importpath = "k8s.io/release/pkg/notes/document",
visibility = ["//visibility:public"],
deps = [
"//pkg/notes:go_default_library",
"//pkg/notes/options:go_default_library",
"//pkg/release:go_default_library",
"@com_github_pkg_errors//:go_default_library",
],
Expand All @@ -15,12 +19,12 @@ go_library(
go_test(
name = "go_default_test",
srcs = ["document_test.go"],
data = glob(["testdata/**"]),
data = [":testdata"],
embed = [":go_default_library"],
deps = [
"//pkg/notes/internal:go_default_library",
"//pkg/notes/options:go_default_library",
"//pkg/release:go_default_library",
"@com_github_kr_pretty//:go_default_library",
"@com_github_kylelemons_godebug//diff:go_default_library",
"@com_github_stretchr_testify//require:go_default_library",
"@io_bazel_rules_go//go/tools/bazel:go_default_library",
],
Expand All @@ -39,3 +43,9 @@ filegroup(
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

filegroup(
name = "testdata",
srcs = glob(["testdata/**"]),
visibility = ["//visibility:private"],
)
Loading

0 comments on commit cda4043

Please sign in to comment.