Skip to content

Commit

Permalink
New Command: Force version on update (#107)
Browse files Browse the repository at this point in the history
  • Loading branch information
award28 authored Jul 5, 2023
1 parent fce6b38 commit 234eb5b
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 3 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ The [Changelogger tool](https://pypi.org/project/changelogged) is used for autom
<!-- BEGIN RELEASE NOTES -->
### [Unreleased]

### [0.13.0] - 2023-07-05

#### Added
- The `force` command, allowing users to override the next version of their release.

### [0.12.0] - 2023-03-18

#### Added
Expand Down Expand Up @@ -167,7 +172,8 @@ The [Changelogger tool](https://pypi.org/project/changelogged) is used for autom
- `unreleased add`, which allows inline or prompted adding of unreleased changes.
<!-- END RELEASE NOTES -->
<!-- BEGIN LINKS -->
[Unreleased]: https://github.com/award28/changelogger/compare/0.12.0...HEAD
[Unreleased]: https://github.com/award28/changelogger/compare/0.13.0...HEAD
[0.13.0]: https://github.com/award28/changelogger/compare/0.12.0...0.13.0
[0.12.0]: https://github.com/award28/changelogger/compare/0.11.4...0.12.0
[0.11.4]: https://github.com/award28/changelogger/compare/0.11.3...0.11.4
[0.11.3]: https://github.com/award28/changelogger/compare/0.11.2...0.11.3
Expand Down
2 changes: 2 additions & 0 deletions changelogger/app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from changelogger.app.commands.add import add
from changelogger.app.commands.check import check
from changelogger.app.commands.force import force
from changelogger.app.commands.init import init
from changelogger.app.commands.notes import notes
from changelogger.app.commands.precommit import precommit
Expand Down Expand Up @@ -49,6 +50,7 @@ def add_command(
app.add_command(init)
app.add_command(notes)
app.add_command(upgrade, "up")
app.add_command(force)
app.add_command(versions)
app.add_command(precommit, hidden=True)

Expand Down
56 changes: 56 additions & 0 deletions changelogger/app/commands/force.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import typer
from rich import print
from rich.markdown import Markdown

from changelogger import changelog
from changelogger.app.prompts import (
prompt_unreleased_changelog,
rollback_handler,
)
from changelogger.conf import settings
from changelogger.models.domain_models import ChangelogUpdate, VersionInfo


def force(
forced_version: str,
confirm: bool = typer.Option(
True,
help="Confirm the release notes before applying them.",
),
prompt_changelog: bool = typer.Option(
True,
help="Prompt for additional release notes before applying them.",
),
) -> None:
"""Force a version override for the upgrade."""
old_version = changelog.get_latest_version()
new_version = VersionInfo.parse(forced_version)

release_notes = changelog.get_release_notes("Unreleased", old_version)
update = ChangelogUpdate(
old_version=old_version,
new_version=new_version,
release_notes=release_notes,
)

if prompt_changelog:
update = prompt_unreleased_changelog(update)

print(f"Upgrading {old_version} ==> {new_version}")
md = f"\n# Changelog updates for [{new_version}]\n"
if update_md := update.release_notes.markdown():
md += update_md
else:
md += "\n*No notes found or added*"

md += "\n---\n"
print(Markdown(md))

if confirm:
typer.confirm("Do these changes look correct?", abort=True)

with rollback_handler():
changelog.update_versioned_files(
update,
settings.VERSIONED_FILES,
)
2 changes: 1 addition & 1 deletion changelogger/conf/defaults.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from pathlib import Path

CHANGELOGGER_VERSION = "0.12.0"
CHANGELOGGER_VERSION = "0.13.0"

DEFAULT_CHANGELOG_PATH = Path("CHANGELOG.md")

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "changelogged"
version = "0.12.0"
version = "0.13.0"
description = "Automated management of your changelog and other versioned files, following the principles of Keep a Changelog and Semantic Versioning."
license = "MIT"
authors = ["award28 <[email protected]>"]
Expand Down

0 comments on commit 234eb5b

Please sign in to comment.