Skip to content

Commit fd0b406

Browse files
committed
Take preference of tags over branches to get stable version
1 parent 682a7fa commit fd0b406

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

readthedocs/projects/version_handling.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from packaging.version import InvalidVersion, Version
1212

1313
from readthedocs.builds.constants import (
14-
LATEST_VERBOSE_NAME, STABLE_VERBOSE_NAME)
14+
LATEST_VERBOSE_NAME, STABLE_VERBOSE_NAME, TAG)
1515

1616

1717
def get_major(version):
@@ -233,6 +233,12 @@ def determine_stable_version(version_list):
233233
if not comparable.is_prerelease]
234234

235235
if versions:
236+
# We take preference for tags over branches. If we don't find any tag,
237+
# we just return the first branch found.
238+
for version_obj, comparable in versions:
239+
if version_obj.type == TAG:
240+
return version_obj
241+
236242
version_obj, comparable = versions[0]
237243
return version_obj
238244
return None

readthedocs/rtd_tests/tests/test_sync_versions.py

+16-1
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,12 @@ def test_new_tag_update_active(self):
9595
version_9 = Version.objects.get(slug='0.9')
9696
self.assertTrue(version_9.active)
9797

98+
# Version 0.9 becomes the stable version
99+
self.assertEqual(
100+
version_9.identifier,
101+
self.pip.get_stable_version().identifier,
102+
)
103+
98104
def test_new_tag_update_inactive(self):
99105

100106
Version.objects.create(
@@ -132,8 +138,17 @@ def test_new_tag_update_inactive(self):
132138
data=json.dumps(version_post_data),
133139
content_type='application/json',
134140
)
141+
# Version 0.9 becomes the stable version and active
135142
version_9 = Version.objects.get(slug='0.9')
136-
self.assertTrue(version_9.active is False)
143+
self.assertEqual(
144+
version_9.identifier,
145+
self.pip.get_stable_version().identifier,
146+
)
147+
self.assertTrue(version_9.active)
148+
149+
# Version 0.8.3 is still inactive
150+
version_8 = Version.objects.get(slug='0.8.3')
151+
self.assertFalse(version_8.active)
137152

138153

139154
class TestStableVersion(TestCase):

0 commit comments

Comments
 (0)