CheddahBot/scripts/fix_tier_one_flags.py

65 lines
1.8 KiB
Python

"""Fix CLIFlags custom field: replace --tier-one with --tier-1 on all non-closed tasks.
Usage:
uv run python scripts/fix_tier_one_flags.py # dry-run (default)
uv run python scripts/fix_tier_one_flags.py --apply # actually update tasks
"""
from __future__ import annotations
import argparse
import os
import re
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
from dotenv import load_dotenv
from cheddahbot.clickup import ClickUpClient
load_dotenv()
def main():
parser = argparse.ArgumentParser(description="Fix --tier-one -> --tier-1 in CLIFlags")
parser.add_argument("--apply", action="store_true", help="Actually update tasks (default: dry-run)")
args = parser.parse_args()
token = os.environ["CLICKUP_API_TOKEN"]
space_id = os.environ["CLICKUP_SPACE_ID"]
client = ClickUpClient(api_token=token)
print(f"Fetching all non-closed tasks from space {space_id}...")
tasks = client.get_tasks_from_space(space_id)
print(f"Found {len(tasks)} tasks total")
fix_count = 0
for task in tasks:
cli_flags = task.custom_fields.get("CLIFlags", "") or ""
if "--tier-one" not in cli_flags:
continue
new_flags = cli_flags.replace("--tier-one", "--tier-1")
fix_count += 1
print(f" [{task.id}] {task.name}")
print(f" OLD: {cli_flags}")
print(f" NEW: {new_flags}")
if args.apply:
ok = client.set_custom_field_by_name(task.id, "CLIFlags", new_flags)
if ok:
print(" -> Updated")
else:
print(" -> FAILED to update")
print(f"\n{'Updated' if args.apply else 'Would update'} {fix_count} tasks")
if not args.apply and fix_count > 0:
print("Run with --apply to make changes")
if __name__ == "__main__":
main()