Skip to content

Instantly share code, notes, and snippets.

@braun-steven
Created February 26, 2017 21:00
Show Gist options
  • Save braun-steven/c556d0ee390fcdd1bdd486ed3445a010 to your computer and use it in GitHub Desktop.
Save braun-steven/c556d0ee390fcdd1bdd486ed3445a010 to your computer and use it in GitHub Desktop.
Export and import issues in gogs
import json
from time import sleep
from pprint import pprint
import requests
def main():
# User from old repo
USER_FROM = 'user'
PW_FROM = 'password'
AUTH_FROM = (USER_FROM, PW_FROM)
# User from new into
USER_INTO = USER_FROM
PW_INTO = PW_FROM
AUTH_INTO = (USER_INTO, PW_INTO)
# URLS
URL_FROM = "https://mrbungle.zdv.uni-mainz.de/git/api/v1/repos/envipath/envipath/issues?page="
URL_INTO = "https://try.gogs.io/api/v1/repos/slang03/test/issues"
headers = {'Content-type': 'application/json', 'Accept': 'text/plain'}
# Collect the issues
new_data = requests.get(URL_FROM + "1", headers=headers, auth=AUTH_FROM).json()
issues = []
i = 1
while len(new_data) > 0:
for iss in new_data:
issues.append(iss)
i += 1
new_data = requests.get(URL_FROM + str(i), headers=headers, auth=AUTH_FROM).json()
print('Number of issues found: ' + str(len(issues)))
failed_issues = []
# Post the issues
for idx, iss in enumerate(issues):
prog = float(idx)/len(issues)*50
print('Progress: ' + str(idx)+'/'+str(len(issues)) + ' ' + '#'*int(prog) +'-'*(50 - int(prog)), end='\r')
# Create post data
data = dict(
title=iss['title'],
body=iss['body'],
)
# Post issue
r = requests.post(URL_INTO, data=json.dumps(data), headers=headers, auth=AUTH_INTO).json()
# Collect failed issues
if 'message' in r:
failed_issues.append(data)
# Show failed issues
if len(failed_issues) > 0:
pprint('Failed issues: ')
pprint(failed_issues)
if __name__ == '__main__':
main()
exit(0)
@msdousti
Copy link

Can you check this with the most recent version of Gogs (Version: 0.11.34.1122)? I get the following error:

Traceback (most recent call last):
  File "gogs_export_import_issues.py", line 64, in <module>
    main()
  File "gogs_export_import_issues.py", line 24, in main
    new_data = requests.get(URL_FROM + "1", headers=headers, auth=AUTH_FROM).json()
  File "C:\Python35\lib\site-packages\requests\models.py", line 892, in json
    return complexjson.loads(self.text, **kwargs)
  File "C:\Python35\lib\json\__init__.py", line 319, in loads
    return _default_decoder.decode(s)
  File "C:\Python35\lib\json\decoder.py", line 339, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Python35\lib\json\decoder.py", line 357, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

I tried sending the request manually (using Postman), and I noted that Gogs returns "Please enable JavaScript in your browser!" error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment