From ff6c5b33694525072725bf3cf51dcd7f80594983 Mon Sep 17 00:00:00 2001 From: Alexander Saprykin Date: Thu, 23 Apr 2020 17:13:47 +0200 Subject: [PATCH] Revert "Added support for Github Enterprise instances (#1972)" This reverts commit 7ebc88222a18dde9531d8be0bdb8cf08d85bdbc0. --- AUTHORS | 1 - galaxy/api/githubapi.py | 4 +--- galaxy/api/serializers/repository.py | 6 +++-- galaxy/api/serializers/roles.py | 1 - galaxy/api/views/token.py | 6 ++--- galaxy/common/github.py | 36 ---------------------------- galaxy/main/models/repository.py | 8 +------ galaxy/worker/tasks/repository.py | 12 ++++------ 8 files changed, 13 insertions(+), 61 deletions(-) delete mode 100644 galaxy/common/github.py diff --git a/AUTHORS b/AUTHORS index 6c469e505..91983287d 100644 --- a/AUTHORS +++ b/AUTHORS @@ -11,7 +11,6 @@ Christopher Chase David Newswanger David Zager Dostonbek -Egor Margineanu Ivan Ivan Remizov James Cammarata diff --git a/galaxy/api/githubapi.py b/galaxy/api/githubapi.py index 9af93f247..c3f858264 100644 --- a/galaxy/api/githubapi.py +++ b/galaxy/api/githubapi.py @@ -24,7 +24,6 @@ from allauth.socialaccount.models import SocialToken from django.core.exceptions import ObjectDoesNotExist -from galaxy.common.github import get_github_api_url from galaxy.main.models import Provider @@ -59,8 +58,7 @@ def get_client(self): "User does not have a GitHub OAuth token" ) try: - client = Github(base_url=get_github_api_url(), - login_or_token=gh_token.token) + client = Github(gh_token.token) except GithubException as exc: raise Exception("Failed to connect to the GitHub API {0} - {1}" .format(exc.data, exc.status)) diff --git a/galaxy/api/serializers/repository.py b/galaxy/api/serializers/repository.py index 1de8f3a49..6093b2e5b 100644 --- a/galaxy/api/serializers/repository.py +++ b/galaxy/api/serializers/repository.py @@ -18,7 +18,6 @@ from django.urls import reverse from rest_framework import serializers as drf_serializers -from galaxy.common.github import get_github_web_url from galaxy.main.models import Repository from . import serializers @@ -165,8 +164,11 @@ def get_summary_fields(self, instance): } def get_external_url(self, instance): + server = '' + if instance.provider_namespace.provider.name.lower() == 'github': + server = 'https://github.com' return '{0}/{1}/{2}'.format( - get_github_web_url(), + server, instance.provider_namespace.name, instance.original_name) diff --git a/galaxy/api/serializers/roles.py b/galaxy/api/serializers/roles.py index e3e536004..eb89c8f5c 100644 --- a/galaxy/api/serializers/roles.py +++ b/galaxy/api/serializers/roles.py @@ -33,7 +33,6 @@ class BaseRoleSerializer(BaseSerializer): REPOSITORY_MOVED_FIELDS = ( 'github_user', 'github_repo', - 'github_server', ('github_branch', 'import_branch'), 'stargazers_count', 'forks_count', diff --git a/galaxy/api/views/token.py b/galaxy/api/views/token.py index 0730ccf4f..37f313c7c 100644 --- a/galaxy/api/views/token.py +++ b/galaxy/api/views/token.py @@ -2,6 +2,7 @@ import requests from allauth.socialaccount.models import SocialAccount +from django.conf import settings from django.contrib.auth import get_user_model from django.core.exceptions import ObjectDoesNotExist, PermissionDenied @@ -13,7 +14,6 @@ from galaxy.api.views import base_views from galaxy.api.serializers import TokenSerializer -from galaxy.common.github import get_github_api_url __all__ = [ 'TokenView', @@ -76,7 +76,7 @@ def post(self, request, *args, **kwargs): raise ValidationError({'detail': "Invalid request."}) try: - git_status = requests.get(get_github_api_url()) + git_status = requests.get(settings.GITHUB_SERVER) git_status.raise_for_status() except Exception: raise ValidationError({ @@ -86,7 +86,7 @@ def post(self, request, *args, **kwargs): try: header = dict(Authorization='token ' + github_token) gh_user = requests.get( - get_github_api_url() + '/user', headers=header + settings.GITHUB_SERVER + '/user', headers=header ) gh_user.raise_for_status() gh_user = gh_user.json() diff --git a/galaxy/common/github.py b/galaxy/common/github.py deleted file mode 100644 index f37191e66..000000000 --- a/galaxy/common/github.py +++ /dev/null @@ -1,36 +0,0 @@ -# (c) 2012-2018, Ansible by Red Hat -# -# This file is part of Ansible Galaxy -# -# Ansible Galaxy is free software: you can redistribute it and/or modify -# it under the terms of the Apache License as published by -# the Apache Software Foundation, either version 2 of the License, or -# (at your option) any later version. -# -# Ansible Galaxy is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# Apache License for more details. -# -# You should have received a copy of the Apache License -# along with Galaxy. If not, see . - -from allauth.socialaccount import app_settings -from allauth.socialaccount.providers.github.provider import GitHubProvider - -provider_id = GitHubProvider.id -settings = app_settings.PROVIDERS.get(provider_id, {}) - - -def get_github_web_url(): - if 'GITHUB_URL' in settings: - return settings.get('GITHUB_URL').rstrip('/') - else: - return 'https://github.com' - - -def get_github_api_url(): - if 'GITHUB_URL' in settings: - return '{0}/api/v3'.format(get_github_web_url()) - else: - return 'https://api.github.com' diff --git a/galaxy/main/models/repository.py b/galaxy/main/models/repository.py index 1d4735cea..e20266547 100644 --- a/galaxy/main/models/repository.py +++ b/galaxy/main/models/repository.py @@ -6,7 +6,6 @@ from django.urls import reverse from galaxy import constants -from galaxy.common.github import get_github_web_url from galaxy.main import fields from .base import BaseModel @@ -107,8 +106,7 @@ class Meta: @property def clone_url(self): - return "{server}/{user}/{repo}.git".format( - server=get_github_web_url(), + return "https://github.com/{user}/{repo}.git".format( user=self.provider_namespace.name, repo=self.original_name ) @@ -121,10 +119,6 @@ def github_user(self): def github_repo(self): return self.original_name - @property - def github_server(self): - return get_github_web_url() - @property def content_counts(self): return Content.objects \ diff --git a/galaxy/worker/tasks/repository.py b/galaxy/worker/tasks/repository.py index 12bd9882a..24c00e18f 100644 --- a/galaxy/worker/tasks/repository.py +++ b/galaxy/worker/tasks/repository.py @@ -27,7 +27,6 @@ from allauth.socialaccount import models as auth_models from galaxy import constants -from galaxy.common.github import get_github_api_url from galaxy.importer import repository as i_repo from galaxy.importer import exceptions as i_exc from galaxy.main import models @@ -91,15 +90,12 @@ def _import_repository(import_task, logger): logger.info(' ') token = _get_social_token(import_task) - gh_api = github.Github(base_url=get_github_api_url(), - login_or_token=token) + gh_api = github.Github(token) gh_repo = gh_api.get_repo(repo_full_name) try: repo_info = i_repo.import_repository( - gh_repo.clone_url.replace("https://", "https://{token}@".format( - token=token - )), + repository.clone_url, branch=import_task.import_branch, temp_dir=settings.CONTENT_DOWNLOAD_DIR, logger=logger) @@ -319,8 +315,8 @@ def _update_repo_info(repository, gh_repo, commit_info, repo_description): repository.commit = commit_info.sha repository.commit_message = commit_info.message[:255] repository.commit_url = \ - '{0}/repos/{1}/git/commits/{2}'.format( - get_github_api_url(), gh_repo.full_name, commit_info.sha) + 'https://api.github.com/repos/{0}/git/commits/{1}'.format( + gh_repo.full_name, commit_info.sha) repository.commit_created = commit_info.committer_date