From 6d9d5968e6b8b33dc2784d6fb4c027f4fa2ad6e9 Mon Sep 17 00:00:00 2001 From: IncandescentChrysalis <160749287+IncandescentChrysalis@users.noreply.github.com> Date: Mon, 16 Sep 2024 13:13:32 +0200 Subject: [PATCH 1/2] Add: Remote link --- .../jira/rest/api/2/issue/FOO-123/remotelink/POST | 7 +++++++ tests/test_jira.py | 13 +++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 tests/responses/jira/rest/api/2/issue/FOO-123/remotelink/POST diff --git a/tests/responses/jira/rest/api/2/issue/FOO-123/remotelink/POST b/tests/responses/jira/rest/api/2/issue/FOO-123/remotelink/POST new file mode 100644 index 000000000..3c3ab5457 --- /dev/null +++ b/tests/responses/jira/rest/api/2/issue/FOO-123/remotelink/POST @@ -0,0 +1,7 @@ +responses[ + '{"object": {"url": "https://confluence.atlassian-python.atlassian.net/display/Test", "title": "Unused link text", "status": {"resolved": false}}}' +] = { + "id": 10000, + "self": "https://atlassian-python.atlassian.net/rest/api/2/issue/FOO-123/remotelink/10000", + "application": {}, +} diff --git a/tests/test_jira.py b/tests/test_jira.py index 571bdfc03..0e6d2c1a8 100644 --- a/tests/test_jira.py +++ b/tests/test_jira.py @@ -92,3 +92,16 @@ def test_delete_issue_property_not_found(self): self.jira.get_issue_property("FOO-123", "NotFoundBar1") with self.assertRaises(HTTPError): self.jira.get_issue_property("FOONotFound-123", "NotFoundBar1") + + def test_post_issue_remotelink(self): + """Create a new remote link""" + resp = self.jira.create_or_update_issue_remote_links( + "FOO-123", + "https://confluence.atlassian-python.atlassian.net/display/Test", + "Unused link text", + ) + self.assertEqual(resp["id"], 10000) + self.assertEqual( + resp["self"], "https://atlassian-python.atlassian.net/rest/api/2/issue/FOO-123/remotelink/10000" + ) + self.assertDictEqual(resp["application"], {}) From f7e1a3e9b05a0b2a5329fa7c0b3858140116d691 Mon Sep 17 00:00:00 2001 From: IncandescentChrysalis <160749287+IncandescentChrysalis@users.noreply.github.com> Date: Wed, 3 Jul 2024 14:55:24 +0200 Subject: [PATCH 2/2] Add: Remote link: Application --- atlassian/jira.py | 4 ++++ .../rest/api/2/issue/FOO-123/remotelink/POST | 10 ++++++++ tests/test_jira.py | 24 +++++++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/atlassian/jira.py b/atlassian/jira.py index e3a89b0a4..acdd4d9ab 100644 --- a/atlassian/jira.py +++ b/atlassian/jira.py @@ -1776,6 +1776,7 @@ def create_or_update_issue_remote_links( icon_url=None, icon_title=None, status_resolved=False, + application: dict = {}, ): """ Add Remote Link to Issue, update url if global_id is passed @@ -1787,6 +1788,7 @@ def create_or_update_issue_remote_links( :param icon_url: str, OPTIONAL: Link to a 16x16 icon representing the type of the object in the remote system :param icon_title: str, OPTIONAL: Text for the tooltip of the main icon describing the type of the object in the remote system :param status_resolved: bool, OPTIONAL: if set to True, Jira renders the link strikethrough + :param application: dict, OPTIONAL: Application description """ base_url = self.resource_url("issue") url = "{base_url}/{issue_key}/remotelink".format(base_url=base_url, issue_key=issue_key) @@ -1802,6 +1804,8 @@ def create_or_update_issue_remote_links( if icon_title: icon_data["title"] = icon_title data["object"]["icon"] = icon_data + if application: + data["application"] = application return self.post(url, data=data) def get_issue_remote_link_by_id(self, issue_key, link_id): diff --git a/tests/responses/jira/rest/api/2/issue/FOO-123/remotelink/POST b/tests/responses/jira/rest/api/2/issue/FOO-123/remotelink/POST index 3c3ab5457..25fb6b130 100644 --- a/tests/responses/jira/rest/api/2/issue/FOO-123/remotelink/POST +++ b/tests/responses/jira/rest/api/2/issue/FOO-123/remotelink/POST @@ -5,3 +5,13 @@ responses[ "self": "https://atlassian-python.atlassian.net/rest/api/2/issue/FOO-123/remotelink/10000", "application": {}, } +responses[ + '{"object": {"url": "https://confluence.atlassian-python.atlassian.net/display/Test", "title": "Unused link text", "status": {"resolved": false}}, "globalId": "appId=00000000-0000-0000-0000-000000000000&pageId=0", "application": {"type": "com.atlassian.confluence", "name": "Confluence"}}' +] = { + "id": 10000, + "self": "https://atlassian-python.atlassian.net/rest/api/2/issue/FOO-123/remotelink/10000", + "application": { + "type": "com.atlassian.confluence", + "name": "Confluence", + }, +} diff --git a/tests/test_jira.py b/tests/test_jira.py index 0e6d2c1a8..04802e021 100644 --- a/tests/test_jira.py +++ b/tests/test_jira.py @@ -105,3 +105,27 @@ def test_post_issue_remotelink(self): resp["self"], "https://atlassian-python.atlassian.net/rest/api/2/issue/FOO-123/remotelink/10000" ) self.assertDictEqual(resp["application"], {}) + + def test_post_issue_remotelink_confluence(self): + """Create a new Confluence remote link""" + resp = self.jira.create_or_update_issue_remote_links( + "FOO-123", + "https://confluence.atlassian-python.atlassian.net/display/Test", + "Unused link text", + global_id="appId=00000000-0000-0000-0000-000000000000&pageId=0", + application={ + "type": "com.atlassian.confluence", + "name": "Confluence", + }, + ) + self.assertEqual(resp["id"], 10000) + self.assertEqual( + resp["self"], "https://atlassian-python.atlassian.net/rest/api/2/issue/FOO-123/remotelink/10000" + ) + self.assertDictEqual( + resp["application"], + { + "type": "com.atlassian.confluence", + "name": "Confluence", + }, + )