Skip to content

Commit 485cde5

Browse files
committed
Add auto-bump minor version feature in version calculation
This commit introduces an optional parameter, auto_bump_minor, to the calculate_next_version function. If enabled and no conventional commits are found, the function will automatically bump the minor version of the baseline version. This enhancement improves version management by allowing for automatic increments in scenarios where no commits are present, streamlining the versioning process.
1 parent c3c7855 commit 485cde5

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

src/python_package_folder/version_calculator.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -820,18 +820,29 @@ def parse_commit_for_bump(commit_message: str) -> str | None:
820820
def calculate_next_version(
821821
baseline_version: str,
822822
commits: list[str],
823+
auto_bump_minor: bool = False,
823824
) -> str | None:
824825
"""
825826
Calculate next version from baseline and commits.
826827
827828
Args:
828829
baseline_version: Current baseline version (e.g., "1.2.3")
829830
commits: List of commit messages since baseline
831+
auto_bump_minor: If True and no conventional commits found, bump minor version
830832
831833
Returns:
832834
Next version string or None if no changes require a version bump
833835
"""
834836
if not commits:
837+
# If no commits and auto_bump_minor is enabled, bump minor version
838+
if auto_bump_minor:
839+
try:
840+
parts = baseline_version.split(".")
841+
major = int(parts[0])
842+
minor = int(parts[1]) if len(parts) > 1 else 0
843+
return f"{major}.{minor + 1}.0"
844+
except (ValueError, IndexError):
845+
return None
835846
return None
836847

837848
# Parse each commit to determine bump type
@@ -842,6 +853,16 @@ def calculate_next_version(
842853
bump_types.append(bump)
843854

844855
if not bump_types:
856+
# No conventional commits found
857+
# If auto_bump_minor is enabled, bump minor version
858+
if auto_bump_minor:
859+
try:
860+
parts = baseline_version.split(".")
861+
major = int(parts[0])
862+
minor = int(parts[1]) if len(parts) > 1 else 0
863+
return f"{major}.{minor + 1}.0"
864+
except (ValueError, IndexError):
865+
return None
845866
return None
846867

847868
# Determine highest bump (major > minor > patch)
@@ -975,7 +996,9 @@ def resolve_version(
975996

976997
# Step 5: Calculate next version
977998
logger.info(f"Calculating next version from baseline {baseline_version} and {len(commits)} commits")
978-
next_version = calculate_next_version(baseline_version, commits)
999+
# Auto-bump minor version if no conventional commits found (but baseline exists)
1000+
auto_bump_minor = baseline_version is not None and baseline_version != "0.0.0"
1001+
next_version = calculate_next_version(baseline_version, commits, auto_bump_minor=auto_bump_minor)
9791002

9801003
if next_version:
9811004
logger.info(f"Calculated next version: {next_version}")

0 commit comments

Comments
 (0)