api/flake/history: implement review requests
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
import argparse
|
import argparse
|
||||||
|
|
||||||
from clan_cli.flakes.add import register_add_parser
|
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
|
from .create import register_create_parser
|
||||||
|
|
||||||
@@ -19,5 +19,5 @@ def register_parser(parser: argparse.ArgumentParser) -> None:
|
|||||||
register_create_parser(create_parser)
|
register_create_parser(create_parser)
|
||||||
add_parser = subparser.add_parser("add", help="Add a clan flake")
|
add_parser = subparser.add_parser("add", help="Add a clan flake")
|
||||||
register_add_parser(add_parser)
|
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)
|
register_list_parser(list_parser)
|
||||||
|
|||||||
@@ -3,18 +3,10 @@ import argparse
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
||||||
from pydantic import AnyUrl
|
|
||||||
from pydantic.tools import parse_obj_as
|
|
||||||
|
|
||||||
from clan_cli.dirs import user_history_file
|
from clan_cli.dirs import user_history_file
|
||||||
|
|
||||||
from ..async_cmd import CmdOut, runforcli
|
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]:
|
async def add_flake(path: Path) -> Dict[str, CmdOut]:
|
||||||
user_history_file().parent.mkdir(parents=True, exist_ok=True)
|
user_history_file().parent.mkdir(parents=True, exist_ok=True)
|
||||||
|
|||||||
@@ -2,19 +2,10 @@
|
|||||||
import argparse
|
import argparse
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from pydantic import AnyUrl
|
|
||||||
from pydantic.tools import parse_obj_as
|
|
||||||
|
|
||||||
from clan_cli.dirs import user_history_file
|
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]:
|
def list_history() -> list[Path]:
|
||||||
user_history_file().parent.mkdir(parents=True, exist_ok=True)
|
|
||||||
if not user_history_file().exists():
|
if not user_history_file().exists():
|
||||||
return []
|
return []
|
||||||
# read path lines from history file
|
# read path lines from history file
|
||||||
@@ -46,14 +46,14 @@ async def get_attrs(url: AnyUrl | Path) -> list[str]:
|
|||||||
return flake_attrs
|
return flake_attrs
|
||||||
|
|
||||||
|
|
||||||
@router.put("/api/flake/add", tags=[Tags.flake])
|
@router.post("/api/flake/history", tags=[Tags.flake])
|
||||||
async def add_flake(flake_dir: Path) -> None:
|
async def flake_history_append(flake_dir: Path) -> None:
|
||||||
await add.add_flake(flake_dir)
|
await add.add_flake(flake_dir)
|
||||||
|
|
||||||
|
|
||||||
@router.get("/api/flake/list_history", tags=[Tags.flake])
|
@router.get("/api/flake/history", tags=[Tags.flake])
|
||||||
async def list_flakes() -> list[Path]:
|
async def flake_history_list() -> list[Path]:
|
||||||
return flakes.list_history.list_history()
|
return flakes.history.list_history()
|
||||||
|
|
||||||
|
|
||||||
# TODO: Check for directory traversal
|
# TODO: Check for directory traversal
|
||||||
|
|||||||
@@ -11,11 +11,11 @@ from clan_cli.dirs import user_history_file
|
|||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def test_flake_add(
|
def test_flake_history_append(
|
||||||
api: TestClient, test_flake: FlakeForTest, temporary_home: Path
|
api: TestClient, test_flake: FlakeForTest, temporary_home: Path
|
||||||
) -> None:
|
) -> None:
|
||||||
response = api.put(
|
response = api.post(
|
||||||
f"/api/flake/add?flake_dir={str(test_flake.path)}",
|
f"/api/flake/history?flake_dir={str(test_flake.path)}",
|
||||||
json={},
|
json={},
|
||||||
)
|
)
|
||||||
assert response.status_code == 200, response.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)
|
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
|
api: TestClient, test_flake: FlakeForTest, temporary_home: Path
|
||||||
) -> None:
|
) -> None:
|
||||||
response = api.get(
|
response = api.get(
|
||||||
"/api/flake/list_history",
|
"/api/flake/history",
|
||||||
)
|
)
|
||||||
assert response.status_code == 200, response.text
|
assert response.status_code == 200, response.text
|
||||||
assert response.json() == []
|
assert response.json() == []
|
||||||
|
|
||||||
# add the test_flake
|
# add the test_flake
|
||||||
response = api.put(
|
response = api.post(
|
||||||
f"/api/flake/add?flake_dir={str(test_flake.path)}",
|
f"/api/flake/history?flake_dir={str(test_flake.path)}",
|
||||||
json={},
|
json={},
|
||||||
)
|
)
|
||||||
assert response.status_code == 200, response.text
|
assert response.status_code == 200, response.text
|
||||||
|
|
||||||
# list the flakes again
|
# list the flakes again
|
||||||
response = api.get(
|
response = api.get(
|
||||||
"/api/flake/list_history",
|
"/api/flake/history",
|
||||||
)
|
)
|
||||||
assert response.status_code == 200, response.text
|
assert response.status_code == 200, response.text
|
||||||
assert response.json() == [str(test_flake.path)]
|
assert response.json() == [str(test_flake.path)]
|
||||||
|
|||||||
Reference in New Issue
Block a user