import json, urllib.request
from pathlib import Path
root=Path(__file__).parent
token=(root/'token').read_text().strip()
def api(path, body=None):
 req=urllib.request.Request('http://localhost:3177/api/v1/'+path, data=None if body is None else json.dumps(body).encode(),headers={'Authorization':'token '+token,'Content-Type':'application/json'})
 with urllib.request.urlopen(req) as r: return json.load(r)
for name, count in [('small',1),('big',52)]:
 api('user/repos',{'name':name,'auto_init':True,'default_branch':'main'})
 for label,color in [('bug','ee0000'),('feature','00aa55')]: api(f'repos/alice/{name}/labels',{'name':label,'color':color})
 for n in range(1,count+1): api(f'repos/alice/{name}/issues',{'title':'Only open issue' if count==1 else f'Pagination issue {n:02}'})
print('Seeded real Forgejo: small (1 issue, 2 labels, alice), big (52 issues).')
