def username_from_repo(self, repo):
"""Generate a username for a git repo url
e.g. minrk-binder-example-abc123
from https://github.com/minrk/binder-example.git
"""
# start with url path
print
if '://' not in repo and _ssh_repo_pat.match(repo):
# ssh url
path = repo.split(':', 1)[1]
else:
path = urlparse(repo).path
prefix = path.strip('/').replace('/', '-').lower()
if prefix.endswith('.git'):
# strip trailing .git
prefix = prefix[:-4]
if len(prefix) > 32:
# if it's long, truncate
prefix = '{}-{}'.format(prefix[:15], prefix[-15:])
# add a random suffix to avoid collisions for users on the same image
return '{}-{}'.format(prefix, ''.join(random.choices(SUFFIX_CHARS, k=SUFFIX_LENGTH)))
评论列表
文章目录