Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow expands for retrieval of comments #1003

Merged
merged 12 commits into from
May 18, 2021
30 changes: 19 additions & 11 deletions jira/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1618,15 +1618,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)
Expand All @@ -1635,14 +1640,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(
Expand Down
16 changes: 16 additions & 0 deletions tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
studioj marked this conversation as resolved.
Show resolved Hide resolved
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,
Expand Down