90 lines
2.9 KiB
Python
90 lines
2.9 KiB
Python
"""CLI script to create a ClickUp task in a client's Overall list.
|
|
|
|
Usage:
|
|
uv run python scripts/create_clickup_task.py --name "Task" --client "Client"
|
|
uv run python scripts/create_clickup_task.py --name "PR" --client "Acme" \\
|
|
--category "Press Release"
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
import json
|
|
import os
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
# Add project root to path so we can import cheddahbot
|
|
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
|
|
|
|
from dotenv import load_dotenv
|
|
|
|
from cheddahbot.clickup import ClickUpClient
|
|
|
|
|
|
def main():
|
|
load_dotenv()
|
|
|
|
parser = argparse.ArgumentParser(description="Create a ClickUp task")
|
|
parser.add_argument("--name", required=True, help="Task name")
|
|
parser.add_argument("--client", required=True, help="Client folder name in ClickUp")
|
|
parser.add_argument("--category", default="", help="Work Category (e.g. 'Press Release')")
|
|
parser.add_argument("--description", default="", help="Task description")
|
|
parser.add_argument("--status", default="to do", help="Initial status (default: 'to do')")
|
|
args = parser.parse_args()
|
|
|
|
api_token = os.environ.get("CLICKUP_API_TOKEN", "")
|
|
space_id = os.environ.get("CLICKUP_SPACE_ID", "")
|
|
|
|
if not api_token:
|
|
print("Error: CLICKUP_API_TOKEN not set", file=sys.stderr)
|
|
sys.exit(1)
|
|
if not space_id:
|
|
print("Error: CLICKUP_SPACE_ID not set", file=sys.stderr)
|
|
sys.exit(1)
|
|
|
|
client = ClickUpClient(api_token=api_token)
|
|
try:
|
|
# Find the client's Overall list
|
|
list_id = client.find_list_in_folder(space_id, args.client)
|
|
if not list_id:
|
|
msg = f"Error: No folder '{args.client}' with 'Overall' list"
|
|
print(msg, file=sys.stderr)
|
|
sys.exit(1)
|
|
|
|
# Create the task
|
|
result = client.create_task(
|
|
list_id=list_id,
|
|
name=args.name,
|
|
description=args.description,
|
|
status=args.status,
|
|
)
|
|
task_id = result.get("id", "")
|
|
|
|
# Set Client dropdown field
|
|
client.set_custom_field_by_name(task_id, "Client", args.client)
|
|
|
|
# Set Work Category if provided
|
|
if args.category:
|
|
field_info = client.discover_field_filter(list_id, "Work Category")
|
|
if field_info and args.category in field_info["options"]:
|
|
option_id = field_info["options"][args.category]
|
|
client.set_custom_field_value(task_id, field_info["field_id"], option_id)
|
|
else:
|
|
msg = f"Warning: Work Category '{args.category}' not found"
|
|
print(msg, file=sys.stderr)
|
|
|
|
print(json.dumps({
|
|
"id": task_id,
|
|
"name": args.name,
|
|
"client": args.client,
|
|
"url": result.get("url", ""),
|
|
"status": args.status,
|
|
}, indent=2))
|
|
finally:
|
|
client.close()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|