Skip to content

Project: don't depend on the brand name #12008

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
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
6 changes: 2 additions & 4 deletions readthedocs/builds/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@
)
from readthedocs.projects.constants import (
BITBUCKET_REGEXS,
GITHUB_BRAND,
GITHUB_PULL_REQUEST_URL,
GITHUB_REGEXS,
GITLAB_BRAND,
GITLAB_MERGE_REQUEST_URL,
GITLAB_REGEXS,
)
Expand Down Expand Up @@ -90,10 +88,10 @@ def external_version_name(build_or_version):

project = build_or_version.project

if project.git_provider_name == GITHUB_BRAND:
if project.is_github_project:
return GITHUB_EXTERNAL_VERSION_NAME

if project.git_provider_name == GITLAB_BRAND:
if project.is_gitlab_project:
return GITLAB_EXTERNAL_VERSION_NAME

# TODO: Add External Version Name for Bitbucket.
Expand Down
22 changes: 18 additions & 4 deletions readthedocs/projects/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1055,10 +1055,24 @@ def get_git_service_class(self, fallback_to_clone_url=False):
return service_cls

@property
def git_provider_name(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you grepped all the repositories to check if we are using it in other places? Just in case.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nothing in .com and ext.

"""Get the provider name for project. e.g: GitHub, GitLab, Bitbucket."""
service_class = self.get_git_service_class(fallback_to_clone_url=True)
return service_class.allauth_provider.name if service_class else None
def is_github_project(self):
from readthedocs.oauth.services import GitHubService

return self.get_git_service_class(fallback_to_clone_url=True) == GitHubService
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be in [GitHubService, GitHubAppService] with #11942


@property
def is_gitlab_project(self):
from readthedocs.oauth.services import GitLabService

return self.get_git_service_class(fallback_to_clone_url=True) == GitLabService

@property
def is_bitbucket_project(self):
from readthedocs.oauth.services import BitbucketService

return (
self.get_git_service_class(fallback_to_clone_url=True) == BitbucketService
)

def find(self, filename, version):
"""
Expand Down
14 changes: 8 additions & 6 deletions readthedocs/rtd_tests/tests/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
from readthedocs.builds.models import Build, Version
from readthedocs.oauth.services import GitHubService, GitLabService
from readthedocs.projects.constants import (
GITHUB_BRAND,
GITLAB_BRAND,
MEDIA_TYPE_EPUB,
MEDIA_TYPE_HTML,
MEDIA_TYPE_HTMLZIP,
Expand Down Expand Up @@ -231,10 +229,12 @@ def test_get_latest_build_excludes_external_versions(self):
# Test that External Version is not considered for get_latest_build.
self.assertEqual(self.pip.get_latest_build(), None)

def test_git_provider_name_github(self):
def test_git_provider_github(self):
self.pip.repo = "https://github.com/pypa/pip"
self.pip.save()
self.assertEqual(self.pip.git_provider_name, GITHUB_BRAND)
assert self.pip.is_github_project
assert not self.pip.is_gitlab_project
assert not self.pip.is_bitbucket_project

def test_git_service_class_github(self):
self.pip.repo = "https://github.com/pypa/pip"
Expand All @@ -244,10 +244,12 @@ def test_git_service_class_github(self):
self.pip.get_git_service_class(fallback_to_clone_url=True), GitHubService
)

def test_git_provider_name_gitlab(self):
def test_git_provider_gitlab(self):
self.pip.repo = "https://gitlab.com/pypa/pip"
self.pip.save()
self.assertEqual(self.pip.git_provider_name, GITLAB_BRAND)
assert self.pip.is_gitlab_project
assert not self.pip.is_github_project
assert not self.pip.is_bitbucket_project

def test_git_service_class_gitlab(self):
self.pip.repo = "https://gitlab.com/pypa/pip"
Expand Down
9 changes: 2 additions & 7 deletions readthedocs/vcs_support/backends/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
)
from readthedocs.config import ALL
from readthedocs.projects.constants import (
GITHUB_BRAND,
GITHUB_PR_PULL_PATTERN,
GITLAB_BRAND,
GITLAB_MR_PULL_PATTERN,
)
from readthedocs.projects.exceptions import RepositoryError
Expand Down Expand Up @@ -147,13 +145,10 @@ def get_remote_fetch_refspec(self):
return f"refs/tags/{tag_name}:refs/tags/{tag_name}"

if self.version_type == EXTERNAL:
# TODO: We should be able to resolve this without looking up in oauth registry
git_provider_name = self.project.git_provider_name

# Remote reference for Git providers where pull request builds are supported
if git_provider_name == GITHUB_BRAND:
if self.project.is_github_project:
return GITHUB_PR_PULL_PATTERN.format(id=self.verbose_name)
if self.project.git_provider_name == GITLAB_BRAND:
if self.project.is_gitlab_project:
return GITLAB_MR_PULL_PATTERN.format(id=self.verbose_name)

log.warning(
Expand Down