Skip to content

Commit e5bf9fd

Browse files
authored
Merge pull request #56 from eifrach/components_fix
fix components filter by jira issue
2 parents 8ebbd08 + 6e05579 commit e5bf9fd

File tree

1 file changed

+23
-13
lines changed

1 file changed

+23
-13
lines changed

src/tools.py

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ async def list_jira_issues(
5454
search_text: Optional[str] = None
5555
) -> Dict[str, Any]:
5656
"""
57-
List JIRA issues from Snowflake with optional filtering.
5857
5958
Args:
6059
project: Filter by project key (e.g., 'SMQE', 'OSIM')
@@ -332,13 +331,15 @@ async def list_jira_components(
332331
project: Optional[str] = None,
333332
archived: Optional[str] = None,
334333
deleted: Optional[str] = None,
334+
issue: Optional[str] = None,
335335
limit: int = 50,
336336
search_text: Optional[str] = None
337337
) -> Dict[str, Any]:
338338
"""
339339
List JIRA components from Snowflake with optional filtering.
340340
341341
Args:
342+
issue: Filter by issue ID (e.g., 'SMQE-1280')
342343
project: Filter by project ID (e.g., '12325621')
343344
archived: Filter by archived status ('Y' or 'N')
344345
deleted: Filter by deleted status ('Y' or 'N')
@@ -357,17 +358,20 @@ async def list_jira_components(
357358
# Build SQL query with filters
358359
sql_conditions = []
359360

361+
if issue:
362+
sql_conditions.append(f"i.ISSUE_KEY = '{sanitize_sql_value(issue)}'")
363+
360364
if project:
361-
sql_conditions.append(f"PROJECT = '{sanitize_sql_value(project)}'")
365+
sql_conditions.append(f"c.PROJECT = '{sanitize_sql_value(project)}'")
362366

363367
if archived:
364-
sql_conditions.append(f"ARCHIVED = '{sanitize_sql_value(archived.upper())}'")
368+
sql_conditions.append(f"c.ARCHIVED = '{sanitize_sql_value(archived.upper())}'")
365369

366370
if deleted:
367-
sql_conditions.append(f"DELETED = '{sanitize_sql_value(deleted.upper())}'")
371+
sql_conditions.append(f"c.DELETED = '{sanitize_sql_value(deleted.upper())}'")
368372

369373
if search_text:
370-
search_condition = f"(LOWER(CNAME) LIKE '%{sanitize_sql_value(search_text.lower())}%' OR LOWER(DESCRIPTION) LIKE '%{sanitize_sql_value(search_text.lower())}%')"
374+
search_condition = f"(LOWER(c.CNAME) LIKE '%{sanitize_sql_value(search_text.lower())}%' OR LOWER(c.DESCRIPTION) LIKE '%{sanitize_sql_value(search_text.lower())}%')"
371375
sql_conditions.append(search_condition)
372376

373377
where_clause = ""
@@ -376,12 +380,17 @@ async def list_jira_components(
376380

377381
sql = f"""
378382
SELECT
379-
ID, PROJECT, CNAME, DESCRIPTION, URL, LEAD,
380-
ASSIGNEETYPE, ARCHIVED, DELETED, _FIVETRAN_SYNCED
381-
FROM JIRA_COMPONENT_RHAI
382-
{where_clause}
383-
ORDER BY CNAME ASC
384-
LIMIT {limit}
383+
c.ID, c.PROJECT, c.CNAME as COMPONENT_NAME, c.DESCRIPTION, c.URL, c.LEAD,
384+
c.ASSIGNEETYPE, c.ARCHIVED, c.DELETED, c._FIVETRAN_SYNCED
385+
FROM JIRA_DB.RHAI_MARTS.JIRA_ISSUE_NON_PII i
386+
JOIN JIRA_DB.RHAI_MARTS.JIRA_NODEASSOCIATION_RHAI na
387+
ON i.ID = na.SOURCE_NODE_ID
388+
AND na.ASSOCIATION_TYPE = 'IssueComponent'
389+
JOIN JIRA_DB.RHAI_MARTS.JIRA_COMPONENT_RHAI c
390+
ON na.SINK_NODE_ID = c.ID
391+
{where_clause}
392+
ORDER BY c.CNAME ASC
393+
LIMIT {limit}
385394
"""
386395

387396
rows = await execute_snowflake_query(sql, snowflake_token)
@@ -390,7 +399,7 @@ async def list_jira_components(
390399

391400
# Expected column order based on SELECT statement
392401
columns = [
393-
"ID", "PROJECT", "CNAME", "DESCRIPTION", "URL", "LEAD",
402+
"ID", "PROJECT", "COMPONENT_NAME", "DESCRIPTION", "URL", "LEAD",
394403
"ASSIGNEETYPE", "ARCHIVED", "DELETED", "_FIVETRAN_SYNCED"
395404
]
396405

@@ -401,7 +410,7 @@ async def list_jira_components(
401410
component = {
402411
"id": row_dict.get("ID"),
403412
"project": row_dict.get("PROJECT"),
404-
"name": row_dict.get("CNAME"),
413+
"name": row_dict.get("COMPONENT_NAME"),
405414
"description": row_dict.get("DESCRIPTION") or "",
406415
"url": row_dict.get("URL"),
407416
"lead": row_dict.get("LEAD"),
@@ -418,6 +427,7 @@ async def list_jira_components(
418427
"total_returned": len(components),
419428
"filters_applied": {
420429
"project": project,
430+
"issue": issue,
421431
"archived": archived,
422432
"deleted": deleted,
423433
"search_text": search_text,

0 commit comments

Comments
 (0)