feat(RMGR-WP-0008): add workplan and register receiving surfaces
This commit is contained in:
parent
5502afc1fd
commit
859df9aae7
15 changed files with 1501 additions and 11 deletions
73
src/repo_manager/parse/register.py
Normal file
73
src/repo_manager/parse/register.py
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
"""Parser for repository-owned register files."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass, field
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
import yaml
|
||||
|
||||
REGISTER_SCHEMA = "repo-manager.register.v0"
|
||||
SUPPORTED_REGISTER_KINDS = frozenset(
|
||||
{
|
||||
"sbom-inventory",
|
||||
"repo-goals",
|
||||
"upstream-contributions",
|
||||
"technical-debt",
|
||||
"extension-points",
|
||||
"register-entries",
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@dataclass
|
||||
class ParsedRegisterEntry:
|
||||
kind: str
|
||||
id: str
|
||||
title: str | None
|
||||
status: str | None
|
||||
source_path: str
|
||||
raw: dict[str, Any] = field(default_factory=dict)
|
||||
|
||||
|
||||
def register_path(repo_root: Path, kind: str) -> Path:
|
||||
return repo_root / "registers" / f"{kind}.yaml"
|
||||
|
||||
|
||||
def parse_register_file(path: Path, *, repo_root: Path) -> list[ParsedRegisterEntry]:
|
||||
try:
|
||||
data = yaml.safe_load(path.read_text(encoding="utf-8")) or {}
|
||||
except (OSError, yaml.YAMLError):
|
||||
return []
|
||||
if not isinstance(data, dict):
|
||||
return []
|
||||
kind = str(data.get("kind") or path.stem)
|
||||
if kind not in SUPPORTED_REGISTER_KINDS:
|
||||
return []
|
||||
entries = data.get("entries") or []
|
||||
if not isinstance(entries, list):
|
||||
return []
|
||||
source_path = str(path.relative_to(repo_root))
|
||||
parsed: list[ParsedRegisterEntry] = []
|
||||
for item in entries:
|
||||
if not isinstance(item, dict) or not item.get("id"):
|
||||
continue
|
||||
parsed.append(
|
||||
ParsedRegisterEntry(
|
||||
kind=kind,
|
||||
id=str(item["id"]),
|
||||
title=str(item["title"]) if item.get("title") is not None else None,
|
||||
status=str(item["status"]) if item.get("status") is not None else None,
|
||||
source_path=source_path,
|
||||
raw=item,
|
||||
)
|
||||
)
|
||||
return parsed
|
||||
|
||||
|
||||
def iter_register_files(repo_root: Path) -> list[Path]:
|
||||
directory = repo_root / "registers"
|
||||
if not directory.is_dir():
|
||||
return []
|
||||
return sorted(path for path in directory.glob("*.yaml") if not path.name.startswith("."))
|
||||
Loading…
Add table
Add a link
Reference in a new issue