Skip to content

Addons: default to semver for sorting versions #11686

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 1 commit into from
Oct 15, 2024
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
85 changes: 85 additions & 0 deletions readthedocs/projects/migrations/0127_default_to_semver.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# Generated by Django 4.2.16 on 2024-10-15 16:07
from django.db import migrations, models
from django_safemigrate import Safe


class Migration(migrations.Migration):
safe = Safe.always
dependencies = [
("projects", "0126_alter_remote_repository_description"),
]

operations = [
migrations.AlterField(
model_name="addonsconfig",
name="flyout_sorting",
field=models.CharField(
choices=[
("alphabetically", "Alphabetically"),
("semver-readthedocs-compatible", "SemVer (Read the Docs)"),
("python-packaging", "Python Packaging (PEP 440 and PEP 425)"),
("calver", "CalVer (YYYY.0M.0M)"),
("custom-pattern", "Define your own pattern"),
],
default="semver-readthedocs-compatible",
max_length=64,
verbose_name="Sorting of versions",
),
),
migrations.AlterField(
model_name="addonsconfig",
name="flyout_sorting_custom_pattern",
field=models.CharField(
blank=True,
default=None,
help_text='Sorting pattern supported by BumpVer (<a href="https://github.com/mbarkhau/bumpver#pattern-examples">See examples</a>)',
max_length=32,
null=True,
verbose_name="Custom version sorting pattern",
),
),
migrations.AlterField(
model_name="addonsconfig",
name="flyout_sorting_latest_stable_at_beginning",
field=models.BooleanField(
default=True,
verbose_name="Show <code>latest</code> and <code>stable</code> at the beginning",
),
),
migrations.AlterField(
model_name="historicaladdonsconfig",
name="flyout_sorting",
field=models.CharField(
choices=[
("alphabetically", "Alphabetically"),
("semver-readthedocs-compatible", "SemVer (Read the Docs)"),
("python-packaging", "Python Packaging (PEP 440 and PEP 425)"),
("calver", "CalVer (YYYY.0M.0M)"),
("custom-pattern", "Define your own pattern"),
],
default="semver-readthedocs-compatible",
max_length=64,
verbose_name="Sorting of versions",
),
),
migrations.AlterField(
model_name="historicaladdonsconfig",
name="flyout_sorting_custom_pattern",
field=models.CharField(
blank=True,
default=None,
help_text='Sorting pattern supported by BumpVer (<a href="https://github.com/mbarkhau/bumpver#pattern-examples">See examples</a>)',
max_length=32,
null=True,
verbose_name="Custom version sorting pattern",
),
),
migrations.AlterField(
model_name="historicaladdonsconfig",
name="flyout_sorting_latest_stable_at_beginning",
field=models.BooleanField(
default=True,
verbose_name="Show <code>latest</code> and <code>stable</code> at the beginning",
),
),
]
10 changes: 7 additions & 3 deletions readthedocs/projects/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@
from readthedocs.vcs_support.backends import backend_cls

from .constants import (
ADDONS_FLYOUT_SORTING_ALPHABETICALLY,
ADDONS_FLYOUT_SORTING_CHOICES,
ADDONS_FLYOUT_SORTING_SEMVER_READTHEDOCS_COMPATIBLE,
DOWNLOADABLE_MEDIA_TYPES,
MEDIA_TYPES,
MULTIPLE_VERSIONS_WITH_TRANSLATIONS,
Expand Down Expand Up @@ -187,21 +187,25 @@ class AddonsConfig(TimeStampedModel):
# Flyout
flyout_enabled = models.BooleanField(default=True)
flyout_sorting = models.CharField(
verbose_name=_("Sorting of versions"),
choices=ADDONS_FLYOUT_SORTING_CHOICES,
default=ADDONS_FLYOUT_SORTING_ALPHABETICALLY,
default=ADDONS_FLYOUT_SORTING_SEMVER_READTHEDOCS_COMPATIBLE,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't update existing projects, right? I wonder if we should migrate it for them 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, not sure if we have a good way to tell apart users that set this option explicitly and who didn't (maybe check if created and modified are equal?)

max_length=64,
)
flyout_sorting_custom_pattern = models.CharField(
max_length=32,
default=None,
null=True,
blank=True,
verbose_name=_("Custom version sorting pattern"),
help_text="Sorting pattern supported by BumpVer "
'(<a href="https://github.com/mbarkhau/bumpver#pattern-examples">See examples</a>)',
)
flyout_sorting_latest_stable_at_beginning = models.BooleanField(
verbose_name=_(
"Show <code>latest</code> and <code>stable</code> at the beginning"
),
default=True,
help_text="Show <code>latest</code> and <code>stable</code> at the beginning",
)

# Hotkeys
Expand Down
8 changes: 4 additions & 4 deletions readthedocs/proxito/tests/test_hosting.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,15 +575,15 @@ def test_flyout_subproject_urls(self):
r.json()["versions"]["active"][0]["urls"]["documentation"]
== "https://project.dev.readthedocs.io/projects/subproject/en/latest/"
)
assert r.json()["versions"]["active"][1]["slug"] == "v1"
assert r.json()["versions"]["active"][1]["slug"] == "v2.3"
assert (
r.json()["versions"]["active"][1]["urls"]["documentation"]
== "https://project.dev.readthedocs.io/projects/subproject/en/v1/"
== "https://project.dev.readthedocs.io/projects/subproject/en/v2.3/"
)
assert r.json()["versions"]["active"][2]["slug"] == "v2.3"
assert r.json()["versions"]["active"][2]["slug"] == "v1"
assert (
r.json()["versions"]["active"][2]["urls"]["documentation"]
== "https://project.dev.readthedocs.io/projects/subproject/en/v2.3/"
== "https://project.dev.readthedocs.io/projects/subproject/en/v1/"
)

assert len(r.json()["projects"]["translations"]) == 1
Expand Down
1 change: 1 addition & 0 deletions readthedocs/proxito/views/hosting.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ def _v1(self, project, version, build, filename, url, request):
version.verbose_name,
repo_type=project.repo_type,
),
reverse=True,
)
elif (
project.addons.flyout_sorting == ADDONS_FLYOUT_SORTING_PYTHON_PACKAGING
Expand Down