Skip to content

Commit 16c7b0d

Browse files
committed
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.
1 parent 1bcceaa commit 16c7b0d

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

keeper/services/createedition.py

+29-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
import re
34
import uuid
45
from typing import TYPE_CHECKING, Optional
56

@@ -86,8 +87,15 @@ def create_edition(
8687
edition.tracked_ref = tracked_ref
8788
edition.tracked_refs = [tracked_ref]
8889

89-
if kind is not None:
90+
if edition.slug == "__main":
91+
# Always mark the default edition as the main edition
92+
edition.set_kind("main")
93+
elif kind is not None:
94+
# Manually set the edition kind
9095
edition.set_kind(kind)
96+
elif tracked_ref is not None:
97+
# Set the EditionKind based on the tracked_ref value
98+
edition.set_kind(determine_edition_kind(tracked_ref))
9199

92100
db.session.add(edition)
93101
db.session.commit()
@@ -98,3 +106,23 @@ def create_edition(
98106
request_dashboard_build(product)
99107

100108
return edition
109+
110+
111+
SEMVER_PATTERN = re.compile(
112+
r"^v?(?P<major>[\d]+)(\.(?P<minor>[\d]+)(\.(?P<patch>[\d]+))?)?$"
113+
)
114+
115+
116+
def determine_edition_kind(git_ref: str) -> str:
117+
"""Determine the kind of edition based on the git ref."""
118+
match = SEMVER_PATTERN.match(git_ref)
119+
if match is None:
120+
return "draft"
121+
122+
if match.group("patch") is not None and match.group("minor") is not None:
123+
return "release"
124+
125+
if match.group("minor") is not None and match.group("patch") is None:
126+
return "minor"
127+
128+
return "major"

0 commit comments

Comments
 (0)