import subprocess,json,time,pathlib,sys
root=pathlib.Path(sys.argv[1])
def api(path,*args):
 return json.loads(subprocess.check_output(['glab','api',path,*args],text=True))
p=api('projects','-X','POST','-f','name=HTML reference proof','-f','path=html-reference-proof-'+str(int(time.time())),'-f','visibility=private','-f','initialize_with_readme=true')
(root/'fixture.json').write_text(json.dumps(p))
i=str(p['id'])
api('projects/'+i+'/repository/branches','-X','POST','-f','branch=html-proof','-f','ref=main')
api('projects/'+i+'/repository/files/proof.txt','-X','POST','-f','branch=html-proof','-f','content=HTML reference rendering fixture','-f','commit_message=Add rendering fixture')
body='''Case A: See <code title="> </code>">#41</code> and #42.

Case B: See <span title="<code>">example</span>, then #42.

Control: See <code>#41</code> and #42.

<pre title="> <code>">#41</pre>

Case C: See #42.'''
(root/'description.md').write_text(body)
m=api('projects/'+i+'/merge_requests','-X','POST','-f','source_branch=html-proof','-f','target_branch=main','-f','title=HTML reference proof','-f','description='+body)
(root/'mr.json').write_text(json.dumps(m))
print(json.dumps({'id':p['id'],'repo':p['http_url_to_repo'],'mr':m['iid']}))
