#!/usr/bin/env python3 """ Ekeepa PRD Task Status Updater Usage: python3 update_status.py [OPTIONAL_NOTE] """ import os import sys import json import shutil import subprocess BASE_DIR = "/workspace/prds" JSON_PATH = os.path.join(BASE_DIR, "data", "prds.json") STATUS_MAP = { "in_progress": { "status": "in_progress", "statusLabel": "در حال توسعه (In Progress)", "folder": "in_progress", "default_note": "آغاز توسعه فنی و ورود به اسپرینت جاری" }, "implemented": { "status": "implemented", "statusLabel": "پیاده‌سازی شده (Live)", "folder": "implemented", "default_note": "استقرار موفق در محیط پروداکشن" }, "backlog": { "status": "backlog", "statusLabel": "در انتظار گرومینگ", "folder": "backlog", "default_note": "انتقال به بک‌لاگ / در انتظار اولویت‌بندی اسپرینت" } } def main(): if len(sys.argv) < 3: print("Usage: update_status.py [NOTE]") sys.exit(1) jira_key = sys.argv[1].strip() new_status = sys.argv[2].strip().lower() note = " ".join(sys.argv[3:]).strip() if len(sys.argv) > 3 else None if new_status not in STATUS_MAP: print(f"Error: Invalid status '{new_status}'. Allowed: {list(STATUS_MAP.keys())}") sys.exit(1) with open(JSON_PATH, "r", encoding="utf-8") as f: prds = json.load(f) target_task = None for t in prds: if t["id"].upper() == jira_key.upper() or t["jiraKey"].upper() == jira_key.upper(): target_task = t break if not target_task: print(f"Error: Task '{jira_key}' not found in prds.json") sys.exit(1) cfg = STATUS_MAP[new_status] old_status = target_task.get("status") old_file_rel = target_task.get("filePath") old_file_abs = os.path.join(BASE_DIR, old_file_rel) # Move file to the correct directory if needed filename = os.path.basename(old_file_rel) new_file_rel = os.path.join(cfg["folder"], filename) new_file_abs = os.path.join(BASE_DIR, new_file_rel) if old_file_abs != new_file_abs and os.path.exists(old_file_abs): os.makedirs(os.path.dirname(new_file_abs), exist_ok=True) shutil.move(old_file_abs, new_file_abs) print(f"Moved file: {old_file_rel} -> {new_file_rel}") target_task["status"] = cfg["status"] target_task["statusLabel"] = cfg["statusLabel"] target_task["filePath"] = new_file_rel # Add changelog entry if "versionsHistory" not in target_task: target_task["versionsHistory"] = [] import datetime today_str = datetime.date.today().strftime("%Y-%m-%d") target_task["versionsHistory"].insert(0, { "version": target_task.get("version", "v1.0.0"), "date": today_str, "notes": note or cfg["default_note"] }) with open(JSON_PATH, "w", encoding="utf-8") as f: json.dump(prds, f, ensure_ascii=False, indent=2) print(f"Updated task {jira_key} status to '{new_status}'") # Re-run build & deploy res = subprocess.run([sys.executable, os.path.join(BASE_DIR, "build.py")], capture_output=True, text=True) print(res.stdout) if res.returncode != 0: print(f"Build error: {res.stderr}") if __name__ == "__main__": main()