"""Create the real GitLab fixture; requires an authenticated glab CLI."""
import json
import subprocess

def api(endpoint, fields):
    result = subprocess.run(
        ['glab', 'api', '-X', 'POST', endpoint, '--input', '-'],
        input=json.dumps(fields), capture_output=True, text=True, check=True,
    )
    return json.loads(result.stdout)

project = api('projects', {
    'name': 'quoted-label-proof-45796',
    'visibility': 'public',
    'initialize_with_readme': True,
})
prefix = f"projects/{project['id']}/"
api(prefix + 'labels', {'name': 'needs "repro"', 'color': '#6750a4'})
for i, title in [(1, 'fix the readme'), (2, 'fix something else')]:
    branch = f'fix-{i}'
    api(prefix + 'repository/branches', {'branch': branch, 'ref': 'main'})
    api(prefix + 'repository/commits', {
        'branch': branch, 'commit_message': title,
        'actions': [{'action': 'create', 'file_path': f'change-{i}.txt', 'content': title}],
    })
    api(prefix + 'merge_requests', {
        'source_branch': branch, 'target_branch': 'main', 'title': title,
        **({'labels': 'needs "repro"'} if i == 1 else {}),
    })
print(project['web_url'])
