diff --git a/src/plane_sync.py b/src/plane_sync.py index ad88e9e..da2412d 100644 --- a/src/plane_sync.py +++ b/src/plane_sync.py @@ -113,25 +113,26 @@ def find_issue_id(work_item_id: str, project_id: str = None) -> str | None: resp.raise_for_status() data = resp.json() results = data.get("results", data if isinstance(data, list) else []) + # M-6: match by sequence_id directly (the authoritative per-project + # number), parsed from the work_item_id suffix - no hardcoded prefix. + try: + target_num = int(work_item_id.rsplit("-", 1)[1]) + except (IndexError, ValueError): + target_num = None for issue in results: - seq = issue.get("sequence_id") - identifier = f"ET-{seq:03d}" if seq else "" - if identifier == work_item_id or work_item_id in issue.get("name", ""): + if target_num is not None and issue.get("sequence_id") == target_num: return issue["id"] - # Fallback: get all issues and match by sequence_id number - if work_item_id.startswith("ET-"): - try: - target_num = int(work_item_id.split("-")[1]) - except (IndexError, ValueError): - target_num = None - if target_num: - resp2 = httpx.get(url, headers=PLANE_HEADERS, timeout=10) - resp2.raise_for_status() - data2 = resp2.json() - results2 = data2.get("results", data2 if isinstance(data2, list) else []) - for issue in results2: - if issue.get("sequence_id") == target_num: - return issue["id"] + if work_item_id in issue.get("name", ""): + return issue["id"] + # Fallback: get all issues and match by sequence_id number (any prefix) + if target_num is not None: + resp2 = httpx.get(url, headers=PLANE_HEADERS, timeout=10) + resp2.raise_for_status() + data2 = resp2.json() + results2 = data2.get("results", data2 if isinstance(data2, list) else []) + for issue in results2: + if issue.get("sequence_id") == target_num: + return issue["id"] except Exception as e: logger.error(f"Failed to find issue for {work_item_id}: {e}") return None