feat: implement Trello list management
Add 4 list management tools extending the Trello client: - trello_create_list — create a new list on a board - trello_rename_list — rename an existing list - trello_archive_list — archive a list - trello_move_list — move a list to a new position Also update the auth spec doc to reflect the PR #5 review fixes (TypedDict contracts, updated disconnect message). Issue: #3
This commit is contained in:
@@ -259,6 +259,11 @@ class TrelloClient:
|
||||
board = result["data"]
|
||||
return {"id": board["id"], "name": board.get("name", ""), "url": board.get("url", "")}
|
||||
|
||||
# If the error is about missing credentials, propagate that directly
|
||||
error_msg = result.get("message", "")
|
||||
if "TRELLO_API_KEY" in error_msg:
|
||||
return {"success": False, "message": error_msg}
|
||||
|
||||
# Try resolving by name
|
||||
boards_result = self.list_boards()
|
||||
if not _is_success(boards_result): # type: ignore[arg-type]
|
||||
@@ -462,6 +467,110 @@ class TrelloClient:
|
||||
},
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# Public API — List Management
|
||||
# ------------------------------------------------------------------
|
||||
|
||||
def create_list(self, name: str, board_id: str, pos: str = "bottom") -> dict[str, Any]:
|
||||
"""Create a new list on a Trello board.
|
||||
|
||||
Args:
|
||||
name: The name for the new list.
|
||||
board_id: Board ID or name.
|
||||
pos: Position — ``"top"``, ``"bottom"``, or a number.
|
||||
|
||||
Returns:
|
||||
dict with list details on success, or an error dict.
|
||||
"""
|
||||
resolved = self._resolve_board_id(board_id)
|
||||
if "success" in resolved and resolved["success"] is False:
|
||||
return resolved # type: ignore[typeddict-item]
|
||||
|
||||
body: dict[str, Any] = {
|
||||
"name": name,
|
||||
"idBoard": resolved["id"],
|
||||
"pos": pos,
|
||||
}
|
||||
result = self._post("/lists", json_body=body)
|
||||
if _is_success(result):
|
||||
lst = result["data"]
|
||||
return {
|
||||
"success": True,
|
||||
"list": {
|
||||
"id": lst.get("id"),
|
||||
"name": lst.get("name"),
|
||||
"id_board": lst.get("idBoard"),
|
||||
},
|
||||
}
|
||||
return {
|
||||
"success": False,
|
||||
"message": result.get("message", "Failed to create list."),
|
||||
}
|
||||
|
||||
def rename_list(self, list_id: str, name: str) -> dict[str, Any]:
|
||||
"""Rename an existing list.
|
||||
|
||||
Args:
|
||||
list_id: Trello list ID.
|
||||
name: The new name.
|
||||
|
||||
Returns:
|
||||
dict with list details on success, or an error dict.
|
||||
"""
|
||||
result = self._put(f"/lists/{list_id}", json_body={"name": name})
|
||||
if _is_success(result):
|
||||
lst = result["data"]
|
||||
return {
|
||||
"success": True,
|
||||
"list": {
|
||||
"id": lst.get("id"),
|
||||
"name": lst.get("name"),
|
||||
},
|
||||
}
|
||||
return {
|
||||
"success": False,
|
||||
"message": result.get("message", "Failed to rename list."),
|
||||
}
|
||||
|
||||
def archive_list(self, list_id: str) -> dict[str, Any]:
|
||||
"""Archive a list.
|
||||
|
||||
Args:
|
||||
list_id: Trello list ID.
|
||||
|
||||
Returns:
|
||||
dict with success message or error.
|
||||
"""
|
||||
result = self._put(f"/lists/{list_id}", json_body={"closed": True})
|
||||
if _is_success(result):
|
||||
lst = result["data"]
|
||||
list_name = lst.get("name", list_id)
|
||||
return {"success": True, "message": f"List '{list_name}' archived."}
|
||||
return {
|
||||
"success": False,
|
||||
"message": result.get("message", "Failed to archive list."),
|
||||
}
|
||||
|
||||
def move_list(self, list_id: str, pos: str = "bottom") -> dict[str, Any]:
|
||||
"""Move a list to a different position on the board.
|
||||
|
||||
Args:
|
||||
list_id: Trello list ID.
|
||||
pos: Position — ``"top"``, ``"bottom"``, or a number.
|
||||
|
||||
Returns:
|
||||
dict with success message or error.
|
||||
"""
|
||||
result = self._put(f"/lists/{list_id}", json_body={"pos": pos})
|
||||
if _is_success(result):
|
||||
lst = result["data"]
|
||||
list_name = lst.get("name", list_id)
|
||||
return {"success": True, "message": f"List '{list_name}' moved."}
|
||||
return {
|
||||
"success": False,
|
||||
"message": result.get("message", "Failed to move list."),
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
def check_requirements() -> bool:
|
||||
"""Check if the required environment variables are set."""
|
||||
|
||||
Reference in New Issue
Block a user