"""Create the real GitLab fixture used by pr-header-fold-whitespace.e2e.ts.
Requires an authenticated glab; creates synthetic data in a private project.
Delete the printed project ID with: glab api -X DELETE projects/ID
"""
import json
import subprocess

def api(path, **fields):
    args = ['glab', 'api', '-X', 'POST', path]
    for key, value in fields.items():
        args += ['-f', f'{key}={value}']
    result = subprocess.run(args, check=True, capture_output=True, text=True)
    return json.loads(result.stdout)

project = api('projects', name='header-fold-proof-44079-1796103123', visibility='private', initialize_with_readme='true', default_branch='main')
p = project['id']
api(f'projects/{p}/repository/branches', branch='leading-space', ref='main')
api(f'projects/{p}/repository/files/%20note.txt', branch='leading-space', content='Leading-space file\n', commit_message='Add leading-space note')
api(f'projects/{p}/repository/files/note.txt', branch='leading-space', content='Ordinary file\n', commit_message='Add ordinary note')
mr = api(f'projects/{p}/merge_requests', source_branch='leading-space', target_branch='main', title='Add note files')
print(json.dumps({'projectId': p, 'repository': project['http_url_to_repo'], 'mergeRequest': mr['web_url']}))
