diff --git a/keeper/services/createedition.py b/keeper/services/createedition.py index d30df0d..7210935 100644 --- a/keeper/services/createedition.py +++ b/keeper/services/createedition.py @@ -1,5 +1,6 @@ from __future__ import annotations +import re import uuid from typing import TYPE_CHECKING, Optional @@ -86,8 +87,15 @@ def create_edition( edition.tracked_ref = tracked_ref edition.tracked_refs = [tracked_ref] - if kind is not None: + if edition.slug == "__main": + # Always mark the default edition as the main edition + edition.set_kind("main") + elif kind is not None: + # Manually set the edition kind edition.set_kind(kind) + elif tracked_ref is not None: + # Set the EditionKind based on the tracked_ref value + edition.set_kind(determine_edition_kind(tracked_ref)) db.session.add(edition) db.session.commit() @@ -98,3 +106,23 @@ def create_edition( request_dashboard_build(product) return edition + + +SEMVER_PATTERN = re.compile( + r"^v?(?P[\d]+)(\.(?P[\d]+)(\.(?P[\d]+))?)?$" +) + + +def determine_edition_kind(git_ref: str) -> str: + """Determine the kind of edition based on the git ref.""" + match = SEMVER_PATTERN.match(git_ref) + if match is None: + return "draft" + + if match.group("patch") is not None and match.group("minor") is not None: + return "release" + + if match.group("minor") is not None and match.group("patch") is None: + return "minor" + + return "major"