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
13 changes: 9 additions & 4 deletions jira/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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):
Expand Down
15 changes: 15 additions & 0 deletions tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down