Skip to content

Commit

Permalink
Try a list of keys to find the tag value. (ansible#1954)
Browse files Browse the repository at this point in the history
* Try a list of keys to find the tag value.
* Skip sorting on problematic versions.

No-Issue

Signed-off-by: James Tanner <[email protected]>
  • Loading branch information
jctanner authored Oct 26, 2023
1 parent 7fe4e1c commit b8d6a6c
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion galaxy_ng/app/api/v1/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,31 @@ 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()))

def get_version_tag(version):
"""
Necessary until we normalize all versions.
"""
if version.get('version'):
return version['version']
elif version.get('tag'):
return version['tag']
elif version.get('name'):
return version['name']
return ''

try:
sorted_versions = sorted(
versions,
key=lambda x: LooseVersion(
get_version_tag(x).lower()
)
)
except TypeError:
# we did our best, it'll have to be unsorted.
return versions
except AttributeError:
# we did our best, it'll have to be unsorted.
return versions

return sorted_versions

0 comments on commit b8d6a6c

Please sign in to comment.