From 40aac38d43c2d7c2220b10a1bef34ac85f960359 Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Thu, 7 Jun 2018 22:32:17 +0100 Subject: [PATCH] Fix worker stopping due to gitpython asking for credentials --- app/tasks/importtasks.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/app/tasks/importtasks.py b/app/tasks/importtasks.py index d2c26ea..302203f 100644 --- a/app/tasks/importtasks.py +++ b/app/tasks/importtasks.py @@ -20,7 +20,7 @@ from git import GitCommandError from flask.ext.sqlalchemy import SQLAlchemy from urllib.error import HTTPError import urllib.request -from urllib.parse import urlparse, quote_plus +from urllib.parse import urlparse, quote_plus, urlsplit from app import app from app.models import * from app.tasks import celery, TaskError @@ -274,6 +274,10 @@ class PackageTreeNode: def get(self, key): return self.meta.get(key) +def generateGitURL(urlstr): + scheme, netloc, path, query, frag = urlsplit(urlstr) + + return "http://:@" + netloc + path + query # Clones a repo from an unvalidated URL. # Returns a tuple of path and repo on sucess. @@ -284,7 +288,11 @@ def cloneRepo(urlstr, ref=None, recursive=False): err = None try: - repo = git.Repo.clone_from(urlstr, gitDir, progress=None, env=None, depth=1, recursive=recursive) + gitUrl = generateGitURL(urlstr) + print("Cloning from " + gitUrl) + repo = git.Repo.clone_from(gitUrl, gitDir, \ + progress=None, env=None, depth=1, recursive=recursive, kill_after_timeout=15) + if ref is not None: repo.create_head("myhead", ref).checkout() return gitDir, repo