Skip to content

Commit c3805d7

Browse files
committed
Build: support cloning private repos with token
Extracted from #11942
1 parent bfb15ca commit c3805d7

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

readthedocs/projects/models.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -980,6 +980,7 @@ def vcs_repo(self, environment, version):
980980
self,
981981
version=version,
982982
environment=environment,
983+
token=self.clone_token,
983984
)
984985
return repo
985986

@@ -1410,6 +1411,24 @@ def get_subproject_candidates(self, user):
14101411
def organization(self):
14111412
return self.organizations.first()
14121413

1414+
@property
1415+
def clone_token(self):
1416+
"""
1417+
Return a token for HTTP Git clone access to the repository.
1418+
1419+
.. note::
1420+
1421+
Only repositories granted acces by a GitHub app installation will return a token.
1422+
"""
1423+
service_class = self.get_git_service_class()
1424+
if not service_class:
1425+
return None
1426+
for service in service_class.for_project(self):
1427+
token = service.get_clone_token(self)
1428+
if token:
1429+
return token
1430+
return None
1431+
14131432

14141433
class APIProject(Project):
14151434
"""
@@ -1426,12 +1445,17 @@ class APIProject(Project):
14261445
"""
14271446

14281447
features = []
1448+
# This is a property in the original model, in order to
1449+
# be able to assign it a value in the constructor, we need to re-declare it
1450+
# as an attribute here.
1451+
clone_token = None
14291452

14301453
class Meta:
14311454
proxy = True
14321455

14331456
def __init__(self, *args, **kwargs):
14341457
self.features = kwargs.pop("features", [])
1458+
self.clone_token = kwargs.pop("clone_token", None)
14351459
environment_variables = kwargs.pop("environment_variables", {})
14361460
ad_free = not kwargs.pop("show_advertising", True)
14371461
# These fields only exist on the API return, not on the model, so we'll

0 commit comments

Comments
 (0)