import urllib.request,json,base64,os
from pathlib import Path
base='http://127.0.0.1:39135/api/v1'
token=Path(os.environ['PROOF_TOKEN_FILE']).read_text().strip()
def api(path,body=None,method='POST'):
 req=urllib.request.Request(base+path, data=json.dumps(body).encode() if body is not None else None,method=method,headers={'Authorization':'token '+token,'Content-Type':'application/json'})
 with urllib.request.urlopen(req) as r: return json.load(r)
api('/user/repos',{'name':'labels','auto_init':True,'default_branch':'main'})
api('/repos/demo/labels/branches',{'old_branch_name':'main','new_branch_name':'release-docs'})
api('/repos/demo/labels/contents/release.md',{'branch':'release-docs','content':base64.b64encode(b'Release notes\n').decode(),'message':'Document release'})
api('/repos/demo/labels/pulls',{'head':'release-docs','base':'main','title':'Document the release','body':'Add release documentation.'})
for name,color in [('documentation','0075ca'),('needs review','e4e669')]: api('/repos/demo/labels/labels',{'name':name,'color':color})
api('/repos/demo/labels/issues/1/labels',{'labels':[1,2]})
print('Created demo/labels #1 with two labels on real Forgejo.')
