from __future__ import annotations from dataclasses import dataclass @dataclass class GitLabSessionResolution: project_id: int project_path: str noteable_type: str noteable_iid: int label: str @property def conversation_id(self) -> str: return f"gitlab:{self.project_id}:{self.noteable_type}:{self.noteable_iid}" def resolve_session_from_unified(msg) -> GitLabSessionResolution | None: metadata = getattr(msg, "metadata", {}) or {} project_id = int(metadata.get("project_id", 0)) project_path = str(metadata.get("project_path", "")) noteable_type = str(metadata.get("noteable_type", "Issue")) noteable_iid = int(metadata.get("noteable_iid", 0)) if project_id <= 0 or noteable_iid <= 0: return None return GitLabSessionResolution( project_id=project_id, project_path=project_path, noteable_type=noteable_type, noteable_iid=noteable_iid, label=f"{project_path}#{noteable_iid}", ) def build_session_label(project_path: str, noteable_type: str, noteable_iid: int, title: str = "") -> str: symbol = "#" if noteable_type == "Issue" else "!" base = f"{project_path}{symbol}{noteable_iid}" if title: return f"{base} — {title}" return base