Skip to content

Commit

Permalink
Set edition kind in create_edition
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jonathansick committed May 23, 2024
1 parent 1bcceaa commit 16c7b0d
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion keeper/services/createedition.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import re
import uuid
from typing import TYPE_CHECKING, Optional

Expand Down Expand Up @@ -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()
Expand All @@ -98,3 +106,23 @@ def create_edition(
request_dashboard_build(product)

return edition


SEMVER_PATTERN = re.compile(
r"^v?(?P<major>[\d]+)(\.(?P<minor>[\d]+)(\.(?P<patch>[\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"

0 comments on commit 16c7b0d

Please sign in to comment.