Merge pull request 'api/flake/history: implement review requests' (#531) from DavHau-dave into main
All checks were successful
assets1 / test (push) Successful in 22s
checks / test (push) Successful in 46s
checks-impure / test (push) Successful in 1m33s

This commit is contained in:
clan-bot 2023-11-17 11:30:13 +00:00
commit 778349b72d
5 changed files with 15 additions and 32 deletions

View File

@ -2,7 +2,7 @@
import argparse
from clan_cli.flakes.add import register_add_parser
from clan_cli.flakes.list_history import register_list_parser
from clan_cli.flakes.history import register_list_parser
from .create import register_create_parser
@ -19,5 +19,5 @@ def register_parser(parser: argparse.ArgumentParser) -> None:
register_create_parser(create_parser)
add_parser = subparser.add_parser("add", help="Add a clan flake")
register_add_parser(add_parser)
list_parser = subparser.add_parser("list", help="List clan flakes")
list_parser = subparser.add_parser("list", help="List recently used flakes")
register_list_parser(list_parser)

View File

@ -3,18 +3,10 @@ import argparse
from pathlib import Path
from typing import Dict
from pydantic import AnyUrl
from pydantic.tools import parse_obj_as
from clan_cli.dirs import user_history_file
from ..async_cmd import CmdOut, runforcli
DEFAULT_URL: AnyUrl = parse_obj_as(
AnyUrl,
"git+https://git.clan.lol/clan/clan-core?new-clan",
)
async def add_flake(path: Path) -> Dict[str, CmdOut]:
user_history_file().parent.mkdir(parents=True, exist_ok=True)

View File

@ -2,19 +2,10 @@
import argparse
from pathlib import Path
from pydantic import AnyUrl
from pydantic.tools import parse_obj_as
from clan_cli.dirs import user_history_file
DEFAULT_URL: AnyUrl = parse_obj_as(
AnyUrl,
"git+https://git.clan.lol/clan/clan-core?new-clan",
)
def list_history() -> list[Path]:
user_history_file().parent.mkdir(parents=True, exist_ok=True)
if not user_history_file().exists():
return []
# read path lines from history file

View File

@ -46,14 +46,14 @@ async def get_attrs(url: AnyUrl | Path) -> list[str]:
return flake_attrs
@router.put("/api/flake/add", tags=[Tags.flake])
async def add_flake(flake_dir: Path) -> None:
@router.post("/api/flake/history", tags=[Tags.flake])
async def flake_history_append(flake_dir: Path) -> None:
await add.add_flake(flake_dir)
@router.get("/api/flake/list_history", tags=[Tags.flake])
async def list_flakes() -> list[Path]:
return flakes.list_history.list_history()
@router.get("/api/flake/history", tags=[Tags.flake])
async def flake_history_list() -> list[Path]:
return flakes.history.list_history()
# TODO: Check for directory traversal

View File

@ -11,11 +11,11 @@ from clan_cli.dirs import user_history_file
log = logging.getLogger(__name__)
def test_flake_add(
def test_flake_history_append(
api: TestClient, test_flake: FlakeForTest, temporary_home: Path
) -> None:
response = api.put(
f"/api/flake/add?flake_dir={str(test_flake.path)}",
response = api.post(
f"/api/flake/history?flake_dir={str(test_flake.path)}",
json={},
)
assert response.status_code == 200, response.json()
@ -23,25 +23,25 @@ def test_flake_add(
assert open(user_history_file()).read().strip() == str(test_flake.path)
def test_flake_list(
def test_flake_history_list(
api: TestClient, test_flake: FlakeForTest, temporary_home: Path
) -> None:
response = api.get(
"/api/flake/list_history",
"/api/flake/history",
)
assert response.status_code == 200, response.text
assert response.json() == []
# add the test_flake
response = api.put(
f"/api/flake/add?flake_dir={str(test_flake.path)}",
response = api.post(
f"/api/flake/history?flake_dir={str(test_flake.path)}",
json={},
)
assert response.status_code == 200, response.text
# list the flakes again
response = api.get(
"/api/flake/list_history",
"/api/flake/history",
)
assert response.status_code == 200, response.text
assert response.json() == [str(test_flake.path)]