Skip to content

Commit bd650e6

Browse files
committed
expand issue comments method to include all available API options
1 parent 3a630c5 commit bd650e6

File tree

2 files changed

+62
-1
lines changed

2 files changed

+62
-1
lines changed

jira/client.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2281,19 +2281,35 @@ def assign_issue(self, issue: int | str, assignee: str | None) -> bool:
22812281
return True
22822282

22832283
@translate_resource_args
2284-
def comments(self, issue: int | str, expand: str | None = None) -> list[Comment]:
2284+
def comments(
2285+
self,
2286+
issue: int | str,
2287+
expand: str | None = None,
2288+
start_at: int | None = None,
2289+
max_results: int | None = None,
2290+
order_by: str | None = None,
2291+
) -> list[Comment]:
22852292
"""Get a list of comment Resources of the issue provided.
22862293
22872294
Args:
22882295
issue (Union[int, str]): the issue ID or key to get the comments from
22892296
expand (Optional[str]): extra information to fetch for each comment such as renderedBody and properties.
2297+
start_at (Optional[int]): index of the first comment to return (page offset)
2298+
max_results (Optional[int]): maximum number of comments to return
2299+
order_by (Optional[str]): order of the comments to return; should be 'created', '+created' or '-created'.
22902300
22912301
Returns:
22922302
List[Comment]
22932303
"""
22942304
params = {}
22952305
if expand is not None:
22962306
params["expand"] = expand
2307+
if start_at is not None:
2308+
params["startAt"] = str(start_at)
2309+
if max_results is not None:
2310+
params["maxResults"] = str(max_results)
2311+
if order_by is not None:
2312+
params["orderBy"] = order_by
22972313
r_json = self._get_json(f"issue/{issue}/comment", params=params)
22982314

22992315
comments = [

tests/resources/test_comment.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,51 @@ def test_comments(self):
2828
comments = self.jira.comments(issue)
2929
assert len(comments) == 0
3030

31+
def test_comments_start_at(self):
32+
comments_created = []
33+
for i in range(10):
34+
comments_created.append(
35+
self.jira.add_comment(self.issue_1_key, f"Comment #{i+1}")
36+
)
37+
comments = self.jira.comments(self.issue_1_key, start_at=5)
38+
self.assertEqual(len(comments), 5)
39+
self.assertEqual(comments[0].body, "Comment #6")
40+
for comment in comments_created:
41+
comment.delete()
42+
comments = self.jira.comments(self.issue_1_key)
43+
assert len(comments) == 0
44+
45+
def test_comments_max_results(self):
46+
comments_created = []
47+
for i in range(10):
48+
comments_created.append(
49+
self.jira.add_comment(self.issue_1_key, f"Comment #{i+1}")
50+
)
51+
comments = self.jira.comments(self.issue_1_key, max_results=4)
52+
self.assertEqual(len(comments), 4)
53+
self.assertEqual(comments[0].body, "Comment #1")
54+
for comment in comments_created:
55+
comment.delete()
56+
comments = self.jira.comments(self.issue_1_key)
57+
assert len(comments) == 0
58+
59+
def test_comments_order_by(self):
60+
comments_created = []
61+
for i in range(10):
62+
comments_created.append(
63+
self.jira.add_comment(self.issue_1_key, f"Comment #{i+1}")
64+
)
65+
comments = self.jira.comments(self.issue_1_key, order_by="created")
66+
self.assertEqual(comments[0].body, "Comment #1")
67+
comments = self.jira.comments(self.issue_1_key, order_by="+created")
68+
self.assertEqual(comments[0].body, "Comment #1")
69+
comments = self.jira.comments(self.issue_1_key, order_by="-created")
70+
self.assertEqual(comments[0].body, "Comment #10")
71+
for comment in comments_created:
72+
comment.delete()
73+
comments = self.jira.comments(self.issue_1_key)
74+
assert len(comments) == 0
75+
3176
def test_expanded_comments(self):
3277
comment1 = self.jira.add_comment(self.issue_1_key, "First comment")
3378
comment2 = self.jira.add_comment(self.issue_1_key, "Second comment")

0 commit comments

Comments
 (0)