Skip to content

Commit 741098b

Browse files
committed
Build: adapt sync_repository_task and sync_versions
1 parent 5bfe10e commit 741098b

File tree

2 files changed

+35
-98
lines changed

2 files changed

+35
-98
lines changed

readthedocs/projects/tasks/builds.py

+21-42
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,6 @@ class SyncRepositoryTask(SyncRepositoryMixin, Task):
100100
RepositoryError,
101101
)
102102

103-
# TODO: adapt this task to make it work. It's currently untested.
104-
105103
def before_start(self, task_id, args, kwargs):
106104
log.info('Running task.', name=self.name)
107105

@@ -146,13 +144,12 @@ def after_return(self, status, retval, task_id, args, kwargs, einfo):
146144
clean_build(self.data.version)
147145

148146
def execute(self):
149-
# TODO: initialize the doc builder here
150-
self.data.builder = DocumentationBuilder()
151-
152147
environment = self.data.environment_class(
153148
project=self.data.project,
154149
version=self.data.version,
155-
environment=self.get_vcs_env_vars(),
150+
environment={
151+
"GIT_TERMINAL_PROMPT": "0",
152+
},
156153
# Do not try to save commands on the db because they are just for
157154
# sync repository
158155
record=False,
@@ -163,26 +160,25 @@ def execute(self):
163160
sender=self.data.version,
164161
environment=environment,
165162
)
166-
self.update_versions_from_repository(environment)
167163

168-
def update_versions_from_repository(self, environment):
169-
"""
170-
Update Read the Docs versions from VCS repository.
164+
vcs_repository = self.data.project.vcs_repo(
165+
version=self.data.version.slug,
166+
environment=environment,
167+
verbose_name=self.data.version.verbose_name,
168+
version_type=self.data.version.type,
169+
)
170+
if any(
171+
[
172+
not vcs_repository.supports_lsremote,
173+
not self.data.project.has_feature(Feature.VCS_REMOTE_LISTING),
174+
]
175+
):
176+
log.info("Syncing repository via full clone.")
177+
vcs_repository.update()
178+
else:
179+
log.info("Syncing repository via remote listing.")
171180

172-
Depending if the VCS backend supports remote listing, we just list its branches/tags
173-
remotely or we do a full clone and local listing of branches/tags.
174-
"""
175-
version_repo = self.get_vcs_repo(environment)
176-
if any([
177-
not version_repo.supports_lsremote,
178-
not self.data.project.has_feature(Feature.VCS_REMOTE_LISTING),
179-
]):
180-
log.info('Syncing repository via full clone.')
181-
self.sync_repo(environment)
182-
else:
183-
log.info('Syncing repository via remote listing.')
184-
# TODO: needs to figure it out how to do this `sync_versions` here
185-
self.sync_versions(version_repo)
181+
self.sync_versions(vcs_repository)
186182

187183

188184
@app.task(
@@ -559,10 +555,7 @@ def execute(self):
559555

560556
# Sync tags/branches from VCS repository into Read the Docs' `Version`
561557
# objects in the database
562-
#
563-
# FIXME: review why I had to disable this for now.
564-
log.error("Not triggering `sync_versions` because it's broken")
565-
# self.sync_versions()
558+
self.sync_versions(self.data.builder.vcs_repository)
566559

567560
self.update_build(state=BUILD_STATE_INSTALLING)
568561
self.data.builder.setup_environment()
@@ -597,20 +590,6 @@ def get_build(build_pk):
597590
for key, val in build.items() if key not in private_keys
598591
}
599592

600-
# TODO: can we name this `clonning`
601-
# def setup_vcs(self, environment):
602-
# """
603-
# Update the checkout of the repo to make sure it's the latest.
604-
605-
# This also syncs versions in the DB.
606-
# """
607-
# self.update_build(state=BUILD_STATE_CLONING)
608-
# self.sync_repo(environment)
609-
610-
# commit = self.data.build_commit or self.get_vcs_repo(environment).commit
611-
# if commit:
612-
# self.data.build['commit'] = commit
613-
614593
# NOTE: this can be just updated on `self.data.build['']` and sent once the
615594
# build has finished to reduce API calls.
616595
def set_valid_clone(self):

readthedocs/projects/tasks/mixins.py

+14-56
Original file line numberDiff line numberDiff line change
@@ -44,48 +44,7 @@ def get_version(version_pk):
4444
version_data = api_v2.version(version_pk).get()
4545
return APIVersion(**version_data)
4646

47-
# def get_vcs_repo(self, environment):
48-
# """
49-
# Get the VCS object of the current project.
50-
51-
# All VCS commands will be executed using `environment`.
52-
# """
53-
# version_repo = self.data.project.vcs_repo(
54-
# version=self.data.version.slug,
55-
# environment=environment,
56-
# verbose_name=self.data.version.verbose_name,
57-
# version_type=self.data.version.type
58-
# )
59-
# return version_repo
60-
61-
# def sync_repo(self, environment):
62-
# """Update the project's repository and hit ``sync_versions`` API."""
63-
# # Make Dirs
64-
# if not os.path.exists(self.data.project.doc_path):
65-
# os.makedirs(self.data.project.doc_path)
66-
67-
# if not self.data.project.vcs_class():
68-
# raise RepositoryError(
69-
# _('Repository type "{repo_type}" unknown').format(
70-
# repo_type=self.data.project.repo_type,
71-
# ),
72-
# )
73-
74-
# # Get the actual code on disk
75-
# log.info(
76-
# 'Checking out version.',
77-
# version_identifier=self.data.version.identifier,
78-
# )
79-
# version_repo = self.get_vcs_repo(environment)
80-
81-
# self.data.builder.checkout()
82-
# # version_repo.update()
83-
84-
# self.sync_versions(version_repo)
85-
# identifier = self.data.build_commit or self.data.version.identifier
86-
# version_repo.checkout(identifier)
87-
88-
def sync_versions(self, version_repo):
47+
def sync_versions(self, vcs_repository):
8948
"""
9049
Update tags/branches via a Celery task.
9150
@@ -97,31 +56,29 @@ def sync_versions(self, version_repo):
9756
# NOTE: `sync_versions` should receive `tags` and `branches` already
9857
# and just validate them trigger the task. All the other logic should
9958
# be done by the DocumentationBuilder or the VCS backend. We should not
100-
# check this here and do not depend on ``version_repo``.
59+
# check this here and do not depend on ``vcs_repository``.
10160

10261
tags = None
10362
branches = None
10463
if (
105-
version_repo.supports_lsremote and
106-
not version_repo.repo_exists() and
107-
self.data.project.has_feature(Feature.VCS_REMOTE_LISTING)
64+
vcs_repository.supports_lsremote
65+
and not vcs_repository.repo_exists()
66+
and self.data.project.has_feature(Feature.VCS_REMOTE_LISTING)
10867
):
10968
# Do not use ``ls-remote`` if the VCS does not support it or if we
11069
# have already cloned the repository locally. The latter happens
11170
# when triggering a normal build.
112-
branches, tags = version_repo.lsremote
113-
log.info('Remote versions.', branches=branches, tags=tags)
71+
branches, tags = vcs_repository.lsremote
11472

11573
branches_data = []
11674
tags_data = []
11775

118-
if (
119-
version_repo.supports_tags and
120-
not self.data.project.has_feature(Feature.SKIP_SYNC_TAGS)
76+
if vcs_repository.supports_tags and not self.data.project.has_feature(
77+
Feature.SKIP_SYNC_TAGS
12178
):
12279
# Will be an empty list if we called lsremote and had no tags returned
12380
if tags is None:
124-
tags = version_repo.tags
81+
tags = vcs_repository.tags
12582
tags_data = [
12683
{
12784
'identifier': v.identifier,
@@ -130,13 +87,12 @@ def sync_versions(self, version_repo):
13087
for v in tags
13188
]
13289

133-
if (
134-
version_repo.supports_branches and
135-
not self.data.project.has_feature(Feature.SKIP_SYNC_BRANCHES)
90+
if vcs_repository.supports_branches and not self.data.project.has_feature(
91+
Feature.SKIP_SYNC_BRANCHES
13692
):
13793
# Will be an empty list if we called lsremote and had no branches returned
13894
if branches is None:
139-
branches = version_repo.branches
95+
branches = vcs_repository.branches
14096
branches_data = [
14197
{
14298
'identifier': v.identifier,
@@ -145,6 +101,8 @@ def sync_versions(self, version_repo):
145101
for v in branches
146102
]
147103

104+
log.debug("Synchronizing versions.", branches=branches, tags=tags)
105+
148106
self.validate_duplicate_reserved_versions(
149107
tags_data=tags_data,
150108
branches_data=branches_data,

0 commit comments

Comments
 (0)