Created
February 26, 2017 21:00
-
-
Save braun-steven/c556d0ee390fcdd1bdd486ed3445a010 to your computer and use it in GitHub Desktop.
Export and import issues in gogs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can you check this with the most recent version of Gogs (Version: 0.11.34.1122)? I get the following error:
I tried sending the request manually (using Postman), and I noted that Gogs returns "Please enable JavaScript in your browser!" error.