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

a tera variable or filter for previous_version #55

Closed
sassman opened this issue Jan 31, 2022 · 1 comment
Closed

a tera variable or filter for previous_version #55

sassman opened this issue Jan 31, 2022 · 1 comment
Assignees
Labels
feature/request New feature or request

Comments

@sassman
Copy link

sassman commented Jan 31, 2022

For context:
I'm using in my changelog usually links that point to GitHubs version compare pages like this:

## [Unreleased]
[Unreleased]: https://github.com/steganogram/stegano-rs/compare/v0.5.0...HEAD

## [0.4.10] - 2021-11-15
[0.4.10]: https://github.com/steganogram/stegano-rs/compare/v0.4.10...v0.4.9

so there are links that points to the GitHub code compare, for the actual version (v0.4.10) with the "previous" (v0.4.9) semver version that was released, and the last released version (v0.5.0) with the HEAD

In order to make this same changelog available by cliff I've tried the cliff.toml as below:

# template for the changelog body
# https://tera.netlify.app/docs/#introduction
body = """
{% if version %}\
    ## [{{ version | trim_start_matches(pat="v") }}] {{ timestamp | date(format="%Y-%m-%d") }}
    [{{ version | trim_start_matches(pat="v") }}]: https://github.com/sassman/putzen-rs/compare/{{ version }}...{{ previous_version }}
{% else %}\
    ## [unreleased]
    [Unreleased]: https://github.com/sassman/putzen-rs/compare/{{ latest_version }}...HEAD
{% endif %}\

I guess this variables could be very tricky to provide, but maybe when assuming semver version tags it might be possible to have them all parsed and prepared for the tera rendering.

Alternatively it might be a filter available that goes to the previous version of a given version number like this:

    [{{ version | trim_start_matches(pat="v") }}]: https://github.com/sassman/putzen-rs/compare/{{ version }}...{{ version | previous_release }}
@sassman sassman added the feature/request New feature or request label Jan 31, 2022
@orhun
Copy link
Owner

orhun commented Feb 6, 2022

Hey Sven!

Have you tried using the previous field which is mentioned in the template context?

So you can use it like this to get the same result:

{% if version %}\
    ## [{{ version | trim_start_matches(pat="v") }}] {{ timestamp | date(format="%Y-%m-%d") }}
    [{{ version | trim_start_matches(pat="v") }}]: https://github.com/sassman/putzen-rs/compare/{{ version }}...{{ previous.version }}
{% else %}\
    ## [unreleased]
    [Unreleased]: https://github.com/sassman/putzen-rs/compare/{{ previous.version }}...HEAD
{% endif %}\

But be aware, this will only work if you run git-cliff with --unreleased or --latest flags. Otherwise you might get template errors due to previous.version not being present. In that case you can add another conditional check to avoid this error.

Hope this helps 🙂

@orhun orhun closed this as completed Apr 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature/request New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants