Skip to content

Commit 1cd2384

Browse files
committed
EX-329: updated remove logic
1 parent 3b70f20 commit 1cd2384

2 files changed

Lines changed: 24 additions & 11 deletions

File tree

src/code_review_agent/cli.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,6 @@ def assess(
466466
return
467467

468468
comment_body = (
469-
f"🤖 *AI Assessment Complete*\n\n"
470469
f"Relevance: *{relevance.score}%*\n\n"
471470
f"Justification: {relevance.justification}"
472471
)

src/code_review_agent/jira_client.py

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def _current_account_id() -> str | None:
105105
pass
106106
return None
107107

108-
def _remove_previous_ai_comments(jira_url: str, task_id: str, marker: str, account_id: str | None):
108+
def _remove_previous_ai_comments(jira_url: str, task_id: str, markers: list[str], account_id: str | None):
109109
auth, headers = _auth_headers()
110110
try:
111111
resp = requests.get(
@@ -117,11 +117,18 @@ def _remove_previous_ai_comments(jira_url: str, task_id: str, marker: str, accou
117117
return
118118
data = resp.json()
119119
removed = 0
120+
121+
def _norm(txt: str) -> str:
122+
return txt.replace("*", "").strip()
123+
124+
norm_markers = {_norm(m) for m in markers}
125+
120126
for c in data.get("comments", []):
121127
cid = c.get("id")
122128
author_id = c.get("author", {}).get("accountId")
123129
body_text = _extract_text_from_adf(c.get("body"))
124-
if marker in body_text and (account_id is None or author_id == account_id):
130+
body_norm = _norm(body_text)
131+
if any(nm in body_norm for nm in norm_markers) and (account_id is None or author_id == account_id):
125132
try:
126133
d = requests.delete(
127134
f"{jira_url}/rest/api/3/issue/{task_id}/comment/{cid}",
@@ -141,23 +148,30 @@ def _remove_previous_ai_comments(jira_url: str, task_id: str, marker: str, accou
141148

142149
def add_comment(task_id: str, comment: str):
143150
"""
144-
Adds (replaces) AI assessment comment:
145-
- Deletes previous comments containing marker (and authored by this user if detectable)
146-
- Posts a fresh one.
151+
Adds (replaces) AI assessment comment with bold marker.
147152
"""
148153
logger.info(f"Adding comment to Jira task {task_id}...")
149154
try:
150155
jira_url = os.environ["JIRA_URL"].rstrip("/")
151156
auth, headers = _auth_headers()
152157

153-
marker = os.getenv("JIRA_AI_COMMENT_TAG", "🤖 AI Assessment")
154-
if marker not in comment:
155-
comment = f"{marker}\n\n{comment}"
158+
# Primary (bold) marker
159+
primary_marker = os.getenv("JIRA_AI_COMMENT_TAG", "*🤖 AI Assessment Complete*")
160+
161+
legacy_markers = [
162+
"🤖 AI Assessment Complete",
163+
"🤖 AI Assessment"
164+
]
165+
all_markers = [primary_marker] + [m for m in legacy_markers if m != primary_marker]
166+
167+
first_line = comment.strip().splitlines()[0] if comment.strip() else ""
168+
169+
if not any(first_line.replace("*", "").startswith(m.replace("*", "")) for m in all_markers):
170+
comment = f"{primary_marker}\n\n{comment}"
156171

157172
account_id = _current_account_id()
158-
_remove_previous_ai_comments(jira_url, task_id, marker, account_id)
173+
_remove_previous_ai_comments(jira_url, task_id, all_markers, account_id)
159174

160-
# Use v3 first, fallback v2
161175
payload = {"body": comment}
162176
for ver in ("3", "2"):
163177
api_url = f"{jira_url}/rest/api/{ver}/issue/{task_id}/comment"

0 commit comments

Comments
 (0)