"""Real GitLab API fixture used for the mobile host-collision reproduction.
Requires glab authenticated with permission to create projects in juliusmarminge.
Delete the temporary project after capturing both commits. Do not alter GitHub PR 1.
"""
import json
import subprocess

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

project = api('projects', {
    'name': 'trpc-interop', 'path': 'trpc-interop', 'namespace_id': 131484201,
    'visibility': 'private', 'initialize_with_readme': True, 'default_branch': 'main',
})
p = f"projects/{project['id']}"
api(p + '/repository/commits', {
    'branch': 'main', 'commit_message': 'Create line-count fixture',
    'actions': [{'action': 'update', 'file_path': 'README.md',
                 'content': ''.join(f'Original line {i}\n' for i in range(9))}],
})
api(p + '/repository/branches', {'branch': 'stats-change', 'ref': 'main'})
api(p + '/repository/commits', {
    'branch': 'stats-change', 'commit_message': 'Change fixture line counts',
    'actions': [{'action': 'update', 'file_path': 'README.md',
                 'content': ''.join(f'Changed content {i}\n' for i in range(40))}],
})
mr = api(p + '/merge_requests', {
    'source_branch': 'stats-change', 'target_branch': 'main', 'title': 'GitLab stats change',
})
print({'projectId': project['id'], 'requestNumber': mr['iid']})
