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

fix(changelog): consider placeholder for old version #664

Conversation

roggervalf
Copy link
Contributor

@roggervalf roggervalf commented Jul 26, 2023

ref #652

@roggervalf
Copy link
Contributor Author

roggervalf commented Jul 26, 2023

hi @bernardcooke53 , do you know if there are test cases to cover the case where template_dir does not exist https://github.com/python-semantic-release/python-semantic-release/blob/master/semantic_release/cli/commands/changelog.py#L57?

@bernardcooke53
Copy link
Contributor

Hi @roggervalf - apologies, I've been quite unwell for the last couple of weeks and haven't really been able to look at this. I will try to look in more detail in the next couple of days, I would like to see an additional piece of logic:

  • If the changelog placeholder is detected, emit a warning of deprecation before falling back to the old behaviour implemented
  • I don't want to put the placeholder into the default changelog template, but I'm ok with a "legacy" changelog template that has one; or a switch to add it to the content.

I appreciate that might not be the most clear explanation, will come back to this in the near future

@roggervalf
Copy link
Contributor Author

Hi @roggervalf - apologies, I've been quite unwell for the last couple of weeks and haven't really been able to look at this. I will try to look in more detail in the next couple of days, I would like to see an additional piece of logic:

* If the changelog placeholder is detected, emit a warning of deprecation before falling back to the old behaviour implemented

* I don't want to put the placeholder into the default changelog template, but I'm ok with a "legacy" changelog template that has one; or a switch to add it to the content.

I appreciate that might not be the most clear explanation, will come back to this in the near future

thank you @bernardcooke53, no worries, take your time

Copy link
Contributor

@bernardcooke53 bernardcooke53 left a comment

Choose a reason for hiding this comment

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

I have left some comments - thank you for putting the code together!

I would want to see some changes before merging this, but am happy to help or to draft those up and get your review on them, as you prefer

@@ -27,7 +27,7 @@


def tags_and_versions(
tags: Iterable[Tag], translator: VersionTranslator
tags: Iterable[Tag], translator: VersionTranslator, only_last_release: bool = False
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think it's necessary to add this, it's not the purpose of tags_and_versions at all. There's only one location where you intend to set this to True, I don't see why you can't just add the [0] there?

f.truncate()
existed_changelog_sections = existed_changelog_text.split(CHANGELOG_PLACEHOLDER)
if len(existed_changelog_sections) > 1:
log.warning("Deprecation: Placeholder is detected, only new changes will be added.")
Copy link
Contributor

Choose a reason for hiding this comment

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

👍 for warning, but it would be good to include a link to Migrating an Existing Changelog

Comment on lines +56 to +58
f.seek(0)
existed_changelog_text = f.read()
f.truncate()
Copy link
Contributor

Choose a reason for hiding this comment

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

This is error-prone - if there's an exception later on then we will have truncated the changelog without writing any text back to it

existed_changelog_text = f.read()
f.truncate()
existed_changelog_sections = existed_changelog_text.split(CHANGELOG_PLACEHOLDER)
if len(existed_changelog_sections) > 1:
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's a much simpler check to have f"{CHANGELOG_PLACEHOLDER}\n" in f.readlines() - avoids trying to split. The text could (by chance) by in a commit message which would lead to issues.

You can always do

existing_changelog_text = f.read()
f.seek(0)
lines = f.readlines()

to get both, or even

lines = f.readlines()
existing_changelog_text = "".join(lines)

changelog_text = render_default_changelog_file(env)
with open(str(changelog_file), "w+", encoding="utf-8") as f:
f.write(changelog_text)
with open(str(changelog_file), "a+", encoding="utf-8") as f:
Copy link
Contributor

Choose a reason for hiding this comment

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

why open in append mode?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hey @bernardcooke53, because I'm reading and writing

existed_changelog_sections = existed_changelog_text.split(CHANGELOG_PLACEHOLDER)
if len(existed_changelog_sections) > 1:
log.warning("Deprecation: Placeholder is detected, only new changes will be added.")
rh = ReleaseHistory.from_git_history(
Copy link
Contributor

Choose a reason for hiding this comment

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

We always iterate in reverse order over the commits, which means the latest release is the first one inserted into ReleaseHistory.released.

You can get the last release by doing:

full_rh = ReleaseHistory.from_git_history(<the existing params>)
latest_release_version = next(iter(full_rh.unreleased), None)
latest_release = full_rh.released.get(latest_release_version, {})

rh = ReleaseHistory(unreleased=full_rh.unreleased, released=latest_release)

This works because dicts remember their insertion order so next will find the oldest-inserted key

Copy link
Contributor Author

Choose a reason for hiding this comment

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

with these suggestions I'm not sure how to keep the existing changelog, as I don't want to override previous changelogs, only add the latest changelog

Copy link
Contributor

Choose a reason for hiding this comment

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

General comment - there's no testing for this functionality, would be nice to see some tests added for it

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 need some help on making a test for it

Copy link

This PR is stale because it has not been confirmed or planned by the maintainers and had been open 60 days with no recent activity. It will be closed in 10 days,
if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale label Mar 25, 2024
Copy link

This PR was closed because activity was dormant for 70 days.

@github-actions github-actions bot closed this Apr 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants