1
0

Changed method of getting files to http and added to flag to use ssh

This commit is contained in:
Logan Bonney 2019-02-13 17:52:16 -07:00
parent 33f594819c
commit bbdb5fe355
2 changed files with 19 additions and 3 deletions

View File

@ -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

16
migrate_gitlab_to_gogs.py Executable file → Normal file
View File

@ -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])