From 630973fa5d16abe3ba69ae57dc1e5ec7d8afe3e2 Mon Sep 17 00:00:00 2001 From: Matt Keenan <67590045+matthewkeenan@users.noreply.github.com> Date: Tue, 18 May 2021 14:07:01 +0100 Subject: [PATCH] Allow expands for retrieval of comments (#1003) * Fix: #949 Allow expands for retrieval of comments * Move comment deletion before assert call * Black formating * Update tests.py * Update comment * Update client.py * Update client.py * Update client.py * Add type and return information * Update client.py for black style Co-authored-by: Sorin Sbarnea --- jira/client.py | 30 +++++++++++++++++++----------- tests/tests.py | 16 ++++++++++++++++ 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/jira/client.py b/jira/client.py index ff7961834..f785fac6d 100644 --- a/jira/client.py +++ b/jira/client.py @@ -1629,15 +1629,20 @@ def assign_issue(self, issue: Union[int, str], assignee: str) -> bool: return True @translate_resource_args - def comments(self, issue: str) -> List[Comment]: + def comments(self, issue: str, expand: Optional[str] = None) -> List[Comment]: """Get a list of comment Resources. - Args: - issue (str): the issue to get comments from - Returns: - List[Comment] + :param issue: the issue to get comments from + :type issue: str + :param expand: extra information to fetch for each comment + such as renderedBody and properties. + :type expand: str + :rtype: List[Comment] """ - r_json = self._get_json("issue/{}/comment".format(str(issue))) + params = {} + if expand is not None: + params["expand"] = expand + r_json = self._get_json("issue/{}/comment".format(str(issue)), params=params) comments = [ Comment(self._options, self._session, raw_comment_json) @@ -1646,14 +1651,17 @@ def comments(self, issue: str) -> List[Comment]: return comments @translate_resource_args - def comment(self, issue: str, comment: str) -> Comment: + def comment( + self, issue: str, comment: str, expand: Optional[str] = None + ) -> Comment: """Get a comment Resource from the server for the specified ID. - Args: - issue (str): ID or key of the issue to get the comment from - comment (str): ID of the comment to get + :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)) + return self._find_for_resource(Comment, (issue, comment), expand=expand) @translate_resource_args def add_comment( diff --git a/tests/tests.py b/tests/tests.py index c89ee422b..71fe1a619 100755 --- a/tests/tests.py +++ b/tests/tests.py @@ -1066,6 +1066,22 @@ 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" + ) + ret_comment2 = self.jira.comment(self.issue_1, comment2.id) + 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 + def test_add_comment(self): comment = self.jira.add_comment( self.issue_3,