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

Fix legacy role view version sorting and validation #1953

Merged
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
5 changes: 4 additions & 1 deletion galaxy_ng/app/api/v1/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from galaxy_ng.app.api.v1.models import LegacyNamespace
from galaxy_ng.app.api.v1.models import LegacyRole
from galaxy_ng.app.api.v1.models import LegacyRoleDownloadCount
from galaxy_ng.app.api.v1.utils import sort_versions


class LegacyNamespacesSerializer(serializers.ModelSerializer):
Expand Down Expand Up @@ -296,7 +297,8 @@ def get_summary_fields(self, obj):

versions = obj.full_metadata.get('versions', [])
if versions:
# the versions data should have been sorted at sync or import time
# FIXME - we can't assume they're all sorted yet
versions = sort_versions(versions)
versions = versions[::-1]
if len(versions) > 10:
versions = versions[:11]
Expand Down Expand Up @@ -449,6 +451,7 @@ def get_previous_link(self, obj):
def get_results(self, obj):

versions = obj.full_metadata.get('versions', [])
versions = sort_versions(versions)

results = []

Expand Down
23 changes: 3 additions & 20 deletions galaxy_ng/app/api/v1/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import tempfile
import uuid

import semantic_version

from django.db import transaction

from ansible.module_utils.compat.version import LooseVersion
Expand All @@ -24,22 +22,15 @@
from galaxy_ng.app.api.v1.models import LegacyNamespace
from galaxy_ng.app.api.v1.models import LegacyRole
from galaxy_ng.app.api.v1.models import LegacyRoleDownloadCount
from galaxy_ng.app.api.v1.utils import sort_versions
from galaxy_ng.app.api.v1.utils import parse_version_tag

from git import Repo


logger = logging.getLogger(__name__)


def parse_version_tag(value):
value = str(value)
if not value:
raise ValueError('Empty version value')
if value[0].lower() == 'v':
value = value[1:]
return semantic_version.Version(value)


def find_real_role(github_user, github_repo):
"""
Given the github_user and github_repo attributes, find a matching
Expand Down Expand Up @@ -173,14 +164,6 @@ def do_git_checkout(clone_url, checkout_path, github_reference):
return gitrepo, github_reference, last_commit


def sort_versions(versions):
"""
Use ansible-core's LooseVersion util to sort the versions.
"""
sorted_versions = sorted(versions, key=lambda x: LooseVersion(x['tag'].lower()))
return sorted_versions


def normalize_versions(versions):

# convert old integer based IDs to uuid
Expand All @@ -206,7 +189,7 @@ def normalize_versions(versions):
versions.remove(version)
continue
lver = LooseVersion(version['tag'].lower())
if not all(isinstance(x, int) for x in lver.version):
if not any(isinstance(x, int) for x in lver.version):
versions.remove(version)

return versions
Expand Down
19 changes: 19 additions & 0 deletions galaxy_ng/app/api/v1/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import semantic_version
from ansible.module_utils.compat.version import LooseVersion


def parse_version_tag(value):
value = str(value)
if not value:
raise ValueError('Empty version value')
if value[0].lower() == 'v':
value = value[1:]
return semantic_version.Version(value)


def sort_versions(versions):
"""
Use ansible-core's LooseVersion util to sort the version dicts by the tag key.
"""
sorted_versions = sorted(versions, key=lambda x: LooseVersion(x['tag'].lower()))
return sorted_versions
Loading