Skip to content

Commit e5c3714

Browse files
authored
Version sync: restore verbose_name for stable version (#11941)
Closes #11939 This also discovered another problem, we are using the verbose name to check for latest/stable, but we should use the slug https://github.com/readthedocs/readthedocs.org/blob/10d9ef95736b3106b4c5c551df57dda8ed1000e2/readthedocs/vcs_support/backends/git.py#L135-L145 Will try to fix that in another PR, as we need to pass the slug down...
1 parent 5f3f199 commit e5c3714

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

readthedocs/projects/models.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
LATEST,
3030
LATEST_VERBOSE_NAME,
3131
STABLE,
32+
STABLE_VERBOSE_NAME,
3233
)
3334
from readthedocs.core.history import ExtraHistoricalRecords
3435
from readthedocs.core.resolver import Resolver
@@ -1200,6 +1201,7 @@ def update_stable_version(self):
12001201
version_updated = (
12011202
new_stable.identifier != current_stable.identifier
12021203
or new_stable.type != current_stable.type
1204+
or current_stable.verbose_name != STABLE_VERBOSE_NAME
12031205
)
12041206
if version_updated:
12051207
log.info(
@@ -1209,6 +1211,7 @@ def update_stable_version(self):
12091211
version_type=new_stable.type,
12101212
)
12111213
current_stable.identifier = new_stable.identifier
1214+
current_stable.verbose_name = STABLE_VERBOSE_NAME
12121215
current_stable.type = new_stable.type
12131216
current_stable.save()
12141217
return new_stable

readthedocs/rtd_tests/tests/test_sync_versions.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,55 @@ def test_machine_attr_when_user_define_stable_branch_and_delete_it_new_project(
670670
)
671671
self.assertTrue(current_stable.machine)
672672

673+
def test_restore_machine_stable_verbose_name(self):
674+
"""
675+
The user imports a new project with a branch named ``Stable``, when
676+
syncing the versions, the RTD's ``stable`` is lost (set to machine=False)
677+
and doesn't update automatically anymore, when the branch
678+
is deleted on the user repository, the RTD's ``stable`` is back
679+
(set to machine=True, and with the correct name in lowercase).
680+
"""
681+
self.pip.versions.exclude(slug="master").delete()
682+
current_stable = self.pip.get_stable_version()
683+
assert current_stable is None
684+
685+
custom_stable = get(
686+
Version,
687+
project=self.pip,
688+
identifier="Stable",
689+
verbose_name="Stable",
690+
slug="stable",
691+
type=BRANCH,
692+
machine=False,
693+
active=True,
694+
)
695+
self.pip.update_stable_version()
696+
697+
assert self.pip.get_stable_version() == custom_stable
698+
699+
branches_data = [
700+
{
701+
"identifier": "master",
702+
"verbose_name": "master",
703+
},
704+
{
705+
"identifier": "0.8.3",
706+
"verbose_name": "0.8.3",
707+
},
708+
]
709+
710+
sync_versions_task(
711+
self.pip.pk,
712+
branches_data=branches_data,
713+
tags_data=[],
714+
)
715+
716+
# RTD stable is restored correctly.
717+
current_stable = self.pip.get_stable_version()
718+
assert current_stable.identifier == "0.8.3"
719+
assert current_stable.verbose_name == "stable"
720+
assert current_stable.machine
721+
673722
def test_machine_attr_when_user_define_latest_tag_and_delete_it(self):
674723
"""The user creates a tag named ``latest`` on an existing repo, when
675724
syncing the versions, the RTD's ``latest`` is lost (set to

0 commit comments

Comments
 (0)