Commit ab3ee6a4 authored by MD. SHAHIDUL ISLAM's avatar MD. SHAHIDUL ISLAM

feat: Add mark_done_and_assign_to_qa tool and corresponding tests

parent e6fb2c6a
...@@ -423,6 +423,87 @@ def transition_issue(issue_key: str, transition_name: str) -> str: ...@@ -423,6 +423,87 @@ def transition_issue(issue_key: str, transition_name: str) -> str:
except Exception as e: except Exception as e:
return f"Error transitioning issue {issue_key}: {str(e)}" return f"Error transitioning issue {issue_key}: {str(e)}"
@mcp.tool()
def mark_done_and_assign_to_qa(issue_key: str, qa_tester: str = None) -> str:
"""
Marks an issue as complete and assigns it to the QA tester in one operation.
This tool performs two actions:
1. Transitions the issue to 'QA Assigned' status (from completed development)
2. Assigns the issue to the QA tester
Args:
issue_key: The Jira issue key (e.g., 'PCM-227')
qa_tester: The QA tester's username. If not provided, uses JIRA_QA_TESTER env variable.
If neither available, raises an error with instructions.
Returns: Success message with both operations completed, or error if unable to proceed.
IMPORTANT: You must explicitly ask the user for confirmation before executing this tool.
"""
jira = _get_jira()
# Determine which tester to use
tester_username = qa_tester or JIRA_QA_TESTER
if not tester_username:
return (
"Error: QA tester not specified. Please provide the tester's username.\n"
f"Set the environment variable JIRA_QA_TESTER or call this tool with qa_tester parameter.\n"
f"Example: mark_done_and_assign_to_qa('{issue_key}', 'samia')\n\n"
"Configured users:\n"
"- Shahidul Islam\n"
"- Samia Islam\n"
"- Md. Sazzadul Islam\n"
"- Ruhit Arman\n"
"- Sudipta Anupan Datta\n"
"- Mehreen Rashid\n"
"- Asif Anam\n"
"- Ayasha Hossain Jui"
)
try:
# Step 1: Transition issue to "QA Assigned" (which maps to "Ready for QA")
transitions = jira.transitions(issue_key)
transition_id = None
available_transitions = []
for t in transitions:
available_transitions.append(t['name'])
# Look for "Ready for QA" transition (normalized from "QA Assigned")
if t['name'].lower() == "ready for qa":
transition_id = t['id']
break
if not transition_id:
available_str = ", ".join(f"'{name}'" for name in available_transitions)
return (
f"Error: Cannot transition issue {issue_key} to 'QA Assigned'.\n"
f"Available transitions: {available_str}\n"
f"The issue may not be in a state that allows QA assignment."
)
# Execute transition
jira.transition_issue(issue_key, transition_id)
# Step 2: Assign to QA tester
jira.assign_issue(issue_key, tester_username)
# Get updated issue details for confirmation
issue = jira.issue(issue_key)
status = issue.fields.status.name
assignee = issue.fields.assignee.displayName if issue.fields.assignee else "Unassigned"
return (
f"✅ Successfully completed both operations for [{issue_key}]({BASE_URL}/browse/{issue_key}):\n"
f" • Status transitioned to: {status}\n"
f" • Assigned to: {assignee}\n"
f" • Summary: {issue.fields.summary}"
)
except Exception as e:
return f"Error marking issue {issue_key} done and assigning to QA: {str(e)}"
@mcp.tool() @mcp.tool()
def search_issues(jql_query: str) -> str: def search_issues(jql_query: str) -> str:
"""Searches Jira for issues using a JQL (Jira Query Language) string. """Searches Jira for issues using a JQL (Jira Query Language) string.
......
#!/usr/bin/env python3
"""Test the mark_done_and_assign_to_qa tool logic."""
# Simulated environment
JIRA_QA_TESTER = "samia" # Set or None to test both scenarios
BASE_URL = "http://103.41.111.60:8085"
def mark_done_and_assign_to_qa_test(issue_key: str, qa_tester: str = None) -> str:
"""Simulated version of the mark_done_and_assign_to_qa tool for testing."""
# Determine which tester to use
tester_username = qa_tester or JIRA_QA_TESTER
if not tester_username:
return (
"Error: QA tester not specified. Please provide the tester's username.\n"
f"Set the environment variable JIRA_QA_TESTER or call this tool with qa_tester parameter.\n"
f"Example: mark_done_and_assign_to_qa('{issue_key}', 'samia')\n\n"
"Configured users:\n"
"- Shahidul Islam\n"
"- Samia Islam\n"
"- Md. Sazzadul Islam\n"
"- Ruhit Arman\n"
"- Sudipta Anupan Datta\n"
"- Mehreen Rashid\n"
"- Asif Anam\n"
"- Ayasha Hossain Jui"
)
# Simulate successful operation
return (
f"✅ Successfully completed both operations for [{issue_key}]({BASE_URL}/browse/{issue_key}):\n"
f" • Status transitioned to: QA Assigned\n"
f" • Assigned to: {tester_username}\n"
f" • Summary: Sample Issue Title"
)
# Test Cases
print("=" * 70)
print("TEST 1: Marking PCM-227 done with QA tester from env variable")
print("=" * 70)
result = mark_done_and_assign_to_qa_test("PCM-227")
print(result)
print("\n" + "=" * 70)
print("TEST 2: Marking PCM-226 done with explicit QA tester parameter")
print("=" * 70)
result = mark_done_and_assign_to_qa_test("PCM-226", qa_tester="mehreen")
print(result)
print("\n" + "=" * 70)
print("TEST 3: Marking PCM-225 done - no tester provided, env var not set")
print("=" * 70)
# Simulate env var not being set
original_tester = JIRA_QA_TESTER
JIRA_QA_TESTER = None
result = mark_done_and_assign_to_qa_test("PCM-225")
print(result)
JIRA_QA_TESTER = original_tester
print("\n" + "=" * 70)
print("SUMMARY: Tool Behavior")
print("=" * 70)
print("""
1. ✅ When JIRA_QA_TESTER env var is set:
- Tool uses that tester automatically
- No need to ask user
2. ✅ When qa_tester parameter is provided:
- Tool uses the provided parameter
- Overrides env variable if set
3. ✅ When neither is available:
- Tool returns helpful error message
- Shows list of available QA testers
- Asks user to either:
a) Set JIRA_QA_TESTER environment variable, OR
b) Provide qa_tester parameter directly
4. ✅ Operations performed:
- Transition to "QA Assigned" (Ready for QA)
- Assignment to selected QA tester
- Both in one tool call for efficiency
""")
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment