Skip to content

Commit e8ea0ea

Browse files
committed
migrate template: Add function to read the project type
Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
1 parent 57a90b2 commit e8ea0ea

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

.github/cookiecutter-migrate.template.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
""" # noqa: E501
2222

2323
import hashlib
24+
import json
2425
import os
2526
import subprocess
2627
import tempfile
@@ -36,6 +37,28 @@ def main() -> None:
3637
print("=" * 72)
3738

3839

40+
def read_project_type() -> str | None:
41+
"""Read the cookiecutter project type from the replay file."""
42+
replay_path = Path(".cookiecutter-replay.json")
43+
if not replay_path.exists():
44+
return None
45+
46+
try:
47+
data = json.loads(replay_path.read_text(encoding="utf-8"))
48+
except (json.JSONDecodeError, OSError):
49+
return None
50+
51+
cookiecutter_data = data.get("cookiecutter")
52+
if not isinstance(cookiecutter_data, dict):
53+
return None
54+
55+
project_type = cookiecutter_data.get("type")
56+
if not isinstance(project_type, str):
57+
return None
58+
59+
return project_type
60+
61+
3962
def apply_patch(patch_content: str) -> None:
4063
"""Apply a patch using the patch utility."""
4164
subprocess.run(["patch", "-p1"], input=patch_content.encode(), check=True)

0 commit comments

Comments
 (0)