import os,json,urllib.request,base64,pathlib
org=os.environ['AZURE_DEVOPS_TEST_ORG'].rstrip('/')
project=os.environ['AZURE_DEVOPS_TEST_PROJECT']
repo=os.environ['AZURE_DEVOPS_TEST_REPO']
base=f'{org}/{project}/_apis/git/repositories/{repo}'
auth=base64.b64encode((':'+os.environ['AZURE_DEVOPS_EXT_PAT']).encode()).decode()
def api(path,data=None,method=None):
 req=urllib.request.Request(base+path+('?' if '?' not in path else '&')+'api-version=7.1',data=json.dumps(data).encode() if data is not None else None,headers={'Authorization':'Basic '+auth,'Content-Type':'application/json'},method=method)
 return json.load(urllib.request.urlopen(req))
main=api('/refs?filter=heads/main')['value'][0]['objectId']
items=[]
for name,desc in [('empty','- [ ]\n\n- [ ] Same'),('control','- [ ] Same')]:
 branch='proof-43818-1126-'+name
 api('/pushes',{'refUpdates':[{'name':'refs/heads/'+branch,'oldObjectId':'0'*40}], 'commits':[{'comment':'Synthetic checkbox proof','parents':[main],'changes':[{'changeType':'add','item':{'path':'/proof-43818-'+name+'.txt'},'newContent':{'content':'Synthetic checkbox proof','contentType':'rawtext'}}]}]})
 pr=api('/pullrequests',{'sourceRefName':'refs/heads/'+branch,'targetRefName':'refs/heads/main','title':'repro-43818 '+name,'description':desc})
 items.append({'id':pr['pullRequestId'],'branch':branch})
pathlib.Path('azure-state.json').write_text(json.dumps(items))
print(items)
