10000 Split up Issue objects by omgjlk · Pull Request #751 · sigmavirus24/github3.py · GitHub
[go: up one dir, main page]

Skip to content

Split up Issue objects #751

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion github3/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ def issues_on(owner, repository, milestone=None, state=None, assignee=None,
Default: -1 returns all issues
:param str etag: (optional), ETag from a previous request to the same
endpoint
:returns: generator of :class:`Issue <github3.issues.Issue>`\ s
:returns: generator of :class:`ShortIssue <github3.issues.ShortIssue>`\ s

"""
if owner and repository:
Expand Down
24 changes: 20 additions & 4 deletions github3/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,24 @@ def to_pull(self):
return self._instance_or_null(pulls.PullRequest, json)


class EventIssue(GitHubCore):
"""The class that represents the issue information returned in Events."""

def _update_attributes(self, issue):
self.id = issue['id']
self.number = issue['number']
self.state = issue['state']
self.title = issue['title']
self.locked = issue['locked']
self._api = self.url = issue['url']

def to_issue(self):
"""Retrieve a full Issue object for this EventIssue."""
from . import issues
json = self._json(self._get(self.url), 200)
return self._instance_or_null(issues.Issue, json)


class Event(GitHubCore):

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


def _issuecomm(payload, session):
from .issues import Issue
from .issues.comment import IssueComment
if payload.get('issue'):
payload['issue'] = Issue(payload['issue'], session)
payload['issue'] = EventIssue(payload['issue'], session)
if payload.get('comment'):
payload['comment'] = IssueComment(payload['comment'], session)
return payload


def _issueevent(payload, session):
from .issues import Issue
if payload.get('issue'):
payload['issue'] = Issue(payload['issue'], session)
payload['issue'] = EventIssue(payload['issue'], session)
return payload


Expand Down
24 changes: 13 additions & 11 deletions github3/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
requires_app_credentials)
from .events import Event
from .gists import Gist
from .issues import Issue, issue_params
from .issues import ShortIssue, Issue, issue_params
from .models import GitHubCore
from .orgs import Membership, ShortOrganization, Organization, Team
from .projects import Project, ProjectCard, ProjectColumn
Expand Down Expand Up @@ -282,7 +282,8 @@ def create_issue(self, owner, repository, title, body=None, assignee=None,
<github3.issues.Milestone>` object, ``m.number`` is what you pass
here.)
:param list labels: (optional), List of label names.
:returns: :class:`Issue <github3.issues.Issue>` if successful
:returns: :class:`ShortIssue <github3.issues.ShortIssue>` if
successful
"""
repo = None
if owner and repository and title:
Expand All @@ -292,7 +293,7 @@ def create_issue(self, owner, repository, title, body=None, assignee=None,
return repo.create_issue(title, body, assignee, milestone,
labels, assignees)

return self._instance_or_null(Issue, None)
return self._instance_or_null(ShortIssue, None)

@requires_auth
def create_key(self, title, key, read_only=False):
Expand Down Expand Up @@ -650,12 +651,12 @@ def issues(self, filter='', state='', labels='', sort='', direction='',
Default: -1 returns all issues
:param str etag: (optional), ETag from a previous request to the same
endpoint
:returns: generator of :class:`Issue <github3.issues.Issue>`
:returns: generator of :class:`ShortIssue <github3.issues.ShortIssue>`
"""
url = self._build_url('issues')
# issue_params will handle the since parameter
params = issue_params(filter, state, labels, sort, direction, since)
return self._iter(int(number), url, Issue, params, etag)
return self._iter(int(number), url, ShortIssue, params, etag)

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

params = repo_issue_params(milestone, state, assignee, mentioned,
labels, sort, direction, since)
return self._iter(int(number), url, Issue, params=params,
return self._iter(int(number), url, ShortIssue, params=params,
etag=etag)
return iter([])

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

@requires_auth
def organizations(self, number=-1, etag=None):
Expand Down Expand Up @@ -1679,13 +1681,13 @@ def user_issues(self, filter='', state='', labels='', sort='',
Default: -1 returns all issues
:param str etag: (optional), ETag from a previous request to the same
endpoint
:returns: generator of :class:`Issue <github3.issues.Issue>`
:returns: generator of :class:`ShortIssue <github3.issues.ShortIssue>`
"""
url = self._build_url('user', 'issues')
# issue_params will handle the since parameter
params = issue_params(filter, state, labels, sort, direction, since)
params.update(per_page=per_page)
return self._iter(int(number), url, Issue, params, etag)
return self._iter(int(number), url, ShortIssue, params, etag)

@requires_auth
def user_teams(self, number=-1, etag=None):
Expand Down
3 changes: 2 additions & 1 deletion github3/issues/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@

from ..utils import timestamp_parameter
from .issue import Issue
from .issue import ShortIssue

__all__ = [Issue]
__all__ = ['Issue', 'ShortIssue']


def issue_params(filter, state, labels, sort, direction, since):
Expand Down
9 changes: 5 additions & 4 deletions github3/issues/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@ def _update_attributes(self, event):
self.commit_id = self._get_attribute(event, 'commit_id')
self._api = self._get_attribute(event, 'url')

#: :class:`Issue <github3.issues.Issue>` where this comment was made.
from .issue import Issue
self.issue = self._class_attribute(event, 'issue', Issue, self)
#: :class:`ShortIssue <github3.issues.ShortIssue>` where this comment
#: was made.
from .issue import ShortIssue
self.issue = self._class_attribute(event, 'issue', ShortIssue, self)

#: :class:`User <github3.users.User>` who caused this event.
#: :class:`User <github3.users.ShortUser>` who caused this event.
self.actor = self._class_attribute(
event, 'actor', users.ShortUser, self,
)
Expand Down
Loading
0