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

Fixing lint #5

Merged
merged 1 commit into from
Aug 16, 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
5 changes: 0 additions & 5 deletions .flake8

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,4 @@ cased COMMAND --help

## Contact

For any questions or support, please contact [email protected]
For any questions or support, please contact [email protected]
2 changes: 1 addition & 1 deletion cased/.vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
"[html][django-html][handlebars][hbs][mustache][jinja][jinja-html][nj][njk][nunjucks][twig]": {
"editor.defaultFormatter": "monosans.djlint"
}
}
}
3 changes: 2 additions & 1 deletion cased/cli.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import click

from cased.commands.deploy import deploy
from cased.commands.login import login, logout
from cased.commands.resources import deployments, branches
from cased.commands.resources import branches, deployments


@click.group()
Expand Down
29 changes: 11 additions & 18 deletions cased/commands/deploy.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,31 @@
import time
import click
from rich.console import Console
from rich.progress import Progress
import questionary
from rich.console import Console

from cased.utils.api import deploy_branch, get_branches
from cased.utils.auth import get_token
from cased.utils.api import get_branches, deploy_branch
from cased.utils.progress import run_process_with_status_bar

console = Console()


def _build_questionary_choices():
data = run_process_with_status_bar(
get_branches, "Fetching branches...", timeout=10
)
data = run_process_with_status_bar(get_branches, "Fetching branches...", timeout=10)
branches = data.get("pull_requests", [])
deployable_branches = [
branch for branch in branches if branch["deployable"] == True
branch for branch in branches if branch["deployable"] is True
]
# Prepare choices for questionary
choices = [
f"{b['branch_name']} -> [{', '.join([target["name"] for target in b.get("targets", [])])}]" for b in deployable_branches
f"{b['branch_name']} -> [{', '.join([target.get('name') for target in b.get('targets', [])])}]" # noqa: E501
for b in deployable_branches
]

if not choices:
console.print("[red]No deployable branches available.[/red]")
return

selected = questionary.select(
"Select a branch to deploy:", choices=choices
).ask()
selected = questionary.select("Select a branch to deploy:", choices=choices).ask()

branch = selected.split(" -> ")[0]

Expand All @@ -38,20 +34,17 @@ def _build_questionary_choices():
(b for b in deployable_branches if b["branch_name"] == branch), None
)
if not selected_branch:
console.print(f"[red]Error: Branch '{branch}' is not deployable.[/red]")
console.print(f"[red]Error: Branch {branch} is not deployable.[/red]")
return

available_targets = selected_branch["targets"]
if not available_targets:
console.print(
f"[red]Error: No targets available for branch '{branch}'.[/red]"
)
console.print(f"[red]Error: No targets available for branch {branch}.[/red]")
return
target = questionary.select(
"Select a target environment:", choices=available_targets
).ask()


return branch, target


Expand All @@ -71,7 +64,7 @@ def deploy(branch, target):
Examples:
cased deploy
cased deploy --branch feature-branch-1 --target dev
"""
""" # noqa: E501
token = get_token()
if not token:
console.print("[red]Please log in first using 'cased login'[/red]")
Expand Down
19 changes: 10 additions & 9 deletions cased/commands/login.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import json
import os
import random
import stat
import tempfile
import time
from datetime import datetime, timedelta

import click
from rich.console import Console
from rich.panel import Panel
from rich.progress import Progress
import os
import json
from datetime import datetime, timedelta
import random
import tempfile
import stat

from cased.utils.auth import CONFIG_DIR, TOKEN_FILE

Expand Down Expand Up @@ -44,7 +45,7 @@ def create_temp_token_file(token_data):

# Schedule file for deletion after 24 hours
deletion_time = datetime.now() + timedelta(hours=24)
deletion_command = f"(sleep {(deletion_time - datetime.now()).total_seconds()} && rm -f {temp_file.name}) &"
deletion_command = f"(sleep {(deletion_time - datetime.now()).total_seconds()} && rm -f {temp_file.name}) &" # noqa: E501
os.system(deletion_command)

return temp_file.name
Expand Down Expand Up @@ -86,7 +87,7 @@ def login():

console.print(
Panel(
f"[green]Login successful![/green]\nSession token stored securely.\nSession expires in {hours} hours {minutes} minutes.",
f"[green]Login successful![/green]\nSession token stored securely.\nSession expires in {hours} hours {minutes} minutes.", # noqa: E501
title="Login Status",
)
)
Expand Down Expand Up @@ -120,7 +121,7 @@ def logout():
else:
console.print(
Panel(
"[yellow]No active session found.[/yellow]\nYou are already logged out.",
"[yellow]No active session found.[/yellow]\nYou are already logged out.", # noqa: E501
title="Logout Status",
)
)
19 changes: 11 additions & 8 deletions cased/commands/resources.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import click
from dateutil import parser
from rich.console import Console
from rich.table import Table
from rich.text import Text
from dateutil import parser


from cased.utils.api import get_branches, get_deployments
from cased.utils.auth import get_token
from cased.utils.api import get_branches, get_targets, get_deployments
from cased.utils.progress import run_process_with_status_bar

console = Console()
Expand Down Expand Up @@ -53,7 +52,11 @@ def deployments(limit):
status = deployment.get("status", "Unknown")
deployment_id = deployment.get("id")
view_url = f"https://cased.com/deployments/{deployment_id}"
deployer_full_name = f"{deployment.get("deployer").get("first_name")} {deployment.get("deployer").get("last_name")}" if deployment.get("deployer") else "Unknown"
deployer_full_name = (
f"{deployment.get('deployer').get('first_name')} {deployment.get('deployer').get('last_name')}" # noqa: E501
if deployment.get("deployer")
else "Unknown"
)

deployments_data.append(
{
Expand Down Expand Up @@ -116,7 +119,7 @@ def branches(limit):
table.add_column("Deployable", style="blue")
table.add_column("Mergeable", style="blue")
table.add_column("Checks", style="cyan")

data = run_process_with_status_bar(get_branches, "Fetching branches...", timeout=10)
branches = data.get("pull_requests", [])
# Generate fake data
Expand All @@ -133,9 +136,9 @@ def branches(limit):
str(branch.get("mergeable")),
", ".join(
[
f"approved: {branch.get("approved")}",
f"up-to-date: {branch.get("up_to_date")}",
f"checks-passed: {branch.get("checks_passing")}",
f"approved: {branch.get('approved')}",
f"up-to-date: {branch.get('up_to_date')}",
f"checks-passed: {branch.get('checks_passing')}",
]
),
)
Expand Down
5 changes: 3 additions & 2 deletions cased/utils/api.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import requests
import click
import os

import click
import requests

API_BASE_URL = os.environ.get(
"CASED_API_BASE_URL", default="https://app.cased.com/api/v1"
)
Expand Down
2 changes: 1 addition & 1 deletion cased/utils/auth.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os
import json
import os
from datetime import datetime

# Configuration
Expand Down
7 changes: 4 additions & 3 deletions cased/utils/progress.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import time
from concurrent.futures import ThreadPoolExecutor, TimeoutError
from typing import Any, Callable

from rich.console import Console
from rich.progress import Progress
from concurrent.futures import ThreadPoolExecutor, TimeoutError
from typing import Callable, Any


def run_process_with_status_bar(
Expand Down Expand Up @@ -42,7 +43,7 @@ def update_progress(progress, task):
except TimeoutError:
progress.update(task, description="[bold red]Timeout!")
console.print(
f"\n[bold red]Process timed out after {timeout} seconds. Please try again later."
f"\n[bold red]Process timed out after {timeout} seconds. Please try again later." # noqa: E501
)
except Exception as e:
progress.update(task, description="[bold red]Error!")
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
click==8.1.3
rich==13.3.5
questionary==1.10.0
python-dateutil==2.9.0
python-dateutil==2.9.0
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from setuptools import setup, find_packages
from setuptools import find_packages, setup

with open("README.md", "r", encoding="utf-8") as fh:
long_description = fh.read()
Expand Down
Loading