Repository: jamesls/jmeslog

Issue:
Release version not honored in new-release command
The version number is ignored if you want to explicitly override the version number instead of having jmeslog automatically determine it, e.g. `jmeslog new-release --release-version 1.2.3`.

Discussion:

Patch:
diff --git a/.changes/next-release/24804927238-bugfix-NewRelease-56222.json b/.changes/next-release/24804927238-bugfix-NewRelease-56222.json
new file mode 100644
index 0000000..da3b88c
--- /dev/null
+++ b/.changes/next-release/24804927238-bugfix-NewRelease-56222.json
@@ -0,0 +1,5 @@
+{
+  "type": "bugfix",
+  "category": "NewRelease",
+  "description": "Honor release version number override when creating a new release (#9)"
+}
diff --git a/jmeslog.py b/jmeslog.py
index 2b0675f..a719343 100644
--- a/jmeslog.py
+++ b/jmeslog.py
@@ -337,9 +337,12 @@ def cmd_new_release(args: argparse.Namespace) -> int:
     # Create a new version file from the existing changes.
     # Delete the next changes folder.
     changes = load_next_changes(args.change_dir)
-    last_released_version = find_last_released_version(args.change_dir)
-    next_version = determine_next_version(last_released_version,
-                                          changes.version_bump_type)
+    if args.release_version is not None:
+        next_version = args.release_version
+    else:
+        last_released_version = find_last_released_version(args.change_dir)
+        next_version = determine_next_version(last_released_version,
+                                              changes.version_bump_type)
     release_file = consolidate_next_release(
         next_version, args.change_dir, changes)
     print(f"New release file written: {release_file}")


Test patch:
diff --git a/tests/test_jmeslog.py b/tests/test_jmeslog.py
index 4d5458a..319b21f 100644
--- a/tests/test_jmeslog.py
+++ b/tests/test_jmeslog.py
@@ -1,11 +1,27 @@
 import os
 import pytest
 import json
+from dataclasses import dataclass
 from unittest import mock
+from typing import Optional
 
 import jmeslog
 
 
+@dataclass
+class CommandArgs:
+    change_dir: Optional[str] = None
+    release_version: Optional[str] = None
+
+
+@dataclass
+class NewChangeArgs:
+    type: str
+    category: str
+    description: str
+    change_dir: Optional[str] = None
+
+
 def new_change(change_type, category='foo', description='bar'):
     return jmeslog.JMESLogEntry(type=change_type,
                                 category=category, description=description)
@@ -319,3 +335,19 @@ def test_can_create_collection_from_old_format():
     assert collection.changes == [jmeslog.JMESLogEntry(type='feature',
                                                        category='foo',
                                                        description='bar')]
+
+
+
+def test_can_set_explicit_version(tmpdir):
+    change_dir = os.path.join(str(tmpdir), '.changes')
+    args = CommandArgs(change_dir=change_dir, release_version='1.2.3')
+    jmeslog.cmd_init(args)
+    new_change_args = NewChangeArgs(
+        type='enhancement',
+        category='Foo',
+        description='Changed foo',
+        change_dir=change_dir,
+    )
+    jmeslog.cmd_new_change(new_change_args)
+    jmeslog.cmd_new_release(args)
+    assert os.listdir(change_dir)[0] == '1.2.3.json'