From 15c9baa7ec57a9bd36bdfeca80c29549fbacdbdd Mon Sep 17 00:00:00 2001 From: Santos Gallegos Date: Tue, 17 Dec 2024 06:03:39 -0500 Subject: [PATCH] Remove dead code from old footer (#11854) Ref https://github.com/readthedocs/readthedocs.org/pull/11836 --- readthedocs/builds/models.py | 118 ---------- readthedocs/projects/constants.py | 11 - readthedocs/projects/models.py | 39 ---- readthedocs/projects/version_handling.py | 12 - readthedocs/rtd_tests/tests/test_project.py | 3 - .../rtd_tests/tests/test_repo_parsing.py | 211 ------------------ 6 files changed, 394 deletions(-) delete mode 100644 readthedocs/rtd_tests/tests/test_repo_parsing.py diff --git a/readthedocs/builds/models.py b/readthedocs/builds/models.py index ffc34333781..ec5988a6ea3 100644 --- a/readthedocs/builds/models.py +++ b/readthedocs/builds/models.py @@ -61,14 +61,11 @@ from readthedocs.notifications.models import Notification from readthedocs.projects.constants import ( BITBUCKET_COMMIT_URL, - BITBUCKET_URL, DOCTYPE_CHOICES, GITHUB_COMMIT_URL, GITHUB_PULL_REQUEST_COMMIT_URL, - GITHUB_URL, GITLAB_COMMIT_URL, GITLAB_MERGE_REQUEST_COMMIT_URL, - GITLAB_URL, MEDIA_TYPES, MKDOCS, MKDOCS_HTML, @@ -550,121 +547,6 @@ def get_storage_paths(self): return paths - def get_github_url( - self, - docroot, - filename, - source_suffix=".rst", - action="view", - ): - """ - Return a GitHub URL for a given filename. - - :param docroot: Location of documentation in repository - :param filename: Name of file - :param source_suffix: File suffix of documentation format - :param action: `view` (default) or `edit` - """ - repo_url = self.project.repo - if "github" not in repo_url: - return "" - - if not docroot: - return "" - - # Normalize /docroot/ - docroot = "/" + docroot.strip("/") + "/" - - if action == "view": - action_string = "blob" - elif action == "edit": - action_string = "edit" - - user, repo = get_github_username_repo(repo_url) - if not user and not repo: - return "" - - if not filename: - # If there isn't a filename, we don't need a suffix - source_suffix = "" - - return GITHUB_URL.format( - user=user, - repo=repo, - version=self.commit_name, - docroot=docroot, - path=filename, - source_suffix=source_suffix, - action=action_string, - ) - - def get_gitlab_url( - self, - docroot, - filename, - source_suffix=".rst", - action="view", - ): - repo_url = self.project.repo - if "gitlab" not in repo_url: - return "" - - if not docroot: - return "" - - # Normalize /docroot/ - docroot = "/" + docroot.strip("/") + "/" - - if action == "view": - action_string = "blob" - elif action == "edit": - action_string = "edit" - - user, repo = get_gitlab_username_repo(repo_url) - if not user and not repo: - return "" - - if not filename: - # If there isn't a filename, we don't need a suffix - source_suffix = "" - - return GITLAB_URL.format( - user=user, - repo=repo, - version=self.commit_name, - docroot=docroot, - path=filename, - source_suffix=source_suffix, - action=action_string, - ) - - def get_bitbucket_url(self, docroot, filename, source_suffix=".rst"): - repo_url = self.project.repo - if "bitbucket" not in repo_url: - return "" - if not docroot: - return "" - - # Normalize /docroot/ - docroot = "/" + docroot.strip("/") + "/" - - user, repo = get_bitbucket_username_repo(repo_url) - if not user and not repo: - return "" - - if not filename: - # If there isn't a filename, we don't need a suffix - source_suffix = "" - - return BITBUCKET_URL.format( - user=user, - repo=repo, - version=self.commit_name, - docroot=docroot, - path=filename, - source_suffix=source_suffix, - ) - class APIVersion(Version): diff --git a/readthedocs/projects/constants.py b/readthedocs/projects/constants.py index eae06bd9e8f..08db597e053 100644 --- a/readthedocs/projects/constants.py +++ b/readthedocs/projects/constants.py @@ -371,23 +371,12 @@ re.compile(r"gitlab.com/(.+)/(.+)"), re.compile(r"gitlab.com:(.+)/(.+)\.git$"), ] -GITHUB_URL = ( - "https://github.com/{user}/{repo}/" - "{action}/{version}{docroot}{path}{source_suffix}" -) GITHUB_COMMIT_URL = "https://github.com/{user}/{repo}/commit/{commit}" GITHUB_PULL_REQUEST_URL = "https://github.com/{user}/{repo}/pull/{number}" GITHUB_PULL_REQUEST_COMMIT_URL = ( "https://github.com/{user}/{repo}/pull/{number}/commits/{commit}" ) -BITBUCKET_URL = ( - "https://bitbucket.org/{user}/{repo}/src/{version}{docroot}{path}{source_suffix}" -) BITBUCKET_COMMIT_URL = "https://bitbucket.org/{user}/{repo}/commits/{commit}" -GITLAB_URL = ( - "https://gitlab.com/{user}/{repo}/" - "{action}/{version}{docroot}{path}{source_suffix}" -) GITLAB_COMMIT_URL = "https://gitlab.com/{user}/{repo}/commit/{commit}" GITLAB_MERGE_REQUEST_COMMIT_URL = ( "https://gitlab.com/{user}/{repo}/commit/{commit}?merge_request_iid={number}" diff --git a/readthedocs/projects/models.py b/readthedocs/projects/models.py index cce8140a539..3adce28e43c 100644 --- a/readthedocs/projects/models.py +++ b/readthedocs/projects/models.py @@ -13,7 +13,6 @@ from django.contrib.contenttypes.fields import GenericRelation from django.core.validators import MaxValueValidator, MinValueValidator from django.db import models -from django.db.models import Prefetch from django.urls import reverse from django.utils import timezone from django.utils.crypto import get_random_string @@ -47,7 +46,6 @@ ProjectQuerySet, RelatedProjectQuerySet, ) -from readthedocs.projects.templatetags.projects_tags import sort_version_aware from readthedocs.projects.validators import ( validate_build_config_file, validate_custom_prefix, @@ -1079,43 +1077,6 @@ def active_versions(self): active=True, uploaded=True ) - def ordered_active_versions(self, **kwargs): - """ - Get all active versions, sorted. - - :param kwargs: All kwargs are passed down to the - `Version.internal.public` queryset. - """ - from readthedocs.builds.models import Version - - kwargs.update( - { - "project": self, - "only_active": True, - "only_built": True, - }, - ) - versions = ( - Version.internal.public(**kwargs) - .select_related( - "project", - "project__main_language_project", - ) - .prefetch_related( - Prefetch( - "project__superprojects", - ProjectRelationship.objects.all().select_related("parent"), - to_attr="_superprojects", - ), - Prefetch( - "project__domains", - Domain.objects.filter(canonical=True), - to_attr="_canonical_domains", - ), - ) - ) - return sort_version_aware(versions) - def all_active_versions(self): """ Get queryset with all active versions. diff --git a/readthedocs/projects/version_handling.py b/readthedocs/projects/version_handling.py index b9c7ff39b06..2d18a58f33d 100644 --- a/readthedocs/projects/version_handling.py +++ b/readthedocs/projects/version_handling.py @@ -126,18 +126,6 @@ def sort_versions(version_list): return versions -def highest_version(version_list): - """ - Return the highest version for a given ``version_list``. - - :rtype: tupe(readthedocs.builds.models.Version, packaging.version.Version) - """ - versions = sort_versions(version_list) - if versions: - return versions[0] - return (None, None) - - def determine_stable_version(version_list): """ Determine a stable version for version list. diff --git a/readthedocs/rtd_tests/tests/test_project.py b/readthedocs/rtd_tests/tests/test_project.py index 91d19ea08c1..7a1e238f302 100644 --- a/readthedocs/rtd_tests/tests/test_project.py +++ b/readthedocs/rtd_tests/tests/test_project.py @@ -168,9 +168,6 @@ def test_get_storage_path_for_external_versions(self): "external/htmlzip/pip/99/pip.zip", ) - def test_ordered_active_versions_excludes_external_versions(self): - self.assertNotIn(self.external_version, self.pip.ordered_active_versions()) - def test_active_versions_excludes_external_versions(self): self.assertNotIn(self.external_version, self.pip.active_versions()) diff --git a/readthedocs/rtd_tests/tests/test_repo_parsing.py b/readthedocs/rtd_tests/tests/test_repo_parsing.py deleted file mode 100644 index d3c042cf775..00000000000 --- a/readthedocs/rtd_tests/tests/test_repo_parsing.py +++ /dev/null @@ -1,211 +0,0 @@ -from django.test import TestCase - -from readthedocs.projects.models import Project - - -class TestRepoParsing(TestCase): - fixtures = ["eric", "test_data"] - - def setUp(self): - self.client.login(username="eric", password="test") - self.pip = Project.objects.get(slug="pip") - self.version = self.pip.versions.create_latest() - - def test_github(self): - self.pip.repo = "https://github.com/user/repo" - self.assertEqual( - self.version.get_github_url(docroot="/docs/", filename="file"), - "https://github.com/user/repo/blob/master/docs/file.rst", - ) - - self.pip.repo = "https://github.com/user/repo/" - self.assertEqual( - self.version.get_github_url(docroot="/docs/", filename="file"), - "https://github.com/user/repo/blob/master/docs/file.rst", - ) - - self.pip.repo = "https://github.com/user/repo.github.io" - self.assertEqual( - self.version.get_github_url(docroot="/docs/", filename="file"), - "https://github.com/user/repo.github.io/blob/master/docs/file.rst", - ) - - self.pip.repo = "https://github.com/user/repo.github.io/" - self.assertEqual( - self.version.get_github_url(docroot="/docs/", filename="file"), - "https://github.com/user/repo.github.io/blob/master/docs/file.rst", - ) - - self.pip.repo = "https://github.com/user/repo.git" - self.assertEqual( - self.version.get_github_url(docroot="/docs/", filename="file"), - "https://github.com/user/repo/blob/master/docs/file.rst", - ) - - self.pip.repo = "https://github.com/user/repo.github.io.git" - self.assertEqual( - self.version.get_github_url(docroot="/docs/", filename="file"), - "https://github.com/user/repo.github.io/blob/master/docs/file.rst", - ) - - self.pip.repo = "https://github.com/user/repo.git.git" - self.assertEqual( - self.version.get_github_url(docroot="/docs/", filename="file"), - "https://github.com/user/repo.git/blob/master/docs/file.rst", - ) - - self.pip.repo = "https://github.com/user/repo/" - self.assertEqual( - self.version.get_github_url(docroot="/docs/", filename=""), - "https://github.com/user/repo/blob/master/docs/", - ) - - def test_github_ssh(self): - self.pip.repo = "git@github.com:user/repo.git" - self.assertEqual( - self.version.get_github_url(docroot="/docs/", filename="file"), - "https://github.com/user/repo/blob/master/docs/file.rst", - ) - - self.pip.repo = "git@github.com:user/repo.github.io.git" - self.assertEqual( - self.version.get_github_url(docroot="/docs/", filename="file"), - "https://github.com/user/repo.github.io/blob/master/docs/file.rst", - ) - - def test_gitlab(self): - self.pip.repo = "https://gitlab.com/user/repo" - self.assertEqual( - self.version.get_gitlab_url(docroot="/foo/bar/", filename="file"), - "https://gitlab.com/user/repo/blob/master/foo/bar/file.rst", - ) - - self.pip.repo = "https://gitlab.com/user/repo/" - self.assertEqual( - self.version.get_gitlab_url(docroot="/foo/bar/", filename="file"), - "https://gitlab.com/user/repo/blob/master/foo/bar/file.rst", - ) - - self.pip.repo = "https://gitlab.com/user/repo.gitlab.io" - self.assertEqual( - self.version.get_gitlab_url(docroot="/foo/bar/", filename="file"), - "https://gitlab.com/user/repo.gitlab.io/blob/master/foo/bar/file.rst", - ) - - self.pip.repo = "https://gitlab.com/user/repo.gitlab.io/" - self.assertEqual( - self.version.get_gitlab_url(docroot="/foo/bar/", filename="file"), - "https://gitlab.com/user/repo.gitlab.io/blob/master/foo/bar/file.rst", - ) - - self.pip.repo = "https://gitlab.com/user/repo.git" - self.assertEqual( - self.version.get_gitlab_url(docroot="/foo/bar/", filename="file"), - "https://gitlab.com/user/repo/blob/master/foo/bar/file.rst", - ) - - self.pip.repo = "https://gitlab.com/user/repo.gitlab.io.git" - self.assertEqual( - self.version.get_gitlab_url(docroot="/foo/bar/", filename="file"), - "https://gitlab.com/user/repo.gitlab.io/blob/master/foo/bar/file.rst", - ) - - self.pip.repo = "https://gitlab.com/user/repo.git.git" - self.assertEqual( - self.version.get_gitlab_url(docroot="/foo/bar/", filename="file"), - "https://gitlab.com/user/repo.git/blob/master/foo/bar/file.rst", - ) - - self.pip.repo = "https://gitlab.com/user/repo.git" - self.assertEqual( - self.version.get_gitlab_url(docroot="/foo/bar/", filename=""), - "https://gitlab.com/user/repo/blob/master/foo/bar/", - ) - - def test_gitlab_ssh(self): - self.pip.repo = "git@gitlab.com:user/repo.git" - self.assertEqual( - self.version.get_gitlab_url(docroot="/foo/bar/", filename="file"), - "https://gitlab.com/user/repo/blob/master/foo/bar/file.rst", - ) - - self.pip.repo = "git@gitlab.com:user/repo.gitlab.io.git" - self.assertEqual( - self.version.get_gitlab_url(docroot="/foo/bar/", filename="file"), - "https://gitlab.com/user/repo.gitlab.io/blob/master/foo/bar/file.rst", - ) - - def test_bitbucket(self): - self.pip.repo = "https://bitbucket.org/user/repo" - self.assertEqual( - self.version.get_bitbucket_url(docroot="/foo/bar/", filename="file"), - "https://bitbucket.org/user/repo/src/master/foo/bar/file.rst", - ) - - self.pip.repo = "https://bitbucket.org/user/repo/" - self.assertEqual( - self.version.get_bitbucket_url(docroot="/foo/bar/", filename="file"), - "https://bitbucket.org/user/repo/src/master/foo/bar/file.rst", - ) - - self.pip.repo = "https://bitbucket.org/user/repo.gitbucket.io" - self.assertEqual( - self.version.get_bitbucket_url(docroot="/foo/bar/", filename="file"), - "https://bitbucket.org/user/repo.gitbucket.io/src/master/foo/bar/file.rst", - ) - - self.pip.repo = "https://bitbucket.org/user/repo.gitbucket.io/" - self.assertEqual( - self.version.get_bitbucket_url(docroot="/foo/bar/", filename="file"), - "https://bitbucket.org/user/repo.gitbucket.io/src/master/foo/bar/file.rst", - ) - - self.pip.repo = "https://bitbucket.org/user/repo.git" - self.assertEqual( - self.version.get_bitbucket_url(docroot="/foo/bar/", filename="file"), - "https://bitbucket.org/user/repo/src/master/foo/bar/file.rst", - ) - - self.pip.repo = "https://bitbucket.org/user/repo.gitbucket.io.git" - self.assertEqual( - self.version.get_bitbucket_url(docroot="/foo/bar/", filename="file"), - "https://bitbucket.org/user/repo.gitbucket.io/src/master/foo/bar/file.rst", - ) - - self.pip.repo = "https://bitbucket.org/user/repo.git.git" - self.assertEqual( - self.version.get_bitbucket_url(docroot="/foo/bar/", filename="file"), - "https://bitbucket.org/user/repo.git/src/master/foo/bar/file.rst", - ) - - self.pip.repo = "https://bitbucket.org/user/repo/" - self.assertEqual( - self.version.get_bitbucket_url(docroot="/foo/bar/", filename=""), - "https://bitbucket.org/user/repo/src/master/foo/bar/", - ) - - def test_bitbucket_https(self): - self.pip.repo = "https://user@bitbucket.org/user/repo.git" - self.assertEqual( - self.version.get_bitbucket_url(docroot="/foo/bar/", filename="file"), - "https://bitbucket.org/user/repo/src/master/foo/bar/file.rst", - ) - - self.pip.repo = "https://user@bitbucket.org/user/repo.gitbucket.io.git" - self.assertEqual( - self.version.get_bitbucket_url(docroot="/foo/bar/", filename="file"), - "https://bitbucket.org/user/repo.gitbucket.io/src/master/foo/bar/file.rst", - ) - - def test_bitbucket_ssh(self): - self.pip.repo = "git@bitbucket.org:user/repo.git" - self.assertEqual( - self.version.get_bitbucket_url(docroot="/foo/bar/", filename="file"), - "https://bitbucket.org/user/repo/src/master/foo/bar/file.rst", - ) - - self.pip.repo = "git@bitbucket.org:user/repo.gitbucket.io.git" - self.assertEqual( - self.version.get_bitbucket_url(docroot="/foo/bar/", filename="file"), - "https://bitbucket.org/user/repo.gitbucket.io/src/master/foo/bar/file.rst", - )