Use default branch instead of LATEST
"""Views pertaining to builds."""
-from __future__ import absolute_import
+from __future__ import (
+ absolute_import,
+ division,
+ print_function,
+ unicode_literals,
+)
+
import json
+import logging
import re
from django.http import HttpResponse, HttpResponseNotFound
from django.shortcuts import redirect
from django.views.decorators.csrf import csrf_exempt
-from readthedocs.core.utils import trigger_build
from readthedocs.builds.constants import LATEST
+from readthedocs.core.utils import trigger_build
from readthedocs.projects import constants
-from readthedocs.projects.models import Project, Feature
+from readthedocs.projects.models import Feature, Project
from readthedocs.projects.tasks import sync_repository_task
-import logging
-
log = logging.getLogger(__name__)
@@ -82,18 +87,24 @@ def sync_versions(project):
This doesn't register a new build,
but clones the repo and syncs the versions.
Due that `sync_repository_task` is bound to a version,
- we always pass the latest version.
+ we always pass the default version.
- :returns: The version that was used to trigger the clone (usually latest).
+ :returns: The version slug that was used to trigger the clone.
+ :rtype: str
"""
try:
- version_slug = LATEST
- version = project.versions.get(slug=version_slug)
+ version_identifier = project.get_default_branch()
+ version = (
+ project.versions
+ .filter(identifier=version_identifier)
+ .first()
+ )
+ if not version:
+ log.info('Unable to sync from %s version', version_identifier)
+ return None
sync_repository_task.delay(version.pk)
return version.slug
- except Project.DoesNotExist:
- log.info('Unable to sync from %s version', version_slug)
- except Exception as e:
+ except Exception:
log.exception('Unknown sync versions exception')
return None
