def import_github(request): name = request.POST['name'] repo = request.POST['repo'] branch = request.POST['branch'] add_remote = (request.POST['add_remote'] == 'true') match = re.match( r'^(?:https?://|git@|git://)?(?:www\.)?github\.com[/:]([\w.-]+)/([\w.-]+?)(?:\.git|/|$)', repo) if match is None: return HttpResponse(json.dumps({ "success": False, 'error': _("Invalid Github URL.") }), content_type="application/json") github_user = match.group(1) github_project = match.group(2) try: project = Project.objects.create(owner=request.user, name=name) except IntegrityError as e: return json_failure(str(e)) if add_remote: project.github_repo = "%s/%s" % (github_user, github_project) project.github_branch = branch project.save() task = do_import_github.delay(project.id, github_user, github_project, branch, delete_project=True) return json_response({'task_id': task.task_id, 'project_id': project.id})
def import_github(request): name = request.POST['name'] repo = request.POST['repo'] branch = request.POST['branch'] add_remote = (request.POST['add_remote'] == 'true') match = re.match( r'^(?:https?://|git@|git://)?(?:www\.)?github\.com[/:]([\w.-]+)/([\w.-]+?)(?:\.git|/|$)', repo) if match is None: raise BadRequest(_("Invalid Github URL.")) github_user = match.group(1) github_project = match.group(2) try: project = Project.objects.create(owner=request.user, name=name) except IntegrityError as e: raise BadRequest(str(e)) if add_remote: project.github_repo = "%s/%s" % (github_user, github_project) project.github_branch = branch project.save() task = do_import_github.delay(project.id, github_user, github_project, branch, delete_project=True) return {'task_id': task.task_id, 'project_id': project.id}
def import_github(request): name = request.POST['name'] repo = request.POST['repo'] branch = request.POST['branch'] match = re.match(r'^(?:https?://|git@|git://)?(?:www\.)?github\.com[/:]([\w.-]+)/([\w.-]+?)(?:\.git|/|$)', repo) if match is None: return HttpResponse(json.dumps({"success": False, 'error': "Invalid GitHub URL."}), content_type="application/json") github_user = match.group(1) github_project = match.group(2) try: project = Project.objects.create(owner=request.user, name=name) except IntegrityError as e: return json_failure(str(e)) task = do_import_github.delay(project.id, github_user, github_project, branch, delete_project=True) return json_response({'task_id': task.task_id, 'project_id': project.id})
def import_github(request): name = request.POST['name'] repo = request.POST['repo'] branch = request.POST['branch'] add_remote = (request.POST['add_remote'] == 'true') match = re.match(r'^(?:https?://|git@|git://)?(?:www\.)?github\.com[/:]([\w.-]+)/([\w.-]+?)(?:\.git|/|$)', repo) if match is None: raise BadRequest(_("Invalid Github URL.")) github_user = match.group(1) github_project = match.group(2) try: project = Project.objects.create(owner=request.user, name=name) except IntegrityError as e: raise BadRequest(str(e)) if add_remote: project.github_repo = "%s/%s" % (github_user, github_project) project.github_branch = branch project.save() task = do_import_github.delay(project.id, github_user, github_project, branch, delete_project=True) return {'task_id': task.task_id, 'project_id': project.id}