Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for using arbitrary Go template when generating markdown. #1008

Merged
merged 1 commit into from
Mar 4, 2020
Merged

Add support for using arbitrary Go template when generating markdown. #1008

merged 1 commit into from
Mar 4, 2020

Conversation

j0n3lson
Copy link
Contributor

@j0n3lson j0n3lson commented Jan 9, 2020

What type of PR is this?

/kind feature

What this PR does / why we need it:

Adds the ability to render notes in markdown using a user-supplied template. A default template is supplied with this PR and is used by default when neither a template string or template file are specified.

This makes the tool less opinionated about the output format and gives the user a bit more control over the output. Wanting to customize the markdown output seems like a common use-case for this tool.

Additionally, users would not need to create wrappers around kubernetes/release just to customize their output (e.g. release-notes -> JSON -> Go template -> Desired output).

Which issue(s) this PR fixes:

Partially addresses urfave/cli#965

Special notes for your reviewer:

This idea was originally suggested by @saschagrunert.

Does this PR introduce a user-facing change?:

Adds a new option for the `--format=go-template:path/to/template.file` which allows a user to specify an arbitrary go-template file. The default format is `--format=go-template:default` and will render the release notes in markdown format. A `--format="markdown"` form is accepted but deprecated.

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. kind/feature Categorizes issue or PR as related to a new feature. labels Jan 9, 2020
@k8s-ci-robot
Copy link
Contributor

Thanks for your pull request. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please follow instructions at https://git.k8s.io/community/CLA.md#the-contributor-license-agreement to sign the CLA.

It may take a couple minutes for the CLA signature to be fully registered; after that, please reply here with a new comment and we'll verify. Thanks.


Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. label Jan 9, 2020
@k8s-ci-robot
Copy link
Contributor

Welcome @j0n3lson!

It looks like this is your first PR to kubernetes/release 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes/release has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Jan 9, 2020
@k8s-ci-robot
Copy link
Contributor

Hi @j0n3lson. Thanks for your PR.

I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jan 9, 2020
@k8s-ci-robot k8s-ci-robot added area/release-eng Issues or PRs related to the Release Engineering subproject sig/release Categorizes an issue or PR as relevant to SIG Release. labels Jan 9, 2020
@j0n3lson j0n3lson marked this pull request as ready for review January 10, 2020 00:26
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jan 10, 2020
@j0n3lson
Copy link
Contributor Author

/assign @saschagrunert

@j0n3lson
Copy link
Contributor Author

/check-cla
/cc @lynncyrin

@k8s-ci-robot
Copy link
Contributor

@j0n3lson: GitHub didn't allow me to request PR reviews from the following users: lynncyrin.

Note that only kubernetes members and repo collaborators can review this PR, and authors cannot review their own PRs.

In response to this:

/check-cla
/cc @lynncyrin

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@coilysiren
Copy link

In case it's helpful for +1 person reinforcing this point: me and @saschagrunert are looking to use the k8s release notes generator for urfave/cli! @j0n3lson has been doing a bunch of legwork to make that happen 🙏

@j0n3lson
Copy link
Contributor Author

/check-cla

@saschagrunert
Copy link
Member

saschagrunert commented Jan 10, 2020

Awesome, thanks. 🙏 This will help us to spread the tool around the world.

@j0n3lson can you please sign the CNCF CLA here.

/ok-to-test
/cc @justaugustus this is a great opportunity to bring the tool into use-cases outside of the k8s ecosystem. 😇

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jan 10, 2020
Copy link
Member

@saschagrunert saschagrunert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally LGTM, I would recommend in going from markdown template to go template file to have it a bit more generic. Later on we could also add support for template strings, but this seems out of scope for now.

cmd/release-notes/main.go Outdated Show resolved Hide resolved
cmd/release-notes/main.go Outdated Show resolved Hide resolved
@saschagrunert
Copy link
Member

/assign @justaugustus @hoegaarden @cpanato @hasheddan

asking kindly for review

@coilysiren
Copy link

I was reminded of this while writing up my most recent release 😄 urfave/cli#1077

@j0n3lson
Copy link
Contributor Author

j0n3lson commented Feb 27, 2020 via email

@justaugustus
Copy link
Member

Thanks @j0n3lson! Keep us posted. :)

@j0n3lson
Copy link
Contributor Author

j0n3lson commented Mar 2, 2020

Quick update:

  • I rebased and also added capability to render the downloads table (previous revision did not have it)

Working on:

Thinking about:

  • Golden file testing. The document_test.go file doesn't have much testing. I thought it'd be great to do an end-to-end test for rendering using a test repo. We could compare the output against a golden file that we check in.

Hoping to finish up with this soon. Sorry for the long wait :)

@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. and removed lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Mar 3, 2020
@j0n3lson
Copy link
Contributor Author

j0n3lson commented Mar 3, 2020

@saschagrunert @justaugustus

Could you have a look. I updated the reviewer notes with some specific questions I had. My test are failing because ValidateAndFinish() has a cyclomatic complexity score of 31. I could fix it but didn't want to expand the scope here.

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Mar 3, 2020
@saschagrunert
Copy link
Member

saschagrunert commented Mar 3, 2020

@saschagrunert @justaugustus

Could you have a look. I updated the reviewer notes with some specific questions I had. My test are failing because ValidateAndFinish() has a cyclomatic complexity score of 31. I could fix it but didn't want to expand the scope here.

We could either reduce the cyclomatic complexity (I can do that as a follow up as well) or you add something like this to .golangci.yml:

linters-settings:
  gocyclo:
    min-complexity: 35

Comment on lines +288 to +291
// TODO: Not sure these options are guaranteed to be set but we need
// them in rendering. Perhaps these should be set in CreateDocument()?
doc.PreviousRevision = opts.StartRev
doc.CurrentRevision = opts.EndRev
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking about something like this too, we couple a var to two different functionalities (rendering and revision retrieval), which seems kinda bad. Let's stick to the TODO for now and follow-up later on this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I answered my own question about whether they're guaranteed to be set:

The default value for Options.DiscoverMode is RevisionDiscoveryModeNONE which means that either or both Options.StartRev and Options.EndRev can be empty.

With existing implementation will see an error if Options.ReleaseTars is given and the above is true (createDownloadsTable() will raise the error). This revision maintains that behavior though (FetchMetadata() will raise the error instead).

pkg/notes/internal/template.go Outdated Show resolved Hide resolved
@j0n3lson
Copy link
Contributor Author

j0n3lson commented Mar 4, 2020

@saschagrunert @justaugustus
Could you have a look. I updated the reviewer notes with some specific questions I had. My test are failing because ValidateAndFinish() has a cyclomatic complexity score of 31. I could fix it but didn't want to expand the scope here.

We could either reduce the cyclomatic complexity (I can do that as a follow up as well) or you add something like this to .golangci.yml:

linters-settings:
  gocyclo:
    min-complexity: 35

Bumped the min-complexity per your suggestion.

Copy link
Member

@saschagrunert saschagrunert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 4, 2020
@saschagrunert
Copy link
Member

PTAL @justaugustus @hasheddan

@justaugustus
Copy link
Member

Bumped the min-complexity per your suggestion.

@j0n3lson -- Can you remove that change and instead add:

//nolint:gocyclo

above the function?
Also, add a TODO to remind us to address the complexity.

Average cyclo is much lower and we should encourage less complex functions by having the linter fail.

@justaugustus
Copy link
Member

In retrospect, this has been open for a while, so let's merge and iterate.
Thanks for your work on this, @j0n3lson!

/lgtm
/approve
/hold cancel

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Mar 4, 2020
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: j0n3lson, justaugustus, saschagrunert

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 4, 2020
@k8s-ci-robot k8s-ci-robot merged commit 85301b5 into kubernetes:master Mar 4, 2020
@k8s-ci-robot k8s-ci-robot added this to the v1.18 milestone Mar 4, 2020
@coilysiren
Copy link

👀 🚀 !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/release-eng Issues or PRs related to the Release Engineering subproject cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/feature Categorizes issue or PR as related to a new feature. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/release Categorizes an issue or PR as relevant to SIG Release. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants