4
4
5
5
from json import dumps
6
6
7
- from . import apps
8
7
from . import decorators
9
8
from . import models
10
9
11
10
11
+ class CheckPullRequest (models .GitHubCore ):
12
+ """Representation of a Pull Request returned in Checks APIs.
13
+
14
+ .. versionadded:: 1.3.0
15
+
16
+ .. note::
17
+
18
+ Refreshing this object returns a :class:`~github3.pulls.PullRequest`.
19
+
20
+ This object has the following attributes:
21
+
22
+ .. attribute:: id
23
+
24
+ The unique id of this pull request across all of GitHub.
25
+
26
+ .. attribute:: number
27
+
28
+ The number of this pull request on its repository.
29
+
30
+ .. attribute:: head
31
+
32
+ A dict of minimal head information retrieved from the Check data
33
+ representing the source of the pull request
34
+
35
+ .. attribute:: base
36
+
37
+ A dict of minimal base information retrieved from the Check data
38
+ representing the pull request destination.
39
+ """
40
+
41
+ def _update_attributes (self , pull ):
42
+ self .id = pull ['id' ]
43
+ self .number = pull ['number' ]
44
+ self .base = pull ['base' ]
45
+ self .head = pull ['head' ]
46
+ self ._api = self .url = pull ['url' ]
47
+
48
+ def _repr (self ):
49
+ return '<CheckPullRequest [#{0}]>' .format (self .number )
50
+
51
+ def to_pull (self ):
52
+ """Retrieve a full PullRequest object for this CheckPullRequest.
53
+
54
+ :returns:
55
+ The full information about this pull request.
56
+ :rtype:
57
+ :class:`~github3.pulls.PullRequest`
58
+ """
59
+ from . import pulls
60
+ json = self ._json (self ._get (self .url ), 200 )
61
+ return self ._instance_or_null (pulls .PullRequest , json )
62
+
63
+ refresh = to_pull
64
+
65
+
66
+ class CheckApp (models .GitHubCore ):
67
+ """Representation of an App returned in Checks APIs.
68
+
69
+ .. versionadded:: 1.3.0
70
+
71
+ .. note::
72
+
73
+ Refreshing this object returns a :class:`~github3.apps.App`.
74
+
75
+ This object has the following attributes:
76
+
77
+ .. attribute:: description
78
+
79
+ The description of the App provided by the owner.
80
+
81
+ .. attribute:: external_url
82
+
83
+ The URL provided for the App by the owner.
84
+
85
+ .. attribute:: html_url
86
+
87
+ The HTML URL provided for the App by the owner.
88
+
89
+ .. attribute:: id
90
+
91
+ The unique identifier for the App. This is useful in cases where you
92
+ may want to authenticate either as an App or as a specific
93
+ installation of an App.
94
+
95
+ .. attribute:: name
96
+
97
+ The display name of the App that the user sees.
98
+
99
+ .. attribute:: owner
100
+
101
+ A dict of minimal user information retrieved from the Check data
102
+ representing the app owner
103
+ """
104
+
105
+ def _update_attributes (self , app ):
106
+ self .description = app ['description' ]
107
+ self .external_url = app ['external_url' ]
108
+ self .html_url = app ['html_url' ]
109
+ self .id = app ['id' ]
110
+ self .name = app ['name' ]
111
+ self .owner = app ['owner' ]
112
+
113
+ def _repr (self ):
114
+ return '<App ["{}" by {}]>' .format (self .name ,
115
+ str (self .owner ['login' ]))
116
+
117
+ def to_app (self ):
118
+ """Retrieve a full App object for this CheckApp.
119
+
120
+ :returns:
121
+ The full information about this App.
122
+ :rtype:
123
+ :class:`~github3.apps.App`
124
+ """
125
+ from . import apps
126
+ json = self ._json (self ._get (self .url ), 200 )
127
+ return self ._instance_or_null (apps .App , json )
128
+
129
+ refresh = to_app
130
+
131
+
12
132
class CheckSuite (models .GitHubCore ):
13
133
"""The :class:`CheckSuite <CheckSuite>` object.
14
134
@@ -49,12 +169,17 @@ class CheckSuite(models.GitHubCore):
49
169
.. attribute:: pull_requests
50
170
51
171
A list of representations of the pull requests the suite belongs to as
52
- :class:`~github3.pulls.ShortPullRequest `. This may be empty.
172
+ :class:`~github3.checks.CheckPullRequest `. This may be empty.
53
173
54
174
.. attribute:: id
55
175
56
176
The unique GitHub assigned numerical id of this check suite.
57
177
178
+ .. attribute:: app
179
+
180
+ A :class:`~github3.checks.CheckApp` representing the App
181
+ this suite belongs to.
182
+
58
183
.. CheckSuite Documentation:
59
184
http://developer.github.com/v3/checks/suites/
60
185
"""
@@ -66,21 +191,21 @@ class CheckSuite(models.GitHubCore):
66
191
67
192
def _update_attributes (self , suite ):
68
193
# Import here, because a toplevel import causes an import loop
69
- from . import pulls , repos
194
+ from . import repos
70
195
self ._api = suite ['url' ]
71
- # self.base = Base(pull['base'], self)
72
196
self .status = suite ['status' ]
73
197
self .conclusion = suite ['conclusion' ]
74
198
self .head_branch = suite ['head_branch' ]
75
199
self .head_sha = suite ['head_sha' ]
76
200
self .before = suite ['before' ]
77
201
self .after = suite ['after' ]
78
- pull_requests = suite .get ('pull_requests' , [])
202
+ prs = suite .get ('pull_requests' , [])
79
203
self .pull_requests = [
80
- pulls . ShortPullRequest (p , self ) for p in pull_requests
204
+ CheckPullRequest (p , self ) for p in prs
81
205
]
82
206
self .repository = repos .ShortRepository (suite ['repository' ], self )
83
207
self .id = suite ['id' ]
208
+ self .app = CheckApp (suite ['app' ], self )
84
209
85
210
def _repr (self ):
86
211
return '<{s.class_name} [{s.id}:{s.status}]>' .format (s = self )
@@ -108,13 +233,14 @@ def check_runs(self):
108
233
:class:`~github3.checks.CheckRun`
109
234
"""
110
235
url = self ._build_url ('check-runs' , base_url = self ._api )
111
- return self ._iter (- 1 , url , CheckRun )
236
+ return self ._iter (- 1 , url , CheckRun ,
237
+ headers = CheckSuite .CUSTOM_HEADERS )
112
238
113
239
114
240
class CheckRun (models .GitHubCore ):
115
241
"""The :class:`CheckRun <CheckRun>` object.
116
242
117
- .. versionadded:: 1.2 .0
243
+ .. versionadded:: 1.3 .0
118
244
119
245
Please see GitHub's `CheckRun Documentation`_ for more information.
120
246
@@ -148,8 +274,8 @@ class CheckRun(models.GitHubCore):
148
274
149
275
.. attribute:: pull_requests
150
276
151
- A list of representations of the pull requests the check run belongs to
152
- as :class:`~github3.pulls.ShortPullRequest` (this may be empty) .
277
+ A list of representations of the pull requests the run belongs to as
278
+ :class:`~github3.checks.CheckPullRequest`. This may be empty.
153
279
154
280
.. attribute:: id
155
281
@@ -174,7 +300,7 @@ class CheckRun(models.GitHubCore):
174
300
175
301
.. attribute:: app
176
302
177
- A :class:`~github3.apps.App ` representing the App
303
+ A :class:`~github3.checks.CheckApp ` representing the App
178
304
this run belongs to.
179
305
180
306
.. CheckRun Documentation:
@@ -187,23 +313,21 @@ class CheckRun(models.GitHubCore):
187
313
}
188
314
189
315
def _update_attributes (self , run ):
190
- # Import here, because a toplevel import causes an import loop
191
- from . import pulls
192
316
self ._api = run ['url' ]
193
317
self .html_url = run ['html_url' ]
194
318
self .status = run ['status' ]
195
319
self .conclusion = run ['conclusion' ]
196
- self .started_at = self ._strptime (run ['created_at ' ])
320
+ self .started_at = self ._strptime (run ['started_at ' ])
197
321
self .completed_at = self ._strptime (run ['completed_at' ])
198
322
self .head_sha = run ['head_sha' ]
199
323
self .name = run ['name' ]
200
- pull_requests = run .get ('pull_requests' , [])
324
+ prs = run .get ('pull_requests' , [])
201
325
self .pull_requests = [
202
- pulls . ShortPullRequest (p , self ) for p in pull_requests
326
+ CheckPullRequest (p , self ) for p in prs
203
327
]
204
328
self .id = run ['id' ]
205
329
self .external_id = run ['external_id' ]
206
- self .app = apps . App (run ['app' ], self )
330
+ self .app = CheckApp (run ['app' ], self )
207
331
self .check_suite = run ['check_suite' ]['id' ]
208
332
# self.output = CheckRunOutput(run['output'], self)
209
333
self .output = run ['output' ] # TODO: turn into an object
@@ -259,7 +383,10 @@ def update(self, name=None, details_url=None, external_id=None,
259
383
json = None
260
384
261
385
if data :
262
- json = self ._json (self ._patch (self ._api , data = dumps (data )), 200 )
386
+ json = self ._json (self ._patch (
387
+ self ._api , data = dumps (data ),
388
+ headers = CheckSuite .CUSTOM_HEADERS ), 200
389
+ )
263
390
if json :
264
391
self ._update_attributes (json )
265
392
return True
0 commit comments