Repository: callowayproject/bump-my-version
Pull request #155 (2024-03-16 14:09:21)

Fix legacy multiline
We discovered that commas in legacy multiline options are replaced by newline which produced errors on configurations for bump2version.

Debug lead me to autocast which doesn't expect strings with both commas and newlines.


Patch:
diff --git a/.github/workflows/version.yaml b/.github/workflows/version.yaml
index def335ab..d171fdd1 100644
--- a/.github/workflows/version.yaml
+++ b/.github/workflows/version.yaml
@@ -3,6 +3,19 @@ on:
   pull_request:
     types: [closed]
     branches: [master]
+  workflow_dispatch:
+    inputs:
+      releaseType:
+        description: 'What kind of release is this?'
+        required: false
+        default: 'auto'
+        type: choice
+        options:
+          - 'auto'
+          - 'major'
+          - 'minor'
+          - 'patch'
+          - 'dev'
 
 jobs:
   version:
@@ -36,6 +49,14 @@ jobs:
           echo "release-kind=$RELEASE_KIND" >> $GITHUB_OUTPUT
           echo "PACKAGE=false" >> $GITHUB_ENV
 
+      - name: Override release kind on manual
+        if: ${{ github.event.inputs.releaseType  != 'auto' }}
+        id: override-release-kind
+        run: |
+          echo "::notice::Overriding release type to ${{ github.event.inputs.releaseType }} since this was a manual trigger"
+          echo "RELEASE_KIND=${{ github.event.inputs.releaseType }}" >> $GITHUB_ENV
+          echo "release-kind=${{ github.event.inputs.releaseType }}" >> $GITHUB_OUTPUT
+
       - name: Get Pull Request Number
         id: pr
         run: |
@@ -59,7 +80,7 @@ jobs:
               echo "PACKAGE=true" >> $GITHUB_ENV
               ;;
             dev)
-              echo "Intentionally not bumping version for dev release"
+              bump-my-version bump --allow-dirty --verbose --no-commit --no-tag "$RELEASE_KIND"
               ;;
           esac
 
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index d4247ab8..6e177f18 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -1,7 +1,7 @@
 repos:
   - repo: https://github.com/astral-sh/ruff-pre-commit
     # Ruff version.
-    rev: 'v0.3.2'
+    rev: 'v0.2.2'
     hooks:
       - id: ruff
         args: [--fix, --exit-non-zero-on-fix]
@@ -43,7 +43,7 @@ repos:
         args: ['--baseline', '.secrets.baseline']
         additional_dependencies: ["gibberish-detector"]
   - repo: https://github.com/pre-commit/mirrors-mypy
-    rev: v1.9.0
+    rev: v1.8.0
     hooks:
       - id: mypy
         args: [--no-strict-optional, --ignore-missing-imports]
diff --git a/bumpversion/autocast.py b/bumpversion/autocast.py
index 06fd0ecb..f417b1aa 100644
--- a/bumpversion/autocast.py
+++ b/bumpversion/autocast.py
@@ -43,11 +43,14 @@ def listify(s: str) -> list:
     Returns:
         List of homogenous basic types.
     """
-    if "," not in s and "\n" not in s:
+    if "\n" in s:
+        str_list = s.strip().split("\n")
+    elif "," in s:
+        str_list = s.strip().split(",")
+    else:
         raise ValueError("Not a List")
 
     # derive the type of the variable
-    str_list = s.strip().split(",") if "," in s else s.strip().split("\n")
     element_caster = str
     for caster in (boolify, int, float, noneify, element_caster):
         with contextlib.suppress(ValueError):


Test patch:
diff --git a/tests/fixtures/legacy_multiline_search_comma.cfg b/tests/fixtures/legacy_multiline_search_comma.cfg
new file mode 100644
index 00000000..d405c298
--- /dev/null
+++ b/tests/fixtures/legacy_multiline_search_comma.cfg
@@ -0,0 +1,8 @@
+[bumpversion]
+current_version = 1.0.0
+
+[bumpversion:file:MULTILINE_SEARCH.md]
+search = **unreleased**,
+	**v{current_version}**,
+replace = **unreleased**,
+	**v{new_version}**,
diff --git a/tests/fixtures/legacy_multiline_search_comma_expected.json b/tests/fixtures/legacy_multiline_search_comma_expected.json
new file mode 100644
index 00000000..e7fdc5f7
--- /dev/null
+++ b/tests/fixtures/legacy_multiline_search_comma_expected.json
@@ -0,0 +1,11 @@
+{
+  "current_version": "1.0.0",
+  "files": [
+    {
+      "filename": "MULTILINE_SEARCH.md",
+      "search": "**unreleased**,\n**v{current_version}**,",
+      "replace": "**unreleased**,\n**v{new_version}**,"
+    }
+  ],
+  "parts": {}
+}
diff --git a/tests/test_autocast.py b/tests/test_autocast.py
index 28204ad8..d3d92a4b 100644
--- a/tests/test_autocast.py
+++ b/tests/test_autocast.py
@@ -46,6 +46,7 @@ def test_noneify():
         param("1,2,3,4", [1, 2, 3, 4], id="int"),
         param("1\n2\n3\n4", [1, 2, 3, 4], id="int"),
         param("s,t,r", ["s", "t", "r"], id="str"),
+        param("s,\nt,\nr\n", ["s,", "t,", "r"], id="str_newline"),
         param("1.1,2,3.14", [1.1, 2.0, 3.14], id="float"),
         param("True,False,true,false", [True, False, True, False], id="bool"),
         param("None,None,None", [None, None, None], id="none"),
@@ -75,6 +76,7 @@ def test_listify_invalid():
         param("False", False, id="False"),
         param("1,2,3,4", [1, 2, 3, 4], id="int-list"),
         param("s,t,r", ["s", "t", "r"], id="str-list"),
+        param("s,\nt,\nr\n", ["s,", "t,", "r"], id="str-list-newline"),
         param("1", 1, id="int"),
         param("1.0", 1.0, id="float"),
         param(1, 1, id="real-int"),
diff --git a/tests/test_config/test_files_legacy.py b/tests/test_config/test_files_legacy.py
index a0e0b025..53a95e00 100644
--- a/tests/test_config/test_files_legacy.py
+++ b/tests/test_config/test_files_legacy.py
@@ -35,6 +35,11 @@ def cfg_file(request) -> str:
     [
         param("basic_cfg.cfg", "basic_cfg_expected.json", id="ini basic cfg"),
         param("legacy_multiline_search.cfg", "legacy_multiline_search_expected.json", id="multiline search cfg"),
+        param(
+            "legacy_multiline_search_comma.cfg",
+            "legacy_multiline_search_comma_expected.json",
+            id="multiline search comma cfg",
+        ),
     ],
 )
 def test_read_ini_file(conf_file: str, expected_file: str, fixtures_path: Path) -> None: