Skip to content

Commit

Permalink
Take preference of tags over branches to get stable version
Browse files Browse the repository at this point in the history
  • Loading branch information
humitos committed Nov 29, 2017
1 parent 682a7fa commit fd0b406
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
8 changes: 7 additions & 1 deletion readthedocs/projects/version_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from packaging.version import InvalidVersion, Version

from readthedocs.builds.constants import (
LATEST_VERBOSE_NAME, STABLE_VERBOSE_NAME)
LATEST_VERBOSE_NAME, STABLE_VERBOSE_NAME, TAG)


def get_major(version):
Expand Down Expand Up @@ -233,6 +233,12 @@ def determine_stable_version(version_list):
if not comparable.is_prerelease]

if versions:
# We take preference for tags over branches. If we don't find any tag,
# we just return the first branch found.
for version_obj, comparable in versions:
if version_obj.type == TAG:
return version_obj

version_obj, comparable = versions[0]
return version_obj
return None
17 changes: 16 additions & 1 deletion readthedocs/rtd_tests/tests/test_sync_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ def test_new_tag_update_active(self):
version_9 = Version.objects.get(slug='0.9')
self.assertTrue(version_9.active)

# Version 0.9 becomes the stable version
self.assertEqual(
version_9.identifier,
self.pip.get_stable_version().identifier,
)

def test_new_tag_update_inactive(self):

Version.objects.create(
Expand Down Expand Up @@ -132,8 +138,17 @@ def test_new_tag_update_inactive(self):
data=json.dumps(version_post_data),
content_type='application/json',
)
# Version 0.9 becomes the stable version and active
version_9 = Version.objects.get(slug='0.9')
self.assertTrue(version_9.active is False)
self.assertEqual(
version_9.identifier,
self.pip.get_stable_version().identifier,
)
self.assertTrue(version_9.active)

# Version 0.8.3 is still inactive
version_8 = Version.objects.get(slug='0.8.3')
self.assertFalse(version_8.active)


class TestStableVersion(TestCase):
Expand Down

0 comments on commit fd0b406

Please sign in to comment.