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

feat: Allow to create final release PR #18

Merged
merged 1 commit into from
Oct 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/badabump/changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
BREAKING_CHANGE_IN_BODY = "BREAKING CHANGE:"
BREAKING_CHANGE_IN_COMMIT_TYPE = "!"

CHANGELOG_EMPTY = "No changes since last pre-release"

COMMIT_TYPE_FEATURE = "feat"
COMMIT_TYPE_FIX = "fix"

Expand Down Expand Up @@ -131,6 +133,9 @@ def format( # noqa: A003
*,
is_pre_release: bool = False,
) -> str:
if not self.commits:
return CHANGELOG_EMPTY

is_git_commit = changelog_type == ChangeLogTypeEnum.git_commit
is_rst = format_type == FormatTypeEnum.rst

Expand Down
8 changes: 3 additions & 5 deletions src/badabump/cli/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def create_update_config(
kwargs["is_breaking_change"] = True
elif changelog.has_minor_change:
kwargs["is_minor_change"] = True
elif changelog.has_micro_change:
else:
kwargs["is_micro_change"] = True

return UpdateConfig(**kwargs)
Expand Down Expand Up @@ -100,12 +100,10 @@ def main(argv: Argv = None) -> int:
)

# Read commits from last tag
# TODO: Allow to release final version without commits from last
# pre-release
try:
git_commits = git.list_commits(current_tag)
if not git_commits:
raise ValueError("No commits, nothing to release :(")
if not git_commits and current_version.pre_release is None:
raise ValueError("No commits found after latest tag")
except ValueError:
print(
f"ERROR: No commits found after: {current_tag!r}. Exit...",
Expand Down
2 changes: 1 addition & 1 deletion src/badabump/versions/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def parse(cls, value: str, *, config: ProjectConfig) -> "Version":
def update(self, config: UpdateConfig) -> "Version":
if self.pre_release:
return Version(
version=self.version.update(config),
version=self.version,
pre_release=self.pre_release.update(config),
)

Expand Down
31 changes: 31 additions & 0 deletions tests/test_changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
Issue: IFXND-55
"""

CHANGELOG_EMPTY = "No changes since last pre-release"

CHANGELOG_FILE_MD = """## Features:

- [IFXND-55] Export necessary types from the package (#31)
Expand All @@ -31,6 +33,7 @@

- **BREAKING CHANGE:** Use badabump release bot for pushing tags
- [#123] (**openapi**) Update descriptions in OpenAPI schema"""

CHANGELOG_FILE_MD_PRE = """### Features:

- [IFXND-55] Export necessary types from the package (#31)
Expand All @@ -39,6 +42,7 @@

- **BREAKING CHANGE:** Use badabump release bot for pushing tags
- [#123] (**openapi**) Update descriptions in OpenAPI schema"""

CHANGELOG_FILE_RST = """**Features:**

- [IFXND-55] Export necessary types from the package (#31)
Expand All @@ -49,6 +53,33 @@
- [#123] (**openapi**) Update descriptions in OpenAPI schema"""


@pytest.mark.parametrize(
"changelog_type, format_type, expected",
(
(
ChangeLogTypeEnum.changelog_file,
FormatTypeEnum.markdown,
CHANGELOG_EMPTY,
),
(
ChangeLogTypeEnum.changelog_file,
FormatTypeEnum.rst,
CHANGELOG_EMPTY,
),
(
ChangeLogTypeEnum.git_commit,
FormatTypeEnum.markdown,
CHANGELOG_EMPTY,
),
(ChangeLogTypeEnum.git_commit, FormatTypeEnum.rst, CHANGELOG_EMPTY),
),
)
def test_changelog_empty(changelog_type, format_type, expected):
changelog = ChangeLog.from_git_commits([])
content = changelog.format(changelog_type, format_type)
assert content == expected


@pytest.mark.parametrize(
"format_type, is_pre_release, expected",
(
Expand Down
12 changes: 6 additions & 6 deletions tests/test_versions_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def test_version_from_tag(tag, config, expected):
# Micro change
("1.0", UpdateConfig(), "1.1"),
("1.0", UpdateConfig(is_pre_release=True), "1.1a0"),
("1.0a0", UpdateConfig(), "1.1"),
("1.0a0", UpdateConfig(), "1.0"),
("1.0a0", UpdateConfig(is_pre_release=True), "1.0a1"),
# Minor change
(
Expand All @@ -111,7 +111,7 @@ def test_version_from_tag(tag, config, expected):
(
"1.1a0",
UpdateConfig(is_minor_change=True, is_micro_change=False),
"2.0",
"1.1",
),
(
"1.1a0",
Expand Down Expand Up @@ -140,7 +140,7 @@ def test_version_from_tag(tag, config, expected):
(
"1.1a0",
UpdateConfig(is_breaking_change=True, is_micro_change=False),
"2.0",
"1.1",
),
(
"1.1a0",
Expand Down Expand Up @@ -170,7 +170,7 @@ def test_version_update_calver(current_suffix, update_config, expected_suffix):
# Micro change
("1.0.0", UpdateConfig(), "1.0.1"),
("1.0.0", UpdateConfig(is_pre_release=True), "1.0.1a0"),
("1.0.0a0", UpdateConfig(), "1.0.1"),
("1.0.0a0", UpdateConfig(), "1.0.0"),
("1.0.0a0", UpdateConfig(is_pre_release=True), "1.0.0a1"),
# Minor change
(
Expand All @@ -190,7 +190,7 @@ def test_version_update_calver(current_suffix, update_config, expected_suffix):
(
"1.0.0a0",
UpdateConfig(is_minor_change=True, is_micro_change=False),
"1.1.0",
"1.0.0",
),
(
"1.0.0a0",
Expand Down Expand Up @@ -219,7 +219,7 @@ def test_version_update_calver(current_suffix, update_config, expected_suffix):
(
"1.0.0a0",
UpdateConfig(is_breaking_change=True, is_micro_change=False),
"2.0.0",
"1.0.0",
),
(
"1.0.0a0",
Expand Down