27 lines
694 B
Python
27 lines
694 B
Python
from typing import Tuple
|
|
|
|
|
|
def parse_semver(v: str) -> Tuple[int, int, int]:
|
|
try:
|
|
parts = v.split(".")
|
|
major = int(parts[0])
|
|
minor = int(parts[1]) if len(parts) > 1 else 0
|
|
patch = int(parts[2]) if len(parts) > 2 else 0
|
|
return major, minor, patch
|
|
except Exception:
|
|
return 0, 0, 0
|
|
|
|
|
|
def compatibility(peer: str, current: str) -> str:
|
|
"""Return one of: compatible, warning, blocked"""
|
|
pM, pm, pp = parse_semver(peer)
|
|
cM, cm, cp = parse_semver(current)
|
|
if pM != cM:
|
|
return "blocked"
|
|
# Same major
|
|
if pm == cm:
|
|
return "compatible"
|
|
# Different minor within same major => warning
|
|
return "warning"
|
|
|