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

Add reverse sort in versions on output json #89

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
6 changes: 3 additions & 3 deletions blueos_repository/consolidate.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,9 @@ async def run(self) -> None:
await asyncio.gather(*(ext.inflate() for ext in extensions))

consolidated_data = [
RepositoryEntry(**dataclasses.asdict(ext.metadata), versions=ext.versions)
RepositoryEntry(**dataclasses.asdict(ext.metadata), versions=ext.sorted_versions)
for ext in extensions
if ext.versions
if ext.sorted_versions
]

try:
Expand All @@ -141,7 +141,7 @@ async def run(self) -> None:
print(f"Unable to fetch final docker rate limit, error: {error}")

with open(MANIFEST_FILE, "w", encoding="utf-8") as manifest_file:
manifest_file.write(json.dumps(consolidated_data, indent=4, sort_keys=True, cls=EnhancedJSONEncoder))
manifest_file.write(json.dumps(consolidated_data, indent=4, cls=EnhancedJSONEncoder))

Logger.dump(MANIFEST_LOG)

Expand Down
11 changes: 11 additions & 0 deletions blueos_repository/extension/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,17 @@ def __init__(self, metadata: ExtensionMetadata) -> None:
self.hub: DockerHub = DockerHub(metadata.docker)
self.registry: DockerRegistry = DockerRegistry(metadata.docker)

@property
def sorted_versions(self) -> Dict[str, ExtensionVersion]:
"""
Returns the versions reverse sorted by semver.

Returns:
Dict[str, ExtensionVersion]: Sorted versions.
"""

return dict(sorted(self.versions.items(), key=lambda item: valid_semver(item[0]), reverse=True)) # type: ignore

@staticmethod
async def fetch_readme(url: str) -> str:
if not url.startswith("http"):
Expand Down
Loading