INNER CODE UNIT · Python
rewrite_schema_refs
bjw-s-labs/helm-charts · .ci/scripts/prepare-schema-refs.py:9
def rewrite_schema_refs(root: Path, path: str, repository: str) -> int:
schema_root = (root / path).resolve()
if not schema_root.is_dir():
raise FileNotFoundError(f"Schema path not found: {schema_root}")
file_uri = root.resolve().as_uri().encode("ascii")
pattern = re.compile(
rb"https://raw\.githubusercontent\.com/"
+ re.escape(repository.encode("ascii"))
+ rb"/[^\"']*/(charts/[^\"']*)"
)
changed = 0
for schema_file in schema_root.rglob("*.json"):
if not schema_file.is_file():
continue
original = schema_file.read_bytes()
rewritten = pattern.sub(
lambda match: file_uri + b"/" + match.group(1), original
)