Skip to content

Commit

Permalink
fix(changelog): don't repost version on bot connect (#156)
Browse files Browse the repository at this point in the history
  • Loading branch information
natelandau authored Jun 17, 2024
1 parent 09ea04d commit de16c09
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/valentina/models/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,7 @@ async def post_changelog_to_guild(self, guild: discord.Guild) -> None:
oldest_version=db_guild.changelog_posted_version,
newest_version=db_global_properties.most_recent_version,
with_personality=True,
exclude_oldest_version=True,
)
except errors.VersionNotFoundError:
logger.error(f"CHANGELOG: Could not find version {self.version} in the changelog")
Expand Down
17 changes: 15 additions & 2 deletions src/valentina/models/changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def __init__(
oldest_version: str | None = None,
newest_version: str | None = None,
with_personality: bool = False,
exclude_oldest_version: bool = False,
):
self.exclude_categories = exclud_cagegories
self.bot = bot
Expand All @@ -46,6 +47,7 @@ def __init__(
exclude_categories=self.exclude_categories,
oldest_version=oldest_version,
newest_version=newest_version,
exclude_oldest_version=exclude_oldest_version,
)

self.oldest_version, self.newest_version = self._validate_versions(
Expand Down Expand Up @@ -159,6 +161,7 @@ def __init__(
oldest_version: str | None = None,
newest_version: str | None = None,
exclude_categories: list[str] = [],
exclude_oldest_version: bool = False,
):
self.path = CHANGELOG_PATH
self.bot = bot
Expand All @@ -175,6 +178,8 @@ def __init__(
"build",
]
self.exclude_categories = exclude_categories
self.exclude_oldest_version = exclude_oldest_version

self.oldest_version = (
(oldest_version if self.__check_version_schema(oldest_version) else None)
if oldest_version
Expand Down Expand Up @@ -203,7 +208,7 @@ def __get_changelog(self) -> str:

return self.path.read_text()

def __parse_changelog(self) -> dict[str, dict[str, str | list[str]]]:
def __parse_changelog(self) -> dict[str, dict[str, str | list[str]]]: # noqa: C901
"""Parse the changelog into a dictionary.
Loop through each line in the changelog, identifying the version and category of each entry.
Expand Down Expand Up @@ -231,6 +236,14 @@ def __parse_changelog(self) -> dict[str, dict[str, str | list[str]]]:
if version_match := version_re.match(line):
version_being_parsed = version_match.group(1)

# When requested, do not parse the oldest version
# This is used when automatically posting the changelog on bot connect
if self.exclude_oldest_version and semver.Version.parse(
version_being_parsed
) == semver.Version.parse(self.oldest_version):
parse_version = False
continue

if (
semver.Version.parse(version_being_parsed)
>= semver.Version.parse(self.oldest_version)
Expand Down Expand Up @@ -314,7 +327,7 @@ def list_of_versions(self) -> list[str]:
Returns:
list[str]: A list of all versions in the changelog.
"""
return list(self.changelog_dict.keys())
return sorted(self.changelog_dict.keys(), key=semver.Version.parse, reverse=True)

def get_text(self) -> str:
"""Generate a text version of the changelog."""
Expand Down
45 changes: 45 additions & 0 deletions tests/models/test_changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,51 @@ def test_changelog_get_embed(changelog, mock_bot): # noqa: ARG001
- Lorem ipsum dolor sit amet
----
View the [full changelog on Github](https://github.com/natelandau/valentina/releases)
"""
)


def test_changelog_get_embed_exclude_oldest(changelog, mock_bot): # noqa: ARG001
"""Test the ChangelogParser get_embed method with exclude_oldest."""
parser = ChangelogParser(
mock_bot, oldest_version="1.1.0", newest_version="2.0.0", exclude_oldest_version=True
)

embed = parser.get_embed()

assert (
embed.description
== """\
## Valentina Noir Changelog
### v2.0.0 (2023-11-04)
**Feat**
- Lorem ipsum dolor sit amet
- Lorem ipsum dolor sit amet
**Fix**
- Lorem ipsum dolor sit amet
- Lorem ipsum dolor sit amet
**Test**
- Lorem ipsum dolor sit amet
- Lorem ipsum dolor sit amet
**Build**
- Lorem ipsum dolor sit amet
- Lorem ipsum dolor sit amet
**Ci**
- Lorem ipsum dolor sit amet
- Lorem ipsum dolor sit amet
**Chore**
- Lorem ipsum dolor sit amet
- Lorem ipsum dolor sit amet
----
View the [full changelog on Github](https://github.com/natelandau/valentina/releases)
"""
Expand Down

0 comments on commit de16c09

Please sign in to comment.