8
8
"""
9
9
from __future__ import unicode_literals
10
10
11
- from .models import GitHubObject
11
+ from .models import GitHubCore
12
12
13
13
14
- class Event (GitHubObject ):
14
+ class Event (GitHubCore ):
15
15
16
16
"""The :class:`Event <Event>` object. It structures and handles the data
17
17
returned by via the `Events <http://developer.github.com/v3/events>`_
@@ -48,7 +48,7 @@ def __init__(self, event):
48
48
handler = _payload_handlers .get (self .type , identity )
49
49
#: Dictionary with the payload. Payload structure is defined by type_.
50
50
# _type: http://developer.github.com/v3/events/types
51
- self .payload = handler (event .get ('payload' ))
51
+ self .payload = handler (event .get ('payload' ), self )
52
52
#: Return ``tuple(owner, repository_name)``
53
53
self .repo = event .get ('repo' )
54
54
if self .repo is not None :
@@ -74,94 +74,102 @@ def is_public(self):
74
74
return self .public
75
75
76
76
77
- def _commitcomment (payload ):
77
+ def _commitcomment (payload , session ):
78
78
from .repos .comment import RepoComment
79
79
if payload .get ('comment' ):
80
- payload ['comment' ] = RepoComment (payload ['comment' ], None )
80
+ payload ['comment' ] = RepoComment (payload ['comment' ], session )
81
81
return payload
82
82
83
83
84
- def _follow (payload ):
84
+ def _follow (payload , session ):
85
85
from .users import User
86
86
if payload .get ('target' ):
87
- payload ['target' ] = User (payload ['target' ], None )
87
+ payload ['target' ] = User (payload ['target' ], session )
88
88
return payload
89
89
90
90
91
- def _forkev (payload ):
91
+ def _forkev (payload , session ):
92
92
from .repos import Repository
93
93
if payload .get ('forkee' ):
94
- payload ['forkee' ] = Repository (payload ['forkee' ], None )
94
+ payload ['forkee' ] = Repository (payload ['forkee' ], session )
95
95
return payload
96
96
97
97
98
- def _gist (payload ):
98
+ def _gist (payload , session ):
99
99
from .gists import Gist
100
100
if payload .get ('gist' ):
101
- payload ['gist' ] = Gist (payload ['gist' ], None )
101
+ payload ['gist' ] = Gist (payload ['gist' ], session )
102
102
return payload
103
103
104
104
105
- def _issuecomm (payload ):
105
+ def _issuecomm (payload , session ):
106
106
from .issues import Issue
107
107
from .issues .comment import IssueComment
108
108
if payload .get ('issue' ):
109
- payload ['issue' ] = Issue (payload ['issue' ], None )
109
+ payload ['issue' ] = Issue (payload ['issue' ], session )
110
110
if payload .get ('comment' ):
111
- payload ['comment' ] = IssueComment (payload ['comment' ], None )
111
+ payload ['comment' ] = IssueComment (payload ['comment' ], session )
112
112
return payload
113
113
114
114
115
- def _issueevent (payload ):
115
+ def _issueevent (payload , session ):
116
116
from .issues import Issue
117
117
if payload .get ('issue' ):
118
- payload ['issue' ] = Issue (payload ['issue' ], None )
118
+ payload ['issue' ] = Issue (payload ['issue' ], session )
119
119
return payload
120
120
121
121
122
- def _member (payload ):
122
+ def _member (payload , session ):
123
123
from .users import User
124
124
if payload .get ('member' ):
125
- payload ['member' ] = User (payload ['member' ], None )
125
+ payload ['member' ] = User (payload ['member' ], session )
126
126
return payload
127
127
128
128
129
- def _pullreqev (payload ):
129
+ def _pullreqev (payload , session ):
130
130
from .pulls import PullRequest
131
131
if payload .get ('pull_request' ):
132
- payload ['pull_request' ] = PullRequest (payload ['pull_request' ], None )
132
+ payload ['pull_request' ] = PullRequest (payload ['pull_request' ],
133
+ session )
133
134
return payload
134
135
135
136
136
- def _pullreqcomm (payload ):
137
- from .pulls import ReviewComment
138
- if payload .get ('comment' ):
139
- payload ['comment' ] = ReviewComment (payload ['comment' ], None )
137
+ def _pullreqcomm (payload , session ):
138
+ from .pulls import PullRequest , ReviewComment
139
+ # Transform the Pull Request attribute
140
+ pull = payload .get ('pull_request' )
141
+ if pull :
142
+ payload ['pull_request' ] = PullRequest (pull , session )
143
+
144
+ # Transform the Comment attribute
145
+ comment = payload .get ('comment' )
146
+ if comment :
147
+ payload ['comment' ] = ReviewComment (comment , session )
140
148
return payload
141
149
142
150
143
- def _release (payload ):
151
+ def _release (payload , session ):
144
152
from .repos .release import Release
145
153
release = payload .get ('release' )
146
154
if release :
147
- payload ['release' ] = Release (release )
155
+ payload ['release' ] = Release (release , session )
148
156
return payload
149
157
150
158
151
- def _team (payload ):
159
+ def _team (payload , session ):
152
160
from .orgs import Team
153
161
from .repos import Repository
154
162
from .users import User
155
163
if payload .get ('team' ):
156
- payload ['team' ] = Team (payload ['team' ], None )
164
+ payload ['team' ] = Team (payload ['team' ], session )
157
165
if payload .get ('repo' ):
158
- payload ['repo' ] = Repository (payload ['repo' ], None )
166
+ payload ['repo' ] = Repository (payload ['repo' ], session )
159
167
if payload .get ('sender' ):
160
- payload ['sender' ] = User (payload ['sender' ], None )
168
+ payload ['sender' ] = User (payload ['sender' ], session )
161
169
return payload
162
170
163
171
17AE
164
- def identity (x ):
172
+ def identity (x , session ):
165
173
return x
166
174
167
175
@@ -177,7 +185,7 @@ def identity(x):
177
185
'IssueCommentEvent' : _issuecomm ,
178
186
'IssuesEvent' : _issueevent ,
179
187
'MemberEvent' : _member ,
180
- 'PublicEvent' : lambda x : '' ,
188
+ 'PublicEvent' : identity ,
181
189
'PullRequestEvent' : _pullreqev ,
182
190
'PullRequestReviewCommentEvent' : _pullreqcomm ,
183
191
'PushEvent' : identity ,
0 commit comments