Skip to content
Open
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
13 changes: 10 additions & 3 deletions src/trache/cache/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@
DB_FILENAME = "cache.db"
MIGRATION_SENTINEL = "cache.db.migrated"

_HEX_CHARS = frozenset("0123456789abcdef")


def _is_trello_id(s: str) -> bool:
"""Return True if s looks like a 24-char Trello hex ID."""
return len(s) == 24 and all(c in _HEX_CHARS for c in s)

# Migration functions keyed by TARGET version. Each receives an open connection
# and runs DDL/DML to bring the schema from (key-1) to key. The version row is
# updated by the runner — migrations must NOT touch schema_version themselves.
Expand Down Expand Up @@ -702,8 +709,8 @@ def resolve_card_id(identifier: str, cache_dir: Path) -> str:
"No board initialised. Run 'trache init' and 'trache pull' first."
)

# Full 24-char ID — return as-is
if len(identifier) == 24:
# Full 24-char hex ID — return as-is
if _is_trello_id(identifier):
return identifier

# Validate UID6 format or temp ID
Expand Down Expand Up @@ -755,7 +762,7 @@ def resolve_card_id(identifier: str, cache_dir: Path) -> str:

def resolve_list_id(identifier: str, cache_dir: Path) -> str:
"""Resolve a list ID or name to a full list ID."""
if len(identifier) == 24:
if _is_trello_id(identifier):
return identifier

with _connect(cache_dir) as conn:
Expand Down
3 changes: 3 additions & 0 deletions src/trache/cli/_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ def wrapper(*args, **kwargs):
msg = e.args[0] if e.args else "Requested item not found"
get_output().error(msg)
raise typer.Exit(1)
except FileNotFoundError as e:
get_output().error(str(e))
raise typer.Exit(1)
except ValueError as e:
get_output().error(str(e))
raise typer.Exit(1)
Expand Down
1 change: 1 addition & 0 deletions src/trache/cli/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ def init(

try:
board_obj = client.get_board(config.board_id)
config.board_id = board_obj.id
config.board_name = board_obj.name
out.human(f"Board: [bold]{escape(board_obj.name)}[/bold]")
except Exception:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_push.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def test_push_added_card(self, tmp_path: Path, sample_card: Card) -> None:

client = MagicMock()
new_card = Card(
id="real_id_from_trello_here",
id="aaa111bbb222ccc333ddd444",
title=sample_card.title,
list_id=sample_card.list_id,
)
Expand Down Expand Up @@ -221,7 +221,7 @@ def test_push_new_card_with_checklists(self, tmp_path: Path) -> None:

# Mock client
real_card = Card(
id="real_trello_card_id_here", title="Card With Checklist", list_id="list1"
id="bbb222ccc333ddd444eee555", title="Card With Checklist", list_id="list1"
)
new_cl = Checklist(id="real_cl_1", name="Tasks", card_id=real_card.id)
item_a = ChecklistItem(id="real_item_a", name="Do thing A")
Expand Down