From bbdb5fe3559e34582d8398e810ace4b52d53b42d Mon Sep 17 00:00:00 2001 From: Logan Bonney Date: Wed, 13 Feb 2019 17:52:16 -0700 Subject: [PATCH] Changed method of getting files to http and added to flag to use ssh --- README.md | 6 +++++- migrate_gitlab_to_gogs.py | 16 ++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) mode change 100755 => 100644 migrate_gitlab_to_gogs.py diff --git a/README.md b/README.md index 15c37d9..78f05c2 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,8 @@ usage: migrate_gitlab_to_gogs.py [-h] --source_namespace SOURCE_NAMESPACE [--add_to_private] [--add_to_organization organization_name] --source_repo SOURCE_REPO --target_repo - TARGET_REPO [--no_confirm] + TARGET_REPO [--no_confirm] [--skip_existing] + [--use_ssh] optional arguments: -h, --help show this help message and exit @@ -41,6 +42,9 @@ optional arguments: URL to your gogs / gitea repo in the format http://mygogs.com/ --no_confirm Skip user confirmation of each single step + --skip_existing Skip repositories that already exist on remote without + asking the user + --use_ssh Use ssh to pull/push files to repos ``` ## Requirements diff --git a/migrate_gitlab_to_gogs.py b/migrate_gitlab_to_gogs.py old mode 100755 new mode 100644 index 0154242..fcf0afc --- a/migrate_gitlab_to_gogs.py +++ b/migrate_gitlab_to_gogs.py @@ -25,6 +25,9 @@ parser.add_argument('--no_confirm', parser.add_argument('--skip_existing', help='Skip repositories that already exist on remote without asking the user', action='store_true') +parser.add_argument('--use_ssh', + help='Use ssh to pull/push files to repos', + action='store_true') args = parser.parse_args() @@ -106,7 +109,10 @@ if not args.no_confirm: for i in range(len(filtered_projects)): src_name = filtered_projects[i]['name'] - src_url = filtered_projects[i]['ssh_url_to_repo'] + if args.use_ssh: + src_url = filtered_projects[i]['ssh_url_to_repo'] + else: + src_url = filtered_projects[i]['http_url_to_repo'] src_description = filtered_projects[i]['description'] dst_name = src_name.replace(' ','-') @@ -118,8 +124,11 @@ for i in range(len(filtered_projects)): # Create repo if args.add_to_private: + print('Posting to:' + gots_url + '/user/repos') create_repo = s.post(gogs_url+'/user/repos', data=dict(token=gogs_token, name=dst_name, private=True)) + elif args.add_to_organization: + print('Posting to:' + gogs_url + '/org/%s/repos') create_repo = s.post(gogs_url+'/org/%s/repos'%args.add_to_organization, data=dict(token=gogs_token, name=dst_name, private=True, description=src_description)) if create_repo.status_code != 201: @@ -134,7 +143,10 @@ for i in range(len(filtered_projects)): dst_info = json.loads(create_repo.text) - dst_url = dst_info['ssh_url'] + if args.use_ssh: + dst_url = dst_info['ssh_url'] + else: + dst_url = dst_info['html_url'] # Git pull and push subprocess.check_call(['git','clone','--bare',src_url]) os.chdir(src_url.split('/')[-1])