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 bug in retrieving available versions #31

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions paxexpress_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ def version():

cli.add_typer(self_cli, name="self")


def main():
cli()


if __name__ == "__main__":
cli()
11 changes: 6 additions & 5 deletions paxexpress_cli/files/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import typer
from paxexpress_cli.packages import core as packages_core
from paxexpress_cli.repositories import core as repositories
from paxexpress_cli.versions import core as versions_core


def get_versions_file(
Expand Down Expand Up @@ -54,8 +55,8 @@ def get_package_file(
subject=subject, repo=repo
)
if not version:
version = select_from_available_versions(
subject=subject, repo=repo, package=package, filename=None
version = versions_core.select_from_available_versions(
subject=subject, repo=repo, package=package
)
url = get_url(f"/packages/{subject}/{repo}/{package}/versions/{version}/files")
params = {}
Expand Down Expand Up @@ -139,7 +140,7 @@ def file_download(
subject=subject, repo=repo
)
if not version:
version = select_from_available_versions(
version = select_from_available_versions_by_filename(
subject=subject, repo=repo, package=package, filename=file_name
)

Expand All @@ -158,7 +159,7 @@ def file_download(
print_error(response.text)


def select_from_available_versions(
def select_from_available_versions_by_filename(
subject: str, repo: str, package: str, filename: Optional[str]
) -> Optional[str]:
files = get_versions_file(
Expand Down Expand Up @@ -223,7 +224,7 @@ def delete_file(
subject=username, repo=repo
)
if not version:
version = select_from_available_versions(
version = select_from_available_versions_by_filename(
subject=username, repo=repo, package=package, filename=filename
)

Expand Down
15 changes: 15 additions & 0 deletions paxexpress_cli/versions/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
delete_version,
update_version,
get_version_for_file,
get_packages_available_versions,
)

version_cli = Typer(name="version")
Expand Down Expand Up @@ -53,6 +54,20 @@ def get(
)


@version_cli.command(name="available", help="Get available version")
def get_available(
subject: str = Option(..., "-s", "--subject"),
repo: str = Option(None, "-r", "--repo"),
package: str = Option(None, "-p", "--package"),
):

get_packages_available_versions(
subject=subject,
repo=repo,
package=package,
)


@version_cli.command(name="create", help="Create a version")
def create(
repo: str = Option(None, "-r", "--repo"),
Expand Down
58 changes: 51 additions & 7 deletions paxexpress_cli/versions/core.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from paxexpress_cli.utils import print_error, select_available_options
from typing import Optional
import httpx
from .models import (
VersionGetAvailableVersionResponseModel,
VersionModel,
VersionCreateBodyModel,
VersionUpdateBodyModel,
Expand All @@ -15,7 +17,28 @@
from ..authentication.core import get_auth_header_and_username
from paxexpress_cli.repositories import core as repositories_core
from paxexpress_cli.packages import core as packages_core
from paxexpress_cli.files import core as files_core


def select_from_available_versions(
subject: str, repo: str, package: str
) -> Optional[str]:
from paxexpress_cli.versions.core import get_packages_available_versions
includeamin marked this conversation as resolved.
Show resolved Hide resolved

versions = get_packages_available_versions(
subject=subject, package=package, repo=repo, is_internal=True
)
if not versions:
print_error("No versions have been created!")
exit(1)
selected_version = select_available_options(
name="version",
message="Select the version",
choices=[item["name"] for item in versions],
)
if not selected_version:
print_error("No version has been selected!")
exit(1)
return selected_version["version"]


def get_latest(
Expand All @@ -38,6 +61,25 @@ def get_latest(
return response_handler(response=response, return_model=VersionModel)


def get_packages_available_versions(
subject: str, repo: Optional[str], package: Optional[str], is_internal: bool = False
):
if not repo:
repo = repositories_core.select_from_available_repo(subject=subject)
if not package:
package = packages_core.select_from_available_packages(
subject=subject, repo=repo
)

url = get_url(f"/packages/{subject}/{repo}/{package}/versions/available")
response = httpx.get(url=url)
if is_internal:
return response_handler(
response=response, return_with_out_model=True, print_result=False
)
response_handler(response=response)
includeamin marked this conversation as resolved.
Show resolved Hide resolved


def get_version(
subject: str,
repo: Optional[str],
Expand All @@ -52,8 +94,8 @@ def get_version(
subject=subject, repo=repo
)
if not version:
version = files_core.select_from_available_versions(
subject=subject, repo=repo, package=package, filename=None
version = select_from_available_versions(
subject=subject, repo=repo, package=package
)
url = get_url(f"/packages/{subject}/{repo}/{package}/versions/{version}")
params = {"attribute_values": attribute_values}
Expand Down Expand Up @@ -93,8 +135,10 @@ def delete_version(
subject=username, repo=repo
)
if not version:
version = files_core.select_from_available_versions(
subject=username, repo=repo, package=package, filename=None
version = select_from_available_versions(
subject=username,
repo=repo,
package=package,
)
if not is_operation_confirmed and not is_operation_confirm():
return
Expand All @@ -119,8 +163,8 @@ def update_version(
subject=username, repo=repo
)
if not version:
version = files_core.select_from_available_versions(
subject=username, repo=repo, package=package, filename=None
version = select_from_available_versions(
subject=username, repo=repo, package=package
)
body = pydantic_to_prompt(model=VersionUpdateBodyModel)
if not is_operation_confirmed and not is_operation_confirm():
Expand Down
12 changes: 12 additions & 0 deletions paxexpress_cli/versions/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,18 @@ class VersionGetResponseModel(VersionModel):
pass


class VersionSummaryModel(BaseModel):
name: str
repo: Optional[str]
package: Optional[str]
owner: str
released: Optional[datetime.datetime]


class VersionGetAvailableVersionResponseModel(BaseModel):
__root__: List[VersionSummaryModel] = []
includeamin marked this conversation as resolved.
Show resolved Hide resolved


class VersionCreateBodyModel(BaseModel):
name: str
# released: Optional[str]
Expand Down