This commit is contained in:
+21
-12
@@ -123,13 +123,13 @@ def validate_url(value: str, field: str) -> str:
|
||||
return value.rstrip("/")
|
||||
|
||||
|
||||
def load_registry(site_root: Path) -> list[dict[str, str]]:
|
||||
def load_registry(site_root: Path) -> list[dict[str, str | int]]:
|
||||
registry_path = site_root / "configs" / "project-sources.ini"
|
||||
parser = configparser.ConfigParser(interpolation=None)
|
||||
if not parser.read(registry_path, encoding="utf-8"):
|
||||
raise ProjectSourceError(f"project source registry is missing: {registry_path}")
|
||||
|
||||
sources: list[dict[str, str]] = []
|
||||
sources: list[dict[str, str | int]] = []
|
||||
for project_id in parser.sections():
|
||||
if not SLUG_RE.fullmatch(project_id):
|
||||
raise ProjectSourceError(f"invalid project id in registry: {project_id}")
|
||||
@@ -141,15 +141,21 @@ def load_registry(site_root: Path) -> list[dict[str, str]]:
|
||||
branch = section["branch"].strip()
|
||||
if not re.fullmatch(r"[A-Za-z0-9._/-]+", branch) or ".." in branch:
|
||||
raise ProjectSourceError(f"{project_id}: invalid branch")
|
||||
sources.append(
|
||||
{
|
||||
"project_id": project_id,
|
||||
"repository": validate_url(section["repository"].strip(), "repository"),
|
||||
"web_url": validate_url(section["web_url"].strip(), "web_url"),
|
||||
"api_url": validate_url(section["api_url"].strip(), "api_url"),
|
||||
"branch": branch,
|
||||
}
|
||||
)
|
||||
source: dict[str, str | int] = {
|
||||
"project_id": project_id,
|
||||
"repository": validate_url(section["repository"].strip(), "repository"),
|
||||
"web_url": validate_url(section["web_url"].strip(), "web_url"),
|
||||
"api_url": validate_url(section["api_url"].strip(), "api_url"),
|
||||
"branch": branch,
|
||||
}
|
||||
if "featured_order" in section:
|
||||
try:
|
||||
source["featured_order"] = int(section["featured_order"])
|
||||
except ValueError as exc:
|
||||
raise ProjectSourceError(
|
||||
f"{project_id}: featured_order must be an integer"
|
||||
) from exc
|
||||
sources.append(source)
|
||||
if not sources:
|
||||
raise ProjectSourceError("project source registry is empty")
|
||||
return sources
|
||||
@@ -566,7 +572,7 @@ def append_fields(original: bytes, fields: dict[str, Any]) -> bytes:
|
||||
|
||||
|
||||
def materialize(
|
||||
source: dict[str, str],
|
||||
source: dict[str, str | int],
|
||||
destination_root: Path,
|
||||
files: dict[str, bytes],
|
||||
records: dict[str, dict[str, str]],
|
||||
@@ -630,6 +636,9 @@ def materialize(
|
||||
"repository_language_tags": repository_language_tags,
|
||||
"taxonomy_tags": taxonomy_tags,
|
||||
}
|
||||
if "featured_order" in source:
|
||||
project_fields["featured"] = "yes"
|
||||
project_fields["featured_order"] = source["featured_order"]
|
||||
|
||||
for source_path, data in files.items():
|
||||
relative = PurePosixPath(source_path).relative_to(".labyricorn")
|
||||
|
||||
Reference in New Issue
Block a user