Skip to content

Commit 5708490

Browse files
committed
Fixed formatting on TODO.rst
Added the first iterator! Also a test for it.
1 parent 74b0f26 commit 5708490

4 files changed

Lines changed: 90 additions & 62 deletions

File tree

TODO.rst

Lines changed: 62 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ unittests
1212
- We're currently at ~92% coverage. I want to get each module close to if not
1313
above 90% coverage before December. 100% by next year (at the latest).
1414

15-
+ The major hurtle now are github3.github and github3.repos. Both contain
16-
functions/functionality that will be very difficult to design test cases
17-
for, e.g., creating a pull request, creating a pull request from an
18-
existing issue, creating a commit object, etc.
15+
+ The major hurtle now are github3.github and github3.repos. Both contain
16+
functions/functionality that will be very difficult to design test cases
17+
for, e.g., creating a pull request, creating a pull request from an
18+
existing issue, creating a commit object, etc.
1919

2020
.. links
2121
@@ -48,61 +48,61 @@ Plan
4848

4949
::
5050

51-
def iter_issues(self, milestone=None, state=None, assignee=None,
52-
mentioned=None, labels=None, sort=None, direction=None,
53-
since=None, count=-1):
54-
"""Iterates over issues on this repo based upon parameters passed.
55-
56-
:param milestone: (optional), 'none', or '*'
57-
:type milestone: int
58-
:param state: (optional), accepted values: ('open', 'closed')
59-
:type state: str
60-
:param assignee: (optional), 'none', '*', or login name
61-
:type assignee: str
62-
:param mentioned: (optional), user's login name
63-
:type mentioned: str
64-
:param labels: (optional), comma-separated list of labels, e.g.
65-
'bug,ui,@high' :param sort: accepted values:
66-
('created', 'updated', 'comments', 'created')
67-
:type labels: str
68-
:param direction: (optional), accepted values: ('open', 'closed')
69-
:type direction: str
70-
:param since: (optional), ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ
71-
:type since: str
72-
:param int count: (optional), numer of issues to iterate over, -1
73-
iterates over all issues
74-
"""
75-
def issues_left():
76-
return count == -1 or count > 0
77-
78-
url = self._build_url('issues', base_url=self._api)
79-
80-
params = {}
81-
if milestone in ('*', 'none') or isinstance(milestone, int):
82-
params['milestone'] = str(milestone).lower()
83-
84-
if assignee:
85-
params['assignee'] = assignee
86-
87-
if mentioned:
88-
params['mentioned'] = mentioned
89-
90-
params.update(issue_params(None, state, labels, sort, direction,
91-
since))
92-
93-
count = int(count)
94-
95-
while issues_left() and url:
96-
response = self._get(url)
97-
json = self._json(response, 200)
98-
for i in json:
99-
yield Issue(i, self)
100-
count -= 1
101-
if count == 0:
102-
break
103-
104-
rel_next = response.links.get('rel_next', {})
105-
url = rel_next.get('url', '')
106-
107-
Naturally, ``issues_left()`` will not be nested into each iterator, but
108-
for the purposes of this example, it is easier to define it there.
51+
def iter_issues(self, milestone=None, state=None, assignee=None,
52+
mentioned=None, labels=None, sort=None, direction=None,
53+
since=None, count=-1):
54+
"""Iterates over issues on this repo based upon parameters passed.
55+
56+
:param milestone: (optional), 'none', or '*'
57+
:type milestone: int
58+
:param state: (optional), accepted values: ('open', 'closed')
59+
:type state: str
60+
:param assignee: (optional), 'none', '*', or login name
61+
:type assignee: str
62+
:param mentioned: (optional), user's login name
63+
:type mentioned: str
64+
:param labels: (optional), comma-separated list of labels, e.g.
65+
'bug,ui,@high' :param sort: accepted values:
66+
('created', 'updated', 'comments', 'created')
67+
:type labels: str
68+
:param direction: (optional), accepted values: ('open', 'closed')
69+
:type direction: str
70+
:param since: (optional), ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ
71+
:type since: str
72+
:param int count: (optional), numer of issues to iterate over, -1
73+
iterates over all issues
74+
"""
75+
def issues_left():
76+
return count == -1 or count > 0
77+
78+
url = self._build_url('issues', base_url=self._api)
79+
80+
params = {}
81+
if milestone in ('*', 'none') or isinstance(milestone, int):
82+
params['milestone'] = str(milestone).lower()
83+
84+
if assignee:
85+
params['assignee'] = assignee
86+
87+
if mentioned:
88+
params['mentioned'] = mentioned
89+
90+
params.update(issue_params(None, state, labels, sort, direction,
91+
since))
92+
93+
count = int(count)
94+
95+
while issues_left() and url:
96+
response = self._get(url)
97+
json = self._json(response, 200)
98+
for i in json:
99+
yield Issue(i, self)
100+
count -= 1
101+
if count == 0:
102+
break
103+
104+
rel_next = response.links.get('rel_next', {})
105+
url = rel_next.get('url', '')
106+
107+
Naturally, ``issues_left()`` will not be nested into each iterator, but for
108+
the purposes of this example, it is easier to define it there.

github3/issues.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,15 @@ def is_closed(self):
297297
return True
298298
return False
299299

300+
def iter_comments(self, number=-1):
301+
"""Iterate over the comments on this issue.
302+
303+
:param int number: (optional), number of comments to iterate over
304+
:returns: iterator of :class:`IssueComment <IssueComment>`
305+
"""
306+
url = self._build_url('comments', base_url=self._api)
307+
return self._iter(int(number), url, IssueComment)
308+
300309
def list_comments(self):
301310
"""List comments on this issue.
302311

github3/models.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,22 @@ def _api(self):
142142
def _api(self, uri):
143143
self._uri = urlparse(uri)
144144

145+
def _iter(self, count, url, cls):
146+
def remaining():
147+
return count == -1 or count > 0
148+
149+
while remaining() and url:
150+
response = self._get(url)
151+
json = self._json(response, 200)
152+
for i in json:
153+
yield cls(i, self)
154+
count -= 1
155+
if not remaining():
156+
break
157+
158+
rel_next = response.links.get('rel_next', {})
159+
url = rel_next.get('url', '')
160+
145161
@property
146162
def ratelimit_remaining(self):
147163
"""Number of requests before GitHub imposes a ratelimit."""

tests/test_issues.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ def test_milestone(self):
5757
if self.issue.milestone:
5858
expect(self.issue.milestone).isinstance(Milestone)
5959

60+
def test_iter_comments(self):
61+
expect(self.issue.iter_comments().next()).isinstance(IssueComment)
62+
6063
def test_list_comments(self):
6164
self.expect_list_of_class(self.issue.list_comments(), IssueComment)
6265

0 commit comments

Comments
 (0)