diff --git a/src/intelligence_layer/connectors/jira/jira_adapter.py b/src/intelligence_layer/connectors/jira/jira_adapter.py index ac3f66e4e..bb07194c8 100644 --- a/src/intelligence_layer/connectors/jira/jira_adapter.py +++ b/src/intelligence_layer/connectors/jira/jira_adapter.py @@ -49,10 +49,11 @@ def update_ticket(self, ticket_id: str, new_label: str) -> None: self.jira.issue(ticket_id).update(fields={"labels": [new_label]}) def _issue_to_ticket(self, issue: Issue) -> Ticket: + status_names = ["Done", "Fertig"] assert issue.fields.description return Ticket( jira_id=issue.id, - text=issue.fields.summary + issue.fields.description, + text=issue.fields.summary + "\n" + issue.fields.description, labels=issue.fields.labels, - is_active=True, # TODO + is_active=issue.fields.status.name not in status_names, ) diff --git a/tests/connectors/jira/test_jira_adapter.py b/tests/connectors/jira/test_jira_adapter.py index 47e16fc22..f547acdfc 100644 --- a/tests/connectors/jira/test_jira_adapter.py +++ b/tests/connectors/jira/test_jira_adapter.py @@ -8,6 +8,9 @@ from intelligence_layer.connectors.jira.jira_adapter import JiraAdapter +SUMMARY = "New issue 1 from jira-python" +DESCRIPTION = "Look into this one" + @fixture def jira_adapter() -> JiraAdapter: @@ -32,8 +35,8 @@ def setup(jira_adapter: JiraAdapter, project_id: str) -> Sequence[Issue]: issues.append( jira_adapter.jira.create_issue( project=project_id, - summary="New issue 1 from jira-python", - description="Look into this one", + summary=SUMMARY, + description=DESCRIPTION, issuetype={"name": "Bug"}, labels=["old_label"], ) @@ -92,6 +95,37 @@ def test_update_ticket(jira_adapter: JiraAdapter, project_id: str) -> None: updated_issues = jira_adapter.jira.search_issues( f"project={project_id} and id={id}" ) - for issue in updated_issues: - assert isinstance(issue, Issue) - assert label in issue.fields.labels + assert isinstance(updated_issues, list) + assert isinstance(updated_issues[0], Issue) + assert label in updated_issues[0].fields.labels + + +@pytest.mark.skip(reason="currently no CI User for Jira configured") +def test_issue_to_ticket(jira_adapter: JiraAdapter, project_id: str) -> None: + issues = setup(jira_adapter, project_id) + issue = issues[0] + + ticket = jira_adapter._issue_to_ticket(issue) + + assert ticket.jira_id == issue.id + assert ticket.text == SUMMARY + "\n" + DESCRIPTION + assert ticket.labels == issue.fields.labels + assert ticket.is_active + + +@pytest.mark.skip(reason="currently no CI User for Jira configured") +def test_ticket_not_active(jira_adapter: JiraAdapter, project_id: str) -> None: + issues = setup(jira_adapter, project_id) + issue = issues[0] + jira_adapter.jira.transition_issue(issue, "Fertig") + updated_issues = jira_adapter.jira.search_issues( + f"project={project_id} and id={issue.id}" + ) + assert isinstance(updated_issues, list) + + ticket = jira_adapter._issue_to_ticket(updated_issues[0]) + + assert ticket.jira_id == issue.id + assert ticket.text == SUMMARY + "\n" + DESCRIPTION + assert ticket.labels == issue.fields.labels + assert not ticket.is_active