Skip to content

Commit dd31aee

Browse files
committed
Add support for https, token push and ssh key optional
1 parent f6573ca commit dd31aee

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

github2gitlab/main.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,11 @@ def sh(self, command):
163163
return "".join(lines)
164164

165165
def gitlab_create_remote(self, repo):
166+
# when using access token, gitlab doesn't care the username
167+
url = self.gitlab['git'].replace(
168+
'https://', 'https://user:{}@'.format(self.gitlab['token']))
166169
repo.create_remote('gitlab',
167-
self.gitlab['git'] + "/" +
170+
url + ("/" if url.startswith('http') else ':') +
168171
self.gitlab['namespace'] + "/" +
169172
self.gitlab['name'] + ".git")
170173

@@ -240,8 +243,12 @@ def git_mirror_optimize(self, repo):
240243

241244
def add_key(self):
242245
"Add ssh key to gitlab if necessary"
243-
with open(self.args.ssh_public_key) as f:
244-
public_key = f.read().strip()
246+
try:
247+
with open(self.args.ssh_public_key) as f:
248+
public_key = f.read().strip()
249+
except:
250+
log.debug("No key found in {}".format(self.args.ssh_public_key))
251+
return None
245252
g = self.gitlab
246253
url = g['url'] + "/user/keys"
247254
query = {'private_token': g['token']}

0 commit comments

Comments
 (0)