import json
import subprocess

def api(endpoint, **fields):
    args = ['glab', 'api', endpoint, '-X', 'POST']
    for key, value in fields.items():
        args += ['-f', f'{key}={value}']
    return json.loads(subprocess.check_output(args))

project = api('projects', name='unicode-reference-proof-1795830273', visibility='private', initialize_with_readme='true')
for number, title in [(1, '界' * 99 + '𠀀'), (2, 'Second MR')]:
    prefix = f"projects/{project['id']}"
    api(prefix + '/repository/branches', branch=f'proof-{number}', ref='main')
    api(prefix + f'/repository/files/proof-{number}.txt', branch=f'proof-{number}', content='proof', commit_message='Add proof file')
    api(prefix + '/merge_requests', source_branch=f'proof-{number}', target_branch='main', title=title)
print(project['http_url_to_repo'])
# After capturing both sides, delete only this synthetic project:
# glab api projects/<printed project's numeric id> -X DELETE
