Skip to content

Commit 8ff1228

Browse files
authored
Add versions command (#31)
1 parent 51b254d commit 8ff1228

5 files changed

Lines changed: 82 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111
<!-- BEGIN RELEASE NOTES -->
1212
### [Unreleased]
1313

14+
### [0.7.0] - 2023-03-01
15+
16+
#### Added
17+
- Created the `manage versions` command
18+
1419
### [0.6.0] - 2023-02-08
1520

1621
#### Changed
@@ -79,7 +84,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7984
- `unreleased add`, which allows inline or prompted adding of unreleased changes.
8085
<!-- END RELEASE NOTES -->
8186
<!-- BEGIN LINKS -->
82-
[Unreleased]: https://github.com/award28/changelogger/compare/0.6.0...HEAD
87+
[Unreleased]: https://github.com/award28/changelogger/compare/0.7.0...HEAD
88+
[0.7.0]: https://github.com/award28/changelogger/compare/0.6.0...0.7.0
8389
[0.6.0]: https://github.com/award28/changelogger/compare/0.5.0...0.6.0
8490
[0.5.0]: https://github.com/award28/changelogger/compare/0.4.0...0.5.0
8591
[0.4.0]: https://github.com/award28/changelogger/compare/0.3.4...0.4.0

changelogger/app/manage/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
from changelogger.app.manage.commands.check import check
44
from changelogger.app.manage.commands.content import content
55
from changelogger.app.manage.commands.upgrade import upgrade
6+
from changelogger.app.manage.commands.versions import versions
67

78
app = typer.Typer()
89
app.command()(upgrade)
910
app.command()(check)
1011
app.command()(content)
12+
app.command()(versions)
1113

1214

1315
@app.callback()
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from rich import print
2+
from typer import Option
3+
4+
from changelogger import changelog
5+
6+
7+
def versions(
8+
latest: bool = Option(
9+
False, help="Gets the latest version in the changelog file"
10+
),
11+
show_all: bool = Option(False, help="Get all versions."),
12+
num_versions: int = Option(10, help="The number of versions to get."),
13+
) -> None:
14+
"""Retrieves the versions found in the changelog file."""
15+
if latest:
16+
print(changelog.get_latest_version())
17+
return
18+
19+
all_versions = changelog.get_all_versions()
20+
end = len(all_versions) if show_all else num_versions
21+
print("\n".join(map(str, all_versions[:end])))

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "changelogged"
3-
version = "0.6.0"
3+
version = "0.7.0"
44
description = "Automated management of your CHANGELOG.md and other versioned files, following the principles of Keep a Changelog and Semantic Versioning."
55
license = "MIT"
66
authors = ["award28 <austin.ward@klaviyo.com>"]
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
from unittest.mock import MagicMock, patch
2+
3+
import pytest
4+
import semver
5+
6+
from changelogger.app.manage.commands.versions import versions
7+
8+
9+
class TestManageVersionsCommand:
10+
VERSIONS = [semver.VersionInfo(v) for v in reversed(range(100))]
11+
12+
@pytest.fixture
13+
def mock_changelog(self):
14+
with patch(
15+
"changelogger.app.manage.commands.versions.changelog"
16+
) as mock:
17+
yield mock
18+
19+
@pytest.fixture
20+
def mock_print(self):
21+
with patch("changelogger.app.manage.commands.versions.print") as mock:
22+
yield mock
23+
24+
def test_versions(
25+
self,
26+
mock_changelog: MagicMock,
27+
mock_print: MagicMock,
28+
) -> None:
29+
mock_changelog.get_all_versions.side_effect = (self.VERSIONS,)
30+
versions(latest=False, show_all=False, num_versions=10)
31+
mock_print.assert_called_once_with(
32+
"\n".join(map(str, self.VERSIONS[:10]))
33+
)
34+
35+
def test_versions_latest(
36+
self,
37+
mock_changelog: MagicMock,
38+
mock_print: MagicMock,
39+
) -> None:
40+
mock_changelog.get_latest_version.side_effect = (self.VERSIONS[0],)
41+
versions(latest=True, show_all=False, num_versions=10)
42+
mock_print.assert_called_once_with(self.VERSIONS[0])
43+
44+
def test_versions_show_all(
45+
self,
46+
mock_changelog: MagicMock,
47+
mock_print: MagicMock,
48+
) -> None:
49+
mock_changelog.get_all_versions.side_effect = (self.VERSIONS,)
50+
versions(latest=False, show_all=True, num_versions=10)
51+
mock_print.assert_called_once_with("\n".join(map(str, self.VERSIONS)))

0 commit comments

Comments
 (0)