Skip to content

Commit bdca0bd

Browse files
authored
1 parent 158e3ec commit bdca0bd

File tree

4 files changed

+30
-21
lines changed

4 files changed

+30
-21
lines changed

readthedocs/builds/utils.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@
1212
)
1313
from readthedocs.projects.constants import (
1414
BITBUCKET_REGEXS,
15-
GITHUB_BRAND,
1615
GITHUB_PULL_REQUEST_URL,
1716
GITHUB_REGEXS,
18-
GITLAB_BRAND,
1917
GITLAB_MERGE_REQUEST_URL,
2018
GITLAB_REGEXS,
2119
)
@@ -90,10 +88,10 @@ def external_version_name(build_or_version):
9088

9189
project = build_or_version.project
9290

93-
if project.git_provider_name == GITHUB_BRAND:
91+
if project.is_github_project:
9492
return GITHUB_EXTERNAL_VERSION_NAME
9593

96-
if project.git_provider_name == GITLAB_BRAND:
94+
if project.is_gitlab_project:
9795
return GITLAB_EXTERNAL_VERSION_NAME
9896

9997
# TODO: Add External Version Name for Bitbucket.

readthedocs/projects/models.py

+18-4
Original file line numberDiff line numberDiff line change
@@ -1055,10 +1055,24 @@ def get_git_service_class(self, fallback_to_clone_url=False):
10551055
return service_cls
10561056

10571057
@property
1058-
def git_provider_name(self):
1059-
"""Get the provider name for project. e.g: GitHub, GitLab, Bitbucket."""
1060-
service_class = self.get_git_service_class(fallback_to_clone_url=True)
1061-
return service_class.allauth_provider.name if service_class else None
1058+
def is_github_project(self):
1059+
from readthedocs.oauth.services import GitHubService
1060+
1061+
return self.get_git_service_class(fallback_to_clone_url=True) == GitHubService
1062+
1063+
@property
1064+
def is_gitlab_project(self):
1065+
from readthedocs.oauth.services import GitLabService
1066+
1067+
return self.get_git_service_class(fallback_to_clone_url=True) == GitLabService
1068+
1069+
@property
1070+
def is_bitbucket_project(self):
1071+
from readthedocs.oauth.services import BitbucketService
1072+
1073+
return (
1074+
self.get_git_service_class(fallback_to_clone_url=True) == BitbucketService
1075+
)
10621076

10631077
def find(self, filename, version):
10641078
"""

readthedocs/rtd_tests/tests/test_project.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
from readthedocs.builds.models import Build, Version
2323
from readthedocs.oauth.services import GitHubService, GitLabService
2424
from readthedocs.projects.constants import (
25-
GITHUB_BRAND,
26-
GITLAB_BRAND,
2725
MEDIA_TYPE_EPUB,
2826
MEDIA_TYPE_HTML,
2927
MEDIA_TYPE_HTMLZIP,
@@ -231,10 +229,12 @@ def test_get_latest_build_excludes_external_versions(self):
231229
# Test that External Version is not considered for get_latest_build.
232230
self.assertEqual(self.pip.get_latest_build(), None)
233231

234-
def test_git_provider_name_github(self):
232+
def test_git_provider_github(self):
235233
self.pip.repo = "https://github.com/pypa/pip"
236234
self.pip.save()
237-
self.assertEqual(self.pip.git_provider_name, GITHUB_BRAND)
235+
assert self.pip.is_github_project
236+
assert not self.pip.is_gitlab_project
237+
assert not self.pip.is_bitbucket_project
238238

239239
def test_git_service_class_github(self):
240240
self.pip.repo = "https://github.com/pypa/pip"
@@ -244,10 +244,12 @@ def test_git_service_class_github(self):
244244
self.pip.get_git_service_class(fallback_to_clone_url=True), GitHubService
245245
)
246246

247-
def test_git_provider_name_gitlab(self):
247+
def test_git_provider_gitlab(self):
248248
self.pip.repo = "https://gitlab.com/pypa/pip"
249249
self.pip.save()
250-
self.assertEqual(self.pip.git_provider_name, GITLAB_BRAND)
250+
assert self.pip.is_gitlab_project
251+
assert not self.pip.is_github_project
252+
assert not self.pip.is_bitbucket_project
251253

252254
def test_git_service_class_gitlab(self):
253255
self.pip.repo = "https://gitlab.com/pypa/pip"

readthedocs/vcs_support/backends/git.py

+2-7
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@
1515
)
1616
from readthedocs.config import ALL
1717
from readthedocs.projects.constants import (
18-
GITHUB_BRAND,
1918
GITHUB_PR_PULL_PATTERN,
20-
GITLAB_BRAND,
2119
GITLAB_MR_PULL_PATTERN,
2220
)
2321
from readthedocs.projects.exceptions import RepositoryError
@@ -147,13 +145,10 @@ def get_remote_fetch_refspec(self):
147145
return f"refs/tags/{tag_name}:refs/tags/{tag_name}"
148146

149147
if self.version_type == EXTERNAL:
150-
# TODO: We should be able to resolve this without looking up in oauth registry
151-
git_provider_name = self.project.git_provider_name
152-
153148
# Remote reference for Git providers where pull request builds are supported
154-
if git_provider_name == GITHUB_BRAND:
149+
if self.project.is_github_project:
155150
return GITHUB_PR_PULL_PATTERN.format(id=self.verbose_name)
156-
if self.project.git_provider_name == GITLAB_BRAND:
151+
if self.project.is_gitlab_project:
157152
return GITLAB_MR_PULL_PATTERN.format(id=self.verbose_name)
158153

159154
log.warning(

0 commit comments

Comments
 (0)