Skip to content

Commit

Permalink
Add support for https, token push and ssh key optional
Browse files Browse the repository at this point in the history
  • Loading branch information
xcompass committed Jul 17, 2017
1 parent f6573ca commit dd31aee
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions github2gitlab/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,11 @@ def sh(self, command):
return "".join(lines)

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

Expand Down Expand Up @@ -240,8 +243,12 @@ def git_mirror_optimize(self, repo):

def add_key(self):
"Add ssh key to gitlab if necessary"
with open(self.args.ssh_public_key) as f:
public_key = f.read().strip()
try:
with open(self.args.ssh_public_key) as f:
public_key = f.read().strip()
except:
log.debug("No key found in {}".format(self.args.ssh_public_key))
return None
g = self.gitlab
url = g['url'] + "/user/keys"
query = {'private_token': g['token']}
Expand Down

0 comments on commit dd31aee

Please sign in to comment.