From 9cfbd915ebffd6fd48ce867fac8eac65132e528a Mon Sep 17 00:00:00 2001 From: Matt Keenan Date: Fri, 26 Feb 2021 07:46:08 -0800 Subject: [PATCH 01/10] Fix: #949 Allow expands for retrieval of comments --- jira/client.py | 13 +++++++++---- tests/tests.py | 15 +++++++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/jira/client.py b/jira/client.py index 57b2d1839..06f8c3ad0 100644 --- a/jira/client.py +++ b/jira/client.py @@ -1592,14 +1592,18 @@ def assign_issue(self, issue, assignee): return True @translate_resource_args - def comments(self, issue): + def comments(self, issue, expand=None): """Get a list of comment Resources. :param issue: the issue to get comments from + :param expand: extra information to fetch inside each comment :type issue: str :rtype: List[Comment] """ - r_json = self._get_json("issue/" + str(issue) + "/comment") + params = {} + if expand is not None: + params["expand"] = expand + r_json = self._get_json("issue/" + str(issue) + "/comment", params=params) comments = [ Comment(self._options, self._session, raw_comment_json) @@ -1608,13 +1612,14 @@ def comments(self, issue): return comments @translate_resource_args - def comment(self, issue, comment): + def comment(self, issue, comment, expand=None): """Get a comment Resource from the server for the specified ID. :param issue: ID or key of the issue to get the comment from :param comment: ID of the comment to get + :param expand: extra information to fetch for comment """ - return self._find_for_resource(Comment, (issue, comment)) + return self._find_for_resource(Comment, (issue, comment), expand=expand) @translate_resource_args def add_comment(self, issue, body, visibility=None, is_internal=False): diff --git a/tests/tests.py b/tests/tests.py index 32f1d6758..2f26224fd 100755 --- a/tests/tests.py +++ b/tests/tests.py @@ -1095,6 +1095,21 @@ def test_comments(self): comments = self.jira.comments(issue) assert len(comments) == 0 + def test_expanded_comments(self): + comment1 = self.jira.add_comment(self.issue_1, "First comment") + comment2 = self.jira.add_comment(self.issue_1, "Second comment") + comments = self.jira.comments(self.issue_1, expand="renderedBody") + self.assertTrue(hasattr(comments[0], "renderedBody")) + ret_comment1 = self.jira.comment(self.issue_1, comment1.id, + expand="renderedBody") + self.assertTrue(hasattr(ret_comment1, "renderedBody")) + ret_comment2 = self.jira.comment(self.issue_1, comment2.id) + self.assertFalse(hasattr(ret_comment2, "renderedBody")) + comment1.delete() + comment2.delete() + comments = self.jira_comments(self.issue_1) + assert len(comments) == 0 + def test_add_comment(self): comment = self.jira.add_comment( self.issue_3, From e46a9643940c61f0d684a014e6778ff42a3bf1e9 Mon Sep 17 00:00:00 2001 From: Matt Keenan <67590045+matthewkeenan@users.noreply.github.com> Date: Mon, 10 May 2021 13:38:43 +0100 Subject: [PATCH 02/10] Move comment deletion before assert call --- tests/tests.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/tests.py b/tests/tests.py index 503476da3..2961372ca 100755 --- a/tests/tests.py +++ b/tests/tests.py @@ -1102,11 +1102,11 @@ def test_expanded_comments(self): self.assertTrue(hasattr(comments[0], "renderedBody")) ret_comment1 = self.jira.comment(self.issue_1, comment1.id, expand="renderedBody") - self.assertTrue(hasattr(ret_comment1, "renderedBody")) ret_comment2 = self.jira.comment(self.issue_1, comment2.id) - self.assertFalse(hasattr(ret_comment2, "renderedBody")) comment1.delete() comment2.delete() + self.assertTrue(hasattr(ret_comment1, "renderedBody")) + self.assertFalse(hasattr(ret_comment2, "renderedBody")) comments = self.jira_comments(self.issue_1) assert len(comments) == 0 From 64eff1a5022cfdc7656065e47f3df875db6e8b30 Mon Sep 17 00:00:00 2001 From: Matt Keenan <67590045+matthewkeenan@users.noreply.github.com> Date: Mon, 10 May 2021 19:51:22 +0100 Subject: [PATCH 03/10] Black formating --- tests/tests.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/tests.py b/tests/tests.py index 2961372ca..573979427 100755 --- a/tests/tests.py +++ b/tests/tests.py @@ -1100,8 +1100,9 @@ def test_expanded_comments(self): comment2 = self.jira.add_comment(self.issue_1, "Second comment") comments = self.jira.comments(self.issue_1, expand="renderedBody") self.assertTrue(hasattr(comments[0], "renderedBody")) - ret_comment1 = self.jira.comment(self.issue_1, comment1.id, - expand="renderedBody") + ret_comment1 = self.jira.comment( + self.issue_1, comment1.id, expand="renderedBody" + ) ret_comment2 = self.jira.comment(self.issue_1, comment2.id) comment1.delete() comment2.delete() From a80af0d91a3bbfc5987fe470f447951b48065e36 Mon Sep 17 00:00:00 2001 From: Matt Keenan <67590045+matthewkeenan@users.noreply.github.com> Date: Mon, 10 May 2021 20:13:20 +0100 Subject: [PATCH 04/10] Update tests.py --- tests/tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/tests.py b/tests/tests.py index 573979427..7b17ee09b 100755 --- a/tests/tests.py +++ b/tests/tests.py @@ -1108,7 +1108,7 @@ def test_expanded_comments(self): comment2.delete() self.assertTrue(hasattr(ret_comment1, "renderedBody")) self.assertFalse(hasattr(ret_comment2, "renderedBody")) - comments = self.jira_comments(self.issue_1) + comments = self.jira.comments(self.issue_1) assert len(comments) == 0 def test_add_comment(self): From 5ab0aa0910bd6b0cf427df3f798784d501e8e92e Mon Sep 17 00:00:00 2001 From: Matt Keenan <67590045+matthewkeenan@users.noreply.github.com> Date: Thu, 13 May 2021 17:57:14 +0100 Subject: [PATCH 05/10] Update comment --- jira/client.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/jira/client.py b/jira/client.py index 53fd32e36..02a583a91 100644 --- a/jira/client.py +++ b/jira/client.py @@ -1595,8 +1595,10 @@ def comments(self, issue, expand=None): """Get a list of comment Resources. :param issue: the issue to get comments from - :param expand: extra information to fetch inside each comment :type issue: str + :param expand: extra information to fetch for each comment + such as renderedBody and properties. + :type expand: comma delimted str :rtype: List[Comment] """ params = {} @@ -1617,6 +1619,7 @@ def comment(self, issue, comment, expand=None): :param issue: ID or key of the issue to get the comment from :param comment: ID of the comment to get :param expand: extra information to fetch for comment + such as renderedBody and properties. """ return self._find_for_resource(Comment, (issue, comment), expand=expand) From c95d797059a143508693b827293c64122f1707c9 Mon Sep 17 00:00:00 2001 From: Matt Keenan <67590045+matthewkeenan@users.noreply.github.com> Date: Thu, 13 May 2021 18:12:30 +0100 Subject: [PATCH 06/10] Update client.py --- jira/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jira/client.py b/jira/client.py index 02a583a91..be67a28ec 100644 --- a/jira/client.py +++ b/jira/client.py @@ -1598,7 +1598,7 @@ def comments(self, issue, expand=None): :type issue: str :param expand: extra information to fetch for each comment such as renderedBody and properties. - :type expand: comma delimted str + :type expand: comma delimited str :rtype: List[Comment] """ params = {} From 048ed7485abb9ffd1186f7664391c727612170df Mon Sep 17 00:00:00 2001 From: Matt Keenan <67590045+matthewkeenan@users.noreply.github.com> Date: Thu, 13 May 2021 18:24:47 +0100 Subject: [PATCH 07/10] Update client.py --- jira/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jira/client.py b/jira/client.py index be67a28ec..a4f9aab4c 100644 --- a/jira/client.py +++ b/jira/client.py @@ -1598,7 +1598,7 @@ def comments(self, issue, expand=None): :type issue: str :param expand: extra information to fetch for each comment such as renderedBody and properties. - :type expand: comma delimited str + :type expand: str :rtype: List[Comment] """ params = {} From d03d5c13760eeca9101b9f854b3c12edbfb484e6 Mon Sep 17 00:00:00 2001 From: Sorin Sbarnea Date: Sun, 16 May 2021 10:29:05 +0100 Subject: [PATCH 08/10] Update client.py --- jira/client.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jira/client.py b/jira/client.py index dac4c5945..d1a8b35af 100644 --- a/jira/client.py +++ b/jira/client.py @@ -1618,7 +1618,7 @@ def assign_issue(self, issue: Union[int, str], assignee: str) -> bool: return True @translate_resource_args - def comments(self, issue, expand=None): + def comments(self, issue: str, expand=None): """Get a list of comment Resources. :param issue: the issue to get comments from @@ -1640,7 +1640,7 @@ def comments(self, issue, expand=None): return comments @translate_resource_args - def comment(self, issue, comment, expand=None): + def comment(self, issue: str, comment, expand=None): """Get a comment Resource from the server for the specified ID. :param issue: ID or key of the issue to get the comment from From 8e2c9464bf320f53f8abd93cc230f2878ad5b20f Mon Sep 17 00:00:00 2001 From: Matt Keenan Date: Mon, 17 May 2021 15:42:49 -0700 Subject: [PATCH 09/10] Add type and return information --- jira/client.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jira/client.py b/jira/client.py index d1a8b35af..c017c3de6 100644 --- a/jira/client.py +++ b/jira/client.py @@ -1618,7 +1618,7 @@ def assign_issue(self, issue: Union[int, str], assignee: str) -> bool: return True @translate_resource_args - def comments(self, issue: str, expand=None): + def comments(self, issue: str, expand: Optional[str] = None) -> List[Comment]: """Get a list of comment Resources. :param issue: the issue to get comments from @@ -1640,7 +1640,7 @@ def comments(self, issue: str, expand=None): return comments @translate_resource_args - def comment(self, issue: str, comment, expand=None): + def comment(self, issue: str, comment: str, expand: Optional[str] = None) -> Comment: """Get a comment Resource from the server for the specified ID. :param issue: ID or key of the issue to get the comment from From 2725e9b3c84cda29c8c48eab64d8c46582d1b395 Mon Sep 17 00:00:00 2001 From: Matt Keenan Date: Mon, 17 May 2021 15:56:51 -0700 Subject: [PATCH 10/10] Update client.py for black style --- jira/client.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/jira/client.py b/jira/client.py index c017c3de6..613b9d49c 100644 --- a/jira/client.py +++ b/jira/client.py @@ -1640,7 +1640,9 @@ def comments(self, issue: str, expand: Optional[str] = None) -> List[Comment]: return comments @translate_resource_args - def comment(self, issue: str, comment: str, expand: Optional[str] = None) -> Comment: + def comment( + self, issue: str, comment: str, expand: Optional[str] = None + ) -> Comment: """Get a comment Resource from the server for the specified ID. :param issue: ID or key of the issue to get the comment from