8000 Update github3.issues.event to be consistent · pythonthings/github3.py@fd23bb5 · GitHub
[go: up one dir, main page]

Skip to content

Commit fd23bb5

Browse files
committed
Update github3.issues.event to be consistent
This also acknowledges the difference between /repos/:owner/:name/issues/:number/events and /repos/:owner/:name/issues/events with separate classes to represent each
1 parent 787e9b0 commit fd23bb5

File tree

4 files changed

+85
-51
lines changed

4 files changed

+85
-51
lines changed

github3/issues/event.py

Lines changed: 80 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,108 @@
11
# -*- coding: utf-8 -*-
2+
"""Issue events logic."""
23
from __future__ import unicode_literals
34

45
from .. import users
56
from ..models import GitHubCore
67

78

89
class IssueEvent(GitHubCore):
9-
"""The :class:`IssueEvent <IssueEvent>` object. This specifically deals
10-
with events described in the
11-
`Issues\>Events <http://developer.github.com/v3/issues/events>`_ section of
12-
the GitHub API.
10+
"""Representation of an event from a specific issue.
1311
14-
Two event instances can be checked like so::
12+
This object will be instantiated from calling
13+
:meth:`~github3.issues.issue.Issue.events` which calls
14+
https://developer.github.com/v3/issues/events/#list-events-for-an-issue
1515
16-
e1 == e2
17-
e1 != e2
16+
See also: http://developer.github.com/v3/issues/events
1817
19-
And is equivalent to::
18+
This object has the following attributes:
2019
21-
e1.commit_id == e2.commit_id
22-
e1.commit_id != e2.commit_id
20+
.. attribute:: actor
2321
24-
"""
25-
def _update_attributes(self, event):
26-
# The type of event:
27-
# ('closed', 'reopened', 'subscribed', 'merged', 'referenced',
28-
# 'mentioned', 'assigned')
29-
#: The type of event, e.g., closed
30-
self.event = self._get_attribute(event, 'event')
31-
#: SHA of the commit.
32-
self.commit_id = self._get_attribute(event, 'commit_id')
33-
self._api = self._get_attribute(event, 'url')
34-
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)
39-
40-
#: :class:`User <github3.users.ShortUser>` who caused this event.
41-
self.actor = self._class_attribute(
42-
event, 'actor', users.ShortUser, self,
43-
)
22+
A :class:`~github3.users.ShortUser` representing the user who
23+
generated this event.
4424
45-
#: Number of comments
46-
self.comments = self._get_attribute(event, 'comments')
25+
.. attribute:: commit_id
4726
48-
#: datetime object representing when the event was created.
49-
self.created_at = self._strptime_attribute(event, 'created_at')
27+
The string SHA of a commit that referenced the parent issue. If there
28+
was no commit referencing this issue, then this will be ``None``.
5029
51-
#: Dictionary of links for the pull request
52-
self.pull_request = self._get_attribute(event, 'pull_request', {})
30+
.. attribute:: commit_url
5331
54-
#: Dictionary containing label details
55-
self.label = self._get_attribute(event, 'label', {})
32+
The URL to retrieve commit information from the API for the commit
33+
that references the parent issue. If there was no commit, this will be
34+
``None``.
5635
57-
#: The integer ID of the event
58-
self.id = self._get_attribute(event, 'id')
36+
.. attribute:: created_at
5937
60-
#: :class:`User <github3.users.User>` that is assigned
61-
self.assignee = self._class_attribute(
62-
event, 'assignee', users.ShortUser, self,
63-
)
38+
A :class:`~datetime.datetime` object representing the date and time
39+
this event occurred.
40+
41+
.. attribute:: event
42+
43+
The issue-specific action that generated this event. Some examples
44+
are:
6445
65-
#: Dictionary containing milestone details
66-
self.milestone = self._get_attribute(event, 'milestone', {})
46+
- closed
47+
- reopened
48+
- subscribed
49+
- merged
50+
- referenced
51+
- mentioned
52+
- assigned
6753
68-
#: Dictionary containing to and from attributes
69-
self.rename = self._get_attribute(event, 'rename', {})
54+
See `this list of events`_ for a full listing.
7055
56+
.. attribute:: id
57+
58+
The unique identifier for this event.
59+
60+
.. _this list of events:
61+
https://developer.github.com/v3/issues/events/#events-1
62+
"""
63+
64+
def _update_attributes(self, event):
65+
self._api = event['url']
66+
self.actor = users.ShortUser(event['actor'], self)
67+
self.commit_id = event['commit_id']
68+
self.commit_url = event['commit_url']
69+
self.created_at = event['created_at']
70+
self.event = event['event']
71+
self.id = self._get_attribute(event, 'id')
7172
self._uniq = self.commit_id
7273

7374
def _repr(self):
7475
return '<Issue Event [{0} by {1}]>'.format(
7576
self.event, self.actor
7677
)
78+
79+
80+
class RepositoryIssueEvent(IssueEvent):
81+
"""Representation of an issue event on the repository level.
82+
83+
This object will be instantiated from calling
84+
:meth:`~github3.repos.repo.Repository.issue_events` or
85+
:meth:`~github3.repos.repo.ShortRepository.issue_events`which call
86+
https://developer.github.com/v3/issues/events/#list-events-for-a-repository
87+
88+
See also: http://developer.github.com/v3/issues/events
89+
90+
This object has all of the attributes of
91+
:class:`~github3.issues.event.IssueEvent` and the following:
92+
93+
.. attribute:: issue
94+
95+
A :class:`~github3.issues.issue.ShortIssue` representing the issue
96+
where this event originated from.
97+
98+
"""
99+
100+
def _update_attributes(self, event):
101+
super(RepositoryIssueEvent, self)._update_attributes(event)
102+
from . import issue
103+
self.issue = issue.ShortIssue(event['issue'], self)
104+
105+
def _repr(self):
106+
return '<Repository Issue Event on #{} [{} by {}]>'.format(
107+
self.issue.number, self.event, self.actor.login
108+
)

github3/repos/repo.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212

1313
from uritemplate import URITemplate
1414

15+
from ..issues import event as ievent
1516
from .. import users
1617

1718
from ..decorators import requires_auth
1819
from ..events import Event
1920
from ..git import Blob, Commit, Reference, Tag, Tree
2021
from ..issues import ShortIssue, Issue, issue_params
21-
from ..issues.event import IssueEvent
2222
from ..issues.label import Label
2323
from ..issues.milestone import Milestone
2424
from .. import licenses
@@ -1229,7 +1229,8 @@ def issue_events(self, number=-1, etag=None):
12291229
:class:`IssueEvent <github3.issues.event.IssueEvent>`\ s
12301230
"""
12311231
url = self._build_url('issues', 'events', base_url=self._api)
1232-
return self._iter(int(number), url, IssueEvent, etag=etag)
1232+
return self._iter(int(number), url, ievent.RepositoryIssueEvent,
1233+
etag=etag)
12331234

12341235
def issues(self, milestone=None, state=None, assignee=None, mentioned=None,
12351236
labels=None, sort=None, direction=None, since=None, number=-1,

tests/integration/test_repos_repo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -803,7 +803,7 @@ def test_issue_events(self):
803803
events = list(repository.issue_events(number=50))
804804

805805
for ev in events:
806-
assert isinstance(ev, github3.issues.event.IssueEvent)
806+
assert isinstance(ev, github3.issues.event.RepositoryIssueEvent)
807807

808808
def test_issues_sorts_ascendingly(self):
809809
"""Test that issues w 7F38 ill be returned in ascending order."""

tests/unit/json/issue_event_example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
},
2323
"event": "closed",
2424
"commit_id": "6dcb09b5b57875f334f61aebed695e2e4193db5e",
25+
"commit_url": "https://api.github.com/repos/octocat/Hello-World/commits/6dcb09b5b57875f334f61aebed695e2e4193db5e",
2526
"created_at": "2011-04-14T16:00:49Z",
2627
"issue": {
2728
"id": 1,

0 commit comments

Comments
 (0)
0