From 225cca7cac2e1c453d42ac361c2844a7ee9b5715 Mon Sep 17 00:00:00 2001 From: Jonathan Sick Date: Wed, 22 May 2024 17:34:07 -0400 Subject: [PATCH] Set edition kind in create_edition If it is the __main slug, then the edition is always a "main" kind. Otherwise inspect the tracking git_ref to set release/major/minor kinds. Otherwise the edition is a draft. --- keeper/services/createedition.py | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) 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"