"""Create the real private GitLab fixture and update a downloaded scenario's fixture references.
Usage: python3 seed-gitlab.py merge-credits-mixed-endings.e2e.ts
Requires an authenticated glab. Delete the printed project ID after the proof.
"""
import json
from pathlib import Path
import subprocess
import sys
import time

project = json.loads(subprocess.check_output([
    "glab", "api", "-X", "POST", "projects",
    "-f", f"name=t3-mixed-endings-proof-{int(time.time())}",
    "-f", "visibility=private", "-f", "initialize_with_readme=true",
    "-f", "squash_option=always", "-f", "squash_commit_template=%{title}\n\n%{first_commit}",
]))
scenario = Path(sys.argv[1])
scenario.write_text(scenario.read_text().replace("89705266", str(project["id"])).replace(
    "https://gitlab.com/julius54/t3-mixed-endings-proof-46620.git", project["http_url_to_repo"]
))
print(f"Created private scratch project {project['id']}; updated scenario fixture references.")
print(f"Cleanup: glab api -X DELETE projects/{project['id']}")
