Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version sync: restore verbose_name for stable version #11941

Merged
merged 1 commit into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions readthedocs/projects/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
LATEST,
LATEST_VERBOSE_NAME,
STABLE,
STABLE_VERBOSE_NAME,
)
from readthedocs.core.history import ExtraHistoricalRecords
from readthedocs.core.resolver import Resolver
Expand Down Expand Up @@ -1200,6 +1201,7 @@ def update_stable_version(self):
version_updated = (
new_stable.identifier != current_stable.identifier
or new_stable.type != current_stable.type
or current_stable.verbose_name != STABLE_VERBOSE_NAME
)
if version_updated:
log.info(
Expand All @@ -1209,6 +1211,7 @@ def update_stable_version(self):
version_type=new_stable.type,
)
current_stable.identifier = new_stable.identifier
current_stable.verbose_name = STABLE_VERBOSE_NAME
current_stable.type = new_stable.type
current_stable.save()
return new_stable
Expand Down
49 changes: 49 additions & 0 deletions readthedocs/rtd_tests/tests/test_sync_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,55 @@ def test_machine_attr_when_user_define_stable_branch_and_delete_it_new_project(
)
self.assertTrue(current_stable.machine)

def test_restore_machine_stable_verbose_name(self):
"""
The user imports a new project with a branch named ``Stable``, when
syncing the versions, the RTD's ``stable`` is lost (set to machine=False)
and doesn't update automatically anymore, when the branch
is deleted on the user repository, the RTD's ``stable`` is back
(set to machine=True, and with the correct name in lowercase).
"""
self.pip.versions.exclude(slug="master").delete()
current_stable = self.pip.get_stable_version()
assert current_stable is None

custom_stable = get(
Version,
project=self.pip,
identifier="Stable",
verbose_name="Stable",
slug="stable",
type=BRANCH,
machine=False,
active=True,
)
self.pip.update_stable_version()

assert self.pip.get_stable_version() == custom_stable

branches_data = [
{
"identifier": "master",
"verbose_name": "master",
},
{
"identifier": "0.8.3",
"verbose_name": "0.8.3",
},
]

sync_versions_task(
self.pip.pk,
branches_data=branches_data,
tags_data=[],
)

# RTD stable is restored correctly.
current_stable = self.pip.get_stable_version()
assert current_stable.identifier == "0.8.3"
assert current_stable.verbose_name == "stable"
assert current_stable.machine

def test_machine_attr_when_user_define_latest_tag_and_delete_it(self):
"""The user creates a tag named ``latest`` on an existing repo, when
syncing the versions, the RTD's ``latest`` is lost (set to
Expand Down