Skip to content

Commit

Permalink
Allow expands for retrieval of comments (#1003)
Browse files Browse the repository at this point in the history
* 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 <sorin.sbarnea@gmail.com>
  • Loading branch information
matthewkeenan and ssbarnea authored May 18, 2021
1 parent de73cfd commit 630973f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 11 deletions.
30 changes: 19 additions & 11 deletions jira/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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(
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()
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

0 comments on commit 630973f

Please sign in to comment.