Skip to content

Versions: keep type of version in sync with the project #10606

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

Merged
merged 6 commits into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 4 additions & 2 deletions readthedocs/api/v2/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
log = structlog.get_logger(__name__)


def sync_versions_to_db(project, versions, type): # pylint: disable=redefined-builtin
def sync_versions_to_db(project, versions, type):
"""
Update the database with the current versions from the repository.

Expand Down Expand Up @@ -117,6 +117,8 @@ def sync_versions_to_db(project, versions, type): # pylint: disable=redefined-b
latest_version.machine = True
latest_version.identifier = project.get_default_branch()
latest_version.verbose_name = LATEST_VERBOSE_NAME
# The machine created latest version always points to a branch.
latest_version.type = BRANCH
latest_version.save()
if added:
log.info(
Expand Down Expand Up @@ -156,7 +158,7 @@ def _create_versions(project, type, versions):

def _set_or_create_version(project, slug, version_id, verbose_name, type_):
"""Search or create a version and set its machine attribute to false."""
version = (project.versions.filter(slug=slug).first())
version = project.versions.filter(slug=slug).first()
if version:
version.identifier = version_id
version.machine = False
Expand Down
15 changes: 8 additions & 7 deletions readthedocs/projects/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1199,18 +1199,19 @@ def update_stable_version(self):
new_stable = determine_stable_version(versions)
if new_stable:
if current_stable:
identifier_updated = (
version_updated = (
new_stable.identifier != current_stable.identifier
or new_stable.type != current_stable.type
)
if identifier_updated:
if version_updated:
log.info(
'Update stable version: %(project)s:%(version)s',
{
'project': self.slug,
'version': new_stable.identifier,
}
"Stable version updated.",
project_slug=self.slug,
version_identifier=new_stable.identifier,
version_type=new_stable.type,
)
current_stable.identifier = new_stable.identifier
current_stable.type = new_stable.type
current_stable.save()
return new_stable
else:
Expand Down