Skip to content

Support outputting a changelog in reStructuredText #384

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

Closed
jtpavlock opened this issue May 24, 2021 · 7 comments · Fixed by #645
Closed

Support outputting a changelog in reStructuredText #384

jtpavlock opened this issue May 24, 2021 · 7 comments · Fixed by #645
Labels
type: feature A new enhacement proposal

Comments

@jtpavlock
Copy link
Contributor

Description

As the title states, it would be convenient for use with sphinx documentation to be able to output the changelog in rst format.

Possible Solution

This seems like it should be a configuration option versus a commandline option.

@jtpavlock jtpavlock added the type: feature A new enhacement proposal label May 24, 2021
@Lee-W
Copy link
Member

Lee-W commented May 25, 2021

It might be related to this PR #376. I don't think we'll explicitly support reStructuredText but make the template customizable instead. This is still under discussion.

@woile
Copy link
Member

woile commented May 25, 2021

I find it a bit hard, because the "magic" is tied to markdown. Commitizen can detect your latest version by reading the titles (#), without affecting extra text nor your old changelog. By doing it this way, you can integrate commitizen into a project with an existing changelog (but only with markdown).

def parse_title_type_of_line(value: str) -> Optional[str]:
md_title_parser = r"^(?P<title>#+)"
m = re.search(md_title_parser, value)
if not m:
return None
return m.groupdict().get("title")

# Try to find the latest release done
version = parse_version_from_markdown(line)
if version:
latest_version = version
latest_version_position = index
break # there's no need for more info

It would involve quite some refactoring unfortunately.

An alternative could be running a markdown to rst as an step in a github action.

@jtpavlock
Copy link
Contributor Author

Commitizen can detect your latest version by reading the titles (#), without affecting extra text nor your old changelog.

Can I ask what the reason for this is as opposed to getting the project version programmatically via package inspection? Is this just a fallback?

@woile
Copy link
Member

woile commented May 25, 2021

We can't inspect a markdown file.

Let's say you didn't generate a changelog for the last 2 releases. What can we do to detect which was the latest release created? We go and read the changelog file.

Let's also say, the last release in the changelog, has been modified by the user. So you cannot replace it.
How do you detect the latest release created, and update the changelog leaving the previous releases untouched?

Because we are tied to markdown, we just compare against any text starting with one or more #, and we insert the incremented missing chunk of changelog, before that.

Also:

  • We must avoid lines that may contain a mention to the latest release. Example:
# Changelog

Latest release: 1.4.0

## 1.4.0
...

In the end the current solution seemed to be covering our use cases fine so far 😅

If there are better solutions I'd like to know more.

@jtpavlock
Copy link
Contributor Author

One solution could be to only generate the changelog for the latest release by default. Then, if someone wants to generate a changelog for all releases, have that be a command option. Users should only ever be generating a changelog for more than the most recent version of their project once, at the time of adoption of this tool.

If the user only wanted a changelog for the last X number of versions, then it would be an easy cut/paste job from the command generated changelog. Again, this scenario should only ever happen once in a project's lifetime, so not a big deal.

It doesn't seem you'd need to be inspecting any changelog files with this all or one generation approach, and then could theoretically support any number of file types, given the changelog output itself is configurable.

@woile
Copy link
Member

woile commented Jul 27, 2022

That makes a lot of sense and would simplify things a lot. Either generate all or latest, right?. If you need specific range you can use cz changelog 0.2.0..0.4.0 and that would cover all the cases. Is a trade-off over more manual work (sometimes), vs making it more flexible to support other formats.

One good thing about the detection of the title is that you can have a bunch of text before the changelog (like the recommendation of keepachangelog before start listing the changes). How could we achieve that?

@jtpavlock
Copy link
Contributor Author

jtpavlock commented Sep 3, 2022

One good thing about the detection of the title is that you can have a bunch of text before the changelog (like the recommendation of keepachangelog before start listing the changes). How could we achieve that?

A couple of options come to mind, but all require searching the changelog file:

  1. Search for a line with a regex match of the configured release title e.g. v\d\.\d\.\d or something
  2. Use some sort of delineator to split the header from the rest of the changelog like a comment or a dashed line.
  3. Instead of searching for # title for markdown, just include the ability to now search for the header in rst format if in an rst file.

Lee-W pushed a commit that referenced this issue Oct 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature A new enhacement proposal
Projects
None yet
3 participants