Skip to content

Commit be0c296

Browse files
committed
Extend the function for getting Jira details
To be able to access remote links.
1 parent b14a512 commit be0c296

File tree

2 files changed

+46
-9
lines changed

2 files changed

+46
-9
lines changed

beeai/mcp_server/jira_tools.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,38 @@ def get_jira_details(
3636
issue_key: Annotated[str, Field(description="Jira issue key (e.g. RHEL-12345)")],
3737
) -> dict[str, Any] | str:
3838
"""
39-
Gets details about the specified Jira issue, including all comments.
39+
Gets details about the specified Jira issue, including all comments and remote links.
4040
Returns a dictionary with issue details and comments or an error message on failure.
4141
"""
42+
headers = _get_jira_headers(os.getenv("JIRA_TOKEN"))
43+
44+
# Get main issue data
4245
try:
4346
response = requests.get(
4447
urljoin(os.getenv("JIRA_URL"), f"rest/api/2/issue/{issue_key}"),
4548
params={"expand": "comments"},
46-
headers=_get_jira_headers(os.getenv("JIRA_TOKEN")),
49+
headers=headers,
4750
)
4851
response.raise_for_status()
52+
issue_data = response.json()
4953
except requests.RequestException as e:
5054
return f"Failed to get details about the specified issue: {e}"
51-
return response.json()
55+
56+
# get remote links - these often contain links to PRs or mailing lists
57+
try:
58+
remote_links_response = requests.get(
59+
urljoin(os.getenv("JIRA_URL"), f"rest/api/2/issue/{issue_key}/remotelink"),
60+
headers=headers,
61+
)
62+
remote_links_response.raise_for_status()
63+
remote_links = remote_links_response.json()
64+
issue_data["remote_links"] = remote_links
65+
except requests.RequestException as e:
66+
# If remote links fail, continue without them
67+
issue_data["remote_links"] = []
68+
69+
return issue_data
70+
5271

5372

5473
def set_jira_fields(

beeai/mcp_server/tests/unit/test_jira_tools.py

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,32 @@ def test_get_jira_details():
2121
"fields": {"summary": "Test issue"},
2222
"comment": {"comments": [{"body": "Test comment"}], "total": 1},
2323
}
24-
25-
def get(url, params, headers):
26-
assert url.endswith(f"rest/api/2/issue/{issue_key}")
27-
assert params.get("expand") == "comments"
28-
return flexmock(json=lambda: issue_data, raise_for_status=lambda: None)
24+
remote_links_data = [
25+
{
26+
"id": 10000,
27+
"object": {
28+
"url": "https://github.com/example/repo/pull/123",
29+
"title": "Fix issue RHEL-12345"
30+
}
31+
}
32+
]
33+
34+
def get(url, params=None, headers=None):
35+
if url.endswith(f"rest/api/2/issue/{issue_key}"):
36+
assert params.get("expand") == "comments"
37+
return flexmock(json=lambda: issue_data, raise_for_status=lambda: None)
38+
elif url.endswith(f"rest/api/2/issue/{issue_key}/remotelink"):
39+
return flexmock(json=lambda: remote_links_data, raise_for_status=lambda: None)
40+
else:
41+
raise AssertionError(f"Unexpected URL: {url}")
2942

3043
flexmock(requests).should_receive("get").replace_with(get)
31-
assert get_jira_details(issue_key) == issue_data
44+
45+
result = get_jira_details(issue_key)
46+
expected_result = issue_data.copy()
47+
expected_result["remote_links"] = remote_links_data
48+
49+
assert result == expected_result
3250

3351

3452
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)