diff --git a/backend/src/github_pm/api.py b/backend/src/github_pm/api.py index 9eab3c8..2adfce3 100644 --- a/backend/src/github_pm/api.py +++ b/backend/src/github_pm/api.py @@ -1,5 +1,6 @@ from collections import defaultdict from datetime import datetime +import re import time from typing import Annotated, Any, AsyncGenerator @@ -13,6 +14,10 @@ api_router = APIRouter() +# We sort "semver" style milestones first, then others alphabetically +VERSION_MATCH = re.compile(r"^v\d+\.\d+\.\d+$") + + class Connector: def __init__(self, github_token: str): @@ -255,6 +260,16 @@ async def get_milestones(gitctx: Annotated[Connector, Depends(connection)]): f"/repos/{context.github_repo}/milestones", headers={"Accept": "application/vnd.github.html+json"}, ) + versions = [] + others = [] + for m in milestones: + if VERSION_MATCH.match(m["title"]): + versions.append(m) + else: + others.append(m) + milestones = sorted(versions, key=lambda x: x["title"]) + sorted( + others, key=lambda x: x["title"] + ) milestones.append( { "title": "none",