Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion src/job/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,18 @@ def clone_repo(self, commit, clone_url, branch, ref, full_history, sub_path=None
schema, url = clone_url.split("://")
clone_url = schema + "://" + token + '@' + url

https_fallback = None
if token and self.github_host:
for prefix in ('git@%s:' % self.github_host, 'ssh://git@%s/' % self.github_host):
if clone_url.startswith(prefix):
https_fallback = 'https://%s@%s/%s' % (token, self.github_host, clone_url[len(prefix):])
break

# Only clean up a failed clone if its destination was absent or empty.
if https_fallback and os.path.lexists(mount_repo_dir):
if os.path.islink(mount_repo_dir) or not os.path.isdir(mount_repo_dir) or os.listdir(mount_repo_dir):
https_fallback = None

cmd = ['git', 'clone']

if not full_history:
Expand All @@ -182,7 +194,17 @@ def clone_repo(self, commit, clone_url, branch, ref, full_history, sub_path=None
cmd += ['--single-branch', '-b', branch]

cmd += [clone_url, mount_repo_dir]
c.execute_mask(cmd, show=True, retry=True, mask=token)
try:
c.execute_mask(cmd, show=True, retry=https_fallback is None, mask=token)
except Exception:
if not https_fallback:
raise
c.collect('SSH clone failed, retrying with HTTPS and GitHub token', show=True)
if os.path.isdir(mount_repo_dir):
shutil.rmtree(mount_repo_dir)
clone_url = https_fallback
cmd[-2] = clone_url
c.execute_mask(cmd, show=True, retry=True, mask=token)

if ref:
cmd = ['git', 'fetch']
Expand Down
Loading