10000 Merge pull request #382 from antoine-g/feature/issue-comments-params · vikasmulaje/github3.py@cddf376 · GitHub
[go: up one dir, main page]

Skip to content

Commit cddf376

Browse files
committed
Merge pull request sigmavirus24#382 from antoine-g/feature/issue-comments-params
Add params support to Issue.comments()
2 parents 66e0899 + babd0cd commit cddf376

File tree

3 files changed

+33
-4
lines changed

3 files changed

+33
-4
lines changed

AUTHORS.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,5 @@ Contributors
9090
- Ryan Pitts (@ryanpitts)
9191

9292
- Jürgen Hermann (@jhermann)
93+
94+
- Antoine Giraudmaillet (@antoine-g)

github3/issues/comment.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# -*- coding: utf-8 -*-
22
from __future__ import unicode_literals
33

4+
from ..utils import timestamp_parameter
45
from ..models import BaseComment
56
from ..users import User
67

@@ -36,3 +37,19 @@ def _update_attributes(self, comment):
3637

3738
def _repr(self):
3839
return '<Issue Comment [{0}]>'.format(self.user.login)
40+
41+
42+
def issue_comment_params(sort, direction, since):
43+
params = {}
44+
45+
if sort in ('created', 'updated'):
46+
params['sort'] = sort
47+
48+
if direction in ('asc', 'desc'):
49+
params['direction'] = direction
50+
51+
since = timestamp_parameter(since)
52+
if since:
53+
params['since'] = since
54+
55+
return params

github3/issues/issue.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from re import match
55
from json import dumps
66
from ..decorators import requires_auth
7-
from .comment import IssueComment
7+
from .comment import IssueComment, issue_comment_params
88
from .event import IssueEvent
99
from .label import Label
1010
from .milestone import Milestone
@@ -155,15 +155,25 @@ def comment(self, id_num):
155155
json = self._json(self._get(url), 200)
156156
return self._instance_or_null(IssueComment, json)
157157

158-
def comments(self, number=-1):
159-
r"""Iterate over the comments on this issue.
158+
def comments(self, number=-1, sort='', direction='', since=None):
159+
"""Iterate over the comments on this issue.
160160
161161
:param int number: (optional), number of comments to iterate over
162+
Default: -1 returns all comments
163+
:param str sort: accepted valuees: ('created', 'updated')
164+
api-default: created
165+
:param str direction: accepted values: ('asc', 'desc')
166+
Ignored without the sort parameter
167+
:param since: (optional), Only issues after this date will
168+
be returned. This can be a `datetime` or an ISO8601 formatted
169+
date string, e.g., 2012-05-20T23:10:27Z
170+
:type since: datetime or string
162171
:returns: iterator of
163172
:class:`IssueComment <github3.issues.comment.IssueComment>`\ s
164173
"""
165174
url = self._build_url('comments', base_url=self._api)
166-
return self._iter(int(number), url, IssueComment)
175+
params = issue_comment_params(sort, direction, since)
176+
return self._iter(int(number), url, IssueComment, params)
167177

168178
@requires_auth
169179
def create_comment(self, body):

0 commit comments

Comments
 (0)
0