Skip to content

Commit af8ea28

Browse files
committed
Split up Issue objects
This creates 3 classes; one for iterations (Short), one for direct GETs (Issue), and one for events (EventIssue). Most attributes are directly assigned, except where otherwise commented. Some cassettes needed to be updated for the relatively new 'assignees' attribute that now comes back. A sample json needed to be updated as well. Cassettes that needed updated that were associated with authenticated calls got the calls updated to use auto_login as well. Some cassettes will break between older requests and newer, so tag those tests accordingly. Allow the tests to work in older requests land for now. The search tests needed to be updated as well, label name changed and syntax changed slightly. Related-to #670 Signed-off-by: Jesse Keating <jkeating@j2solutions.net>
1 parent 96ab0e2 commit af8ea28

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+202
-142
lines changed

github3/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ def issues_on(owner, repository, milestone=None, state=None, assignee=None,
266266
Default: -1 returns all issues
267267
:param str etag: (optional), ETag from a previous request to the same
268268
endpoint
269-
:returns: generator of :class:`Issue <github3.issues.Issue>`\ s
269+
:returns: generator of :class:`ShortIssue <github3.issues.ShortIssue>`\ s
270270
271271
"""
272272
if owner and repository:

github3/events.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,24 @@ def to_pull(self):
6868
return self._instance_or_null(pulls.PullRequest, json)
6969

7070

71+
class EventIssue(GitHubCore):
72+
"""The class that represents the issue information returned in Events."""
73+
74+
def _update_attributes(self, issue):
75+
self.id = issue['id']
76+
self.number = issue['number']
77+
self.state = issue['state']
78+
self.title = issue['title']
79+
self.locked = issue['locked']
80+
self._api = self.url = issue['url']
81+
82+
def to_issue(self):
83+
"""Retrieve a full Issue object for this EventIssue."""
84+
from . import issues
85+
json = self._json(self._get(self.url), 200)
86+
return self._instance_or_null(issues.Issue, json)
87+
88+
7189
class Event(GitHubCore):
7290

7391
"""The :class:`Event <Event>` object. It structures and handles the data
@@ -156,19 +174,17 @@ def _gist(payload, session):
156174

157175

158176
def _issuecomm(payload, session):
159-
from .issues import Issue
160177
from .issues.comment import IssueComment
161178
if payload.get('issue'):
162-
payload['issue'] = Issue(payload['issue'], session)
179+
payload['issue'] = EventIssue(payload['issue'], session)
163180
if payload.get('comment'):
164181
payload['comment'] = IssueComment(payload['comment'], session)
165182
return payload
166183

167184

168185
def _issueevent(payload, session):
169-
from .issues import Issue
170186
if payload.get('issue'):
171-
payload['issue'] = Issue(payload['issue'], session)
187+
payload['issue'] = EventIssue(payload['issue'], session)
172188
return payload
173189

174190

github3/github.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
requires_app_credentials)
1616
from .events import Event
1717
from .gists import Gist
18-
from .issues import Issue, issue_params
18+
from .issues import ShortIssue, Issue, issue_params
1919
from .models import GitHubCore
2020
from .orgs import Membership, ShortOrganization, Organization, Team
2121
from .projects import Project, ProjectCard, ProjectColumn
@@ -282,7 +282,8 @@ def create_issue(self, owner, repository, title, body=None, assignee=None,
282282
<github3.issues.Milestone>` object, ``m.number`` is what you pass
283283
here.)
284284
:param list labels: (optional), List of label names.
285-
:returns: :class:`Issue <github3.issues.Issue>` if successful
285+
:returns: :class:`ShortIssue <github3.issues.ShortIssue>` if
286+
successful
286287
"""
287288
repo = None
288289
if owner and repository and title:
@@ -292,7 +293,7 @@ def create_issue(self, owner, repository, title, body=None, assignee=None,
292293
return repo.create_issue(title, body, assignee, milestone,
293294
labels, assignees)
294295

295-
return self._instance_or_null(Issue, None)
296+
return self._instance_or_null(ShortIssue, None)
296297

297298
@requires_auth
298299
def create_key(self, title, key, read_only=False):
@@ -650,12 +651,12 @@ def issues(self, filter='', state='', labels='', sort='', direction='',
650651
Default: -1 returns all issues
651652
:param str etag: (optional), ETag from a previous request to the same
652653
endpoint
653-
:returns: generator of :class:`Issue <github3.issues.Issue>`
654+
:returns: generator of :class:`ShortIssue <github3.issues.ShortIssue>`
654655
"""
655656
url = self._build_url('issues')
656657
# issue_params will handle the since parameter
657658
params = issue_params(filter, state, labels, sort, direction, since)
658-
return self._iter(int(number), url, Issue, params, etag)
659+
return self._iter(int(number), url, ShortIssue, params, etag)
659660

660661
def issues_on(self, username, repository, milestone=None, state=None,
661662
assignee=None, mentioned=None, labels=None, sort=None,
@@ -689,14 +690,15 @@ def issues_on(self, username, repository, milestone=None, state=None,
689690
Default: -1 returns all issues
690691
:param str etag: (optional), ETag from a previous request to the same
691692
endpoint
692-
:returns: generator of :class:`Issue <github3.issues.Issue>`\ s
693+
:returns: generator of
694+
:class:`ShortIssue <github3.issues.ShortIssue>`\ s
693695
"""
694696
if username and repository:
695697
url = self._build_url('repos', username, repository, 'issues')
696698

697699
params = repo_issue_params(milestone, state, assignee, mentioned,
698700
labels, sort, direction, since)
699-
return self._iter(int(number), url, Issue, params=params,
701+
return self._iter(int(number), url, ShortIssue, params=params,
700702
etag=etag)
701703
return iter([])
702704

@@ -907,12 +909,12 @@ def organization_issues(self, name, filter='', state='', labels='',
907909
-1, returns all available issues
908910
:param str etag: (optional), ETag from a previous request to the same
909911
endpoint
910-
:returns: generator of :class:`Issue <github3.issues.Issue>`
912+
:returns: generator of :class:`ShortIssue <github3.issues.ShortIssue>`
911913
"""
912914
url = self._build_url('orgs', name, 'issues')
913915
# issue_params will handle the since parameter
914916
params = issue_params(filter, state, labels, sort, direction, since)
915-
return self._iter(int(number), url, Issue, params, etag)
917+
return self._iter(int(number), url, ShortIssue, params, etag)
916918

917919
@requires_auth
918920
def organizations(self, number=-1, etag=None):
@@ -1679,13 +1681,13 @@ def user_issues(self, filter='', state='', labels='', sort='',
16791681
Default: -1 returns all issues
16801682
:param str etag: (optional), ETag from a previous request to the same
16811683
endpoint
1682-
:returns: generator of :class:`Issue <github3.issues.Issue>`
1684+
:returns: generator of :class:`ShortIssue <github3.issues.ShortIssue>`
16831685
"""
16841686
url = self._build_url('user', 'issues')
16851687
# issue_params will handle the since parameter
16861688
params = issue_params(filter, state, labels, sort, direction, since)
16871689
params.update(per_page=per_page)
1688-
return self._iter(int(number), url, Issue, params, etag)
1690+
return self._iter(int(number), url, ShortIssue, params, etag)
16891691

16901692
@requires_auth
16911693
def user_teams(self, number=-1, etag=None):

github3/issues/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99

1010
from ..utils import timestamp_parameter
1111
from .issue import Issue
12+
from .issue import ShortIssue
1213

13-
__all__ = [Issue]
14+
__all__ = ['Issue', 'ShortIssue']
1415

1516

1617
def issue_params(filter, state, labels, sort, direction, since):

github3/issues/event.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,12 @@ def _update_attributes(self, event):
3232
self.commit_id = self._get_attribute(event, 'commit_id')
3333
self._api = self._get_attribute(event, 'url')
3434

35-
#: :class:`Issue <github3.issues.Issue>` where this comment was made.
36-
from .issue import Issue
37-
self.issue = self._class_attribute(event, 'issue', Issue, self)
35+
#: :class:`ShortIssue <github3.issues.ShortIssue>` where this comment
36+
#: was made.
37+
from .issue import ShortIssue
38+
self.issue = self._class_attribute(event, 'issue', ShortIssue, self)
3839

39-
#: :class:`User <github3.users.User>` who caused this event.
40+
#: :class:`User <github3.users.ShortUser>` who caused this event.
4041
self.actor = self._class_attribute(
4142
event, 'actor', users.ShortUser, self,
4243
)

0 commit comments

Comments
 (0)