-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Asignee and Reporter metadata for Epics in JiraReader (#16842)
- Loading branch information
Showing
5 changed files
with
204 additions
and
11 deletions.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
llama-index-integrations/readers/llama-index-readers-jira/CHANGELOG.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
# CHANGELOG | ||
|
||
## [0.3.2] - 2024-11-05 | ||
|
||
- Add assignee and reporter emails as metadata | ||
- Fix getting assignee and reporter for epics | ||
- Add include_epics parameter | ||
|
||
## [0.1.2] - 2024-02-13 | ||
|
||
- Add maintainers and keywords from library.json (llamahub) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletion
4
llama-index-integrations/readers/llama-index-readers-jira/tests/BUILD
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
python_tests() | ||
python_tests( | ||
dependencies=["llama-index-integrations/readers/llama-index-readers-jira:poetry"], | ||
) |
166 changes: 166 additions & 0 deletions
166
llama-index-integrations/readers/llama-index-readers-jira/tests/test_readers_jira.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,173 @@ | ||
from llama_index.core.readers.base import BaseReader | ||
from llama_index.readers.jira import JiraReader | ||
import pytest | ||
from unittest.mock import patch, MagicMock | ||
|
||
|
||
def test_class(): | ||
names_of_base_classes = [b.__name__ for b in JiraReader.__mro__] | ||
assert BaseReader.__name__ in names_of_base_classes | ||
|
||
|
||
@pytest.fixture(autouse=True) | ||
def mock_jira(): | ||
with patch("jira.JIRA") as mock_jira: | ||
mock_jira.return_value = MagicMock() | ||
yield mock_jira | ||
|
||
|
||
@pytest.fixture() | ||
def mock_issue(): | ||
issue = MagicMock() | ||
# Setup basic issue fields | ||
issue.id = "TEST-123" | ||
issue.fields.summary = "Test Summary" | ||
issue.fields.description = "Test Description" | ||
issue.fields.issuetype.name = "Story" | ||
issue.fields.created = "2024-01-01" | ||
issue.fields.updated = "2024-01-02" | ||
issue.fields.labels = ["test-label"] | ||
issue.fields.status.name = "In Progress" | ||
issue.fields.project.name = "Test Project" | ||
issue.fields.priority.name = "High" | ||
|
||
# Setup assignee and reporter | ||
issue.fields.assignee = MagicMock() | ||
issue.fields.assignee.displayName = "Test Assignee" | ||
issue.fields.assignee.emailAddress = "[email protected]" | ||
issue.fields.reporter = MagicMock() | ||
issue.fields.reporter.displayName = "Test Reporter" | ||
issue.fields.reporter.emailAddress = "[email protected]" | ||
|
||
# Setup raw fields for parent/epic info | ||
issue.raw = { | ||
"fields": { | ||
"parent": { | ||
"key": "EPIC-1", | ||
"fields": { | ||
"summary": "Epic Summary", | ||
"status": {"description": "Epic Description"}, | ||
}, | ||
} | ||
} | ||
} | ||
|
||
issue.permalink.return_value = "https://test.atlassian.net/browse/TEST-123" | ||
return issue | ||
|
||
|
||
def test_basic_auth(mock_jira): | ||
reader = JiraReader( | ||
email="[email protected]", | ||
api_token="test-token", | ||
server_url="example.atlassian.net", | ||
) | ||
|
||
mock_jira.assert_called_once_with( | ||
basic_auth=("[email protected]", "test-token"), | ||
server="https://example.atlassian.net", | ||
) | ||
|
||
|
||
def test_oauth2(mock_jira): | ||
reader = JiraReader(Oauth2={"cloud_id": "test-cloud", "api_token": "test-token"}) | ||
|
||
mock_jira.assert_called_once_with( | ||
options={ | ||
"server": "https://api.atlassian.com/ex/jira/test-cloud", | ||
"headers": {"Authorization": "Bearer test-token"}, | ||
} | ||
) | ||
|
||
|
||
def test_pat_auth(mock_jira): | ||
reader = JiraReader( | ||
PATauth={ | ||
"server_url": "https://example.atlassian.net", | ||
"api_token": "test-token", | ||
} | ||
) | ||
|
||
mock_jira.assert_called_once_with( | ||
options={ | ||
"server": "https://example.atlassian.net", | ||
"headers": {"Authorization": "Bearer test-token"}, | ||
} | ||
) | ||
|
||
|
||
def test_load_data_basic(mock_jira, mock_issue): | ||
# Setup mock JIRA instance | ||
jira_instance = mock_jira.return_value | ||
jira_instance.search_issues.return_value = [mock_issue] | ||
|
||
reader = JiraReader( | ||
email="[email protected]", | ||
api_token="test-token", | ||
server_url="example.atlassian.net", | ||
) | ||
|
||
documents = reader.load_data("project = TEST") | ||
|
||
# Verify search_issues was called correctly | ||
jira_instance.search_issues.assert_called_once_with( | ||
"project = TEST", startAt=0, maxResults=50 | ||
) | ||
|
||
# Verify returned document | ||
assert len(documents) == 1 | ||
doc = documents[0] | ||
assert doc.doc_id == "TEST-123" | ||
assert doc.text == "Test Summary \n Test Description" | ||
|
||
# Verify extra_info | ||
assert doc.extra_info["assignee"] == "Test Assignee" | ||
assert doc.extra_info["assignee_email"] == "[email protected]" | ||
assert doc.extra_info["reporter"] == "Test Reporter" | ||
assert doc.extra_info["reporter_email"] == "[email protected]" | ||
assert doc.extra_info["epic_key"] == "EPIC-1" | ||
assert doc.extra_info["epic_summary"] == "Epic Summary" | ||
assert doc.extra_info["epic_description"] == "Epic Description" | ||
|
||
|
||
def test_load_data_exclude_epics(mock_jira, mock_issue): | ||
# Modify mock issue to be an epic | ||
mock_issue.fields.issuetype.name = "Epic" | ||
jira_instance = mock_jira.return_value | ||
jira_instance.search_issues.return_value = [mock_issue] | ||
|
||
reader = JiraReader( | ||
email="[email protected]", | ||
api_token="test-token", | ||
server_url="example.atlassian.net", | ||
include_epics=False, | ||
) | ||
|
||
documents = reader.load_data("project = TEST") | ||
|
||
# Verify no documents returned since epics are excluded | ||
assert len(documents) == 0 | ||
|
||
|
||
def test_load_data_no_assignee_reporter(mock_jira, mock_issue): | ||
# Remove assignee and reporter | ||
mock_issue.fields.assignee = None | ||
mock_issue.fields.reporter = None | ||
jira_instance = mock_jira.return_value | ||
jira_instance.search_issues.return_value = [mock_issue] | ||
|
||
reader = JiraReader( | ||
email="[email protected]", | ||
api_token="test-token", | ||
server_url="example.atlassian.net", | ||
) | ||
|
||
documents = reader.load_data("project = TEST") | ||
|
||
# Verify document has empty assignee/reporter fields | ||
assert len(documents) == 1 | ||
doc = documents[0] | ||
assert doc.extra_info["assignee"] == "" | ||
assert doc.extra_info["assignee_email"] == "" | ||
assert doc.extra_info["reporter"] == "" | ||
assert doc.extra_info["reporter_email"] == "" |