forked from sigmavirus24/github3.py
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathevent.py
More file actions
194 lines (153 loc) · 5.22 KB
/
Copy pathevent.py
File metadata and controls
194 lines (153 loc) · 5.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
"""
github3.event
=============
This module contains the class(es) related to Events
"""
from .models import GitHubCore
class Event(GitHubCore):
"""The :class:`Event <Event>` object. It structures and handles the data
returned by via the `Events <http://developer.github.com/v3/events>`_
section of the GitHub API.
"""
def __init__(self, event, session=None):
super(Event, self).__init__(event, session)
from .user import User
from .org import Organization
self._created = self._strptime(event.get('created_at'))
self._type = event.get('type')
self._public = event.get('public')
self._repo = event.get('repo', {})
self._actor = event.get('actor', {})
if self._actor:
self._actor = User(self._actor, self._session)
self._id = event.get('id')
handler = _payload_handlers[self._type]
self._payload = handler(event.get('payload'))
self._org = event.get('org', {})
if self._org:
self._org = Organization(self._org, self)
def __repr__(self):
return '<Event [{0}]>'.format(self._type[:-5])
@property
def actor(self):
""":class:`User <github3.user.User>` object representing the actor."""
return self._actor
@property
def created_at(self):
"""datetime object representing when the event was created."""
return self._created
@property
def id(self):
"""Unique id of the event"""
return self._id
@staticmethod
def list_types():
"""List all possible types of Events"""
return sorted(_payload_handlers.keys())
@property
def org(self):
""":class:`Organization <github3.org.Organization>` object if actor
was an org."""
return self._org
@property
def payload(self):
"""Dictionary with the payload. Payload structure is defined by type_.
.. _type: http://developer.github.com/v3/events/types
"""
return self._payload
def is_public(self):
"""Indicates whether the Event is public or not.
:returns: bool -- True if event is pubic, False otherwise
"""
return self._public
@property
def repo(self):
"""Return ``tuple(owner, repository_name)``"""
return tuple(self._repo['name'].split('/'))
@property
def type(self):
"""Event type"""
return self._type
def _commitcomment(payload):
from .repo import RepoComment
if payload.get('comment'):
payload['comment'] = RepoComment(payload['comment'], None)
return payload
def _download(payload):
from .repo import Download
if payload.get('download'):
payload['download'] = Download(payload['download'], None)
return payload
def _follow(payload):
from .user import User
if payload.get('target'):
payload['target'] = User(payload['target'], None)
return payload
def _forkev(payload):
from .repo import Repository
if payload.get('forkee'):
payload['forkee'] = Repository(payload['forkee'], None)
return payload
def _gist(payload):
from .gist import Gist
if payload.get('gist'):
payload['gist'] = Gist(payload['gist'], None)
return payload
def _issuecomm(payload):
from .issue import Issue, IssueComment
if payload.get('issue'):
payload['issue'] = Issue(payload['issue'], None)
if payload.get('comment'):
payload['comment'] = IssueComment(payload['comment'], None)
return payload
def _issueevent(payload):
from .issue import Issue
if payload.get('issue'):
payload['issue'] = Issue(payload['issue'], None)
return payload
def _member(payload):
from .user import User
if payload.get('member'):
payload['member'] = User(payload['member'], None)
return payload
def _pullreqev(payload):
from .pulls import PullRequest
if payload.get('pull_request'):
payload['pull_request'] = PullRequest(payload['pull_request'], None)
return payload
def _pullreqcomm(payload):
from .pulls import ReviewComment
if payload.get('comment'):
payload['comment'] = ReviewComment(payload['comment'], None)
return payload
def _team(payload):
from .org import Team
from .repo import Repository
from .user import User
if payload.get('team'):
payload['team'] = Team(payload['team'], None)
if payload.get('repo'):
payload['repo'] = Repository(payload['repo'], None)
if payload.get('user'):
payload['user'] = User(payload['user'], None)
return payload
_payload_handlers = {
'CommitCommentEvent': _commitcomment,
'CreateEvent': lambda x: x,
'DeleteEvent': lambda x: x,
'DownloadEvent': _download,
'FollowEvent': _follow,
'ForkEvent': _forkev,
'ForkApplyEvent': lambda x: x,
'GistEvent': _gist,
'GollumEvent': lambda x: x,
'IssueCommentEvent': _issuecomm,
'IssuesEvent': _issueevent,
'MemberEvent': _member,
'PublicEvent': lambda x: '',
'PullRequestEvent': _pullreqev,
'PullRequestReviewCommentEvent': _pullreqcomm,
'PushEvent': lambda x: x,
'TeamAddEvent': _team,
'WatchEvent': lambda x: x,
}