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

TemplateCache: 'customs' should allow missing keys #536

Closed
abhinav opened this issue Sep 16, 2023 · 1 comment · Fixed by #538
Closed

TemplateCache: 'customs' should allow missing keys #536

abhinav opened this issue Sep 16, 2023 · 1 comment · Fixed by #538
Labels
enhancement New feature or request

Comments

@abhinav
Copy link
Contributor

abhinav commented Sep 16, 2023

Is your feature request related to a problem? Please describe.

Currently, the customs template function will return an error if a requested key was missing for any of the changelog entries.
This makes it difficult to add a new custom key with existing unreleased changes.

For example, if you do:

changie init
changie new # answer prompts
changie new # answer prompts

$EDITOR .changie.yaml 
# Add a new custom config, and use it in the template with `{{customs .Changes "Foo"}}`.

changie batch
# Error: missing custom key: 'Foo'

Describe the solution you'd like
The customs function should return an empty string for keys that are absent.
This will match the behavior of directly accessing the custom field via .Change.Custom.Foo.

Alternatively, if this this change is considered breaking, a new function customValues would do.

Describe alternatives you've considered
Iterating over .Changes and accessing the custom fields directly.
This isn't as nice because you can't post-process and dedupe, e.g. customs .Changes "Foo" | compact | uniq.

Additional context
If we're in agreement about the change, I'm happy to make a PR for it.

@abhinav abhinav added the enhancement New feature or request label Sep 16, 2023
@miniscruff
Copy link
Owner

Hmm, I think my idea for this at the time was that, it could prevent typos if you see an error over an empty string. But I agree it is a little lame thinking about it again. I agree with this change.

abhinav added a commit to abhinav/changie that referenced this issue Sep 16, 2023
If 'customs' returns an error for missing keys on changes,
it's difficult to add a new custom key with unreleased changes pending
and a template that uses 'customs'.

Change 'customs' to yield an empty string for a missing custom key.
This matches the behavior of accessing the missing key directly
via `$change.Custom.Foo`.

Resolves miniscruff#536
miniscruff added a commit that referenced this issue Sep 16, 2023
If 'customs' returns an error for missing keys on changes,
it's difficult to add a new custom key with unreleased changes pending
and a template that uses 'customs'.

Change 'customs' to yield an empty string for a missing custom key.
This matches the behavior of accessing the missing key directly
via `$change.Custom.Foo`.

Resolves #536

* Prepare release v1.13.1

Co-authored-by: Ronnie <miniscruff@hey.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants