6
6
from uritemplate import URITemplate
7
7
8
8
from .. import utils
9
+ from .. import models
9
10
from ..decorators import requires_auth
10
11
from ..exceptions import error_for
11
- from ..models import GitHubCore
12
12
13
13
14
- class Release (GitHubCore ):
14
+ class Release (models . GitHubCore ):
15
15
16
16
"""The :class:`Release <Release>` object.
17
17
18
18
It holds the information GitHub returns about a release from a
19
19
:class:`Repository <github3.repos.repo.Repository>`.
20
20
21
- """
21
+ Please see GitHub's `Releases Documentation`_ for more information.
22
22
23
- CUSTOM_HEADERS = {'Accept' : 'application/vnd.github.manifold-preview' }
23
+ .. _Releases Documentation:
24
+ https://developer.github.com/v3/repos/releases/
25
+ """
24
26
25
27
def _update_attributes (self , release ):
26
- self ._api = self ._get_attribute ( release , 'url' )
28
+ self ._api = self .url = release [ 'url' ]
27
29
28
30
#: List of :class:`Asset <Asset>` objects for this release
29
- self .original_assets = self ._get_attribute (release , 'assets' , [])
30
- if self .original_assets :
31
- self .original_assets = [
32
- Asset (i , self ) for i in self .original_assets
33
- ]
34
-
35
- #: URL for uploaded assets
36
- self .assets_url = self ._get_attribute (release , 'assets_url' )
31
+ self .original_assets = [
32
+ Asset (i , self ) for i in release ['assets' ]
33
+ ]
37
34
38
35
#: Body of the release (the description)
39
- self .body = self . _get_attribute ( release , 'body' )
36
+ self .body = release [ 'body' ]
40
37
41
38
#: Date the release was created
42
39
self .created_at = self ._strptime_attribute (release , 'created_at' )
43
40
44
41
#: Boolean whether value is True or False
45
- self .draft = self ._get_attribute (release , 'draft' )
46
-
47
- #: HTML URL of the release
48
- self .html_url = self ._get_attribute (release , 'html_url' )
42
+ self .draft = release ['draft' ]
49
43
50
44
#: GitHub id
51
- self .id = self . _get_attribute ( release , 'id' )
45
+ self .id = release [ 'id' ]
52
46
53
47
#: Name given to the release
54
- self .name = self . _get_attribute ( release , 'name' )
48
+ self .name = release [ 'name' ]
55
49
56
50
#: Boolean whether release is a prerelease
57
- self .prerelease = self . _get_attribute ( release , 'prerelease' )
51
+ self .prerelease = release [ 'prerelease' ]
58
52
59
53
#: Date the release was published
60
54
self .published_at = self ._strptime_attribute (release , 'published_at' )
61
55
62
56
#: Name of the tag
63
- self .tag_name = self ._get_attribute (release , 'tag_name' )
64
-
65
- #: URL to download a tarball of the release
66
- self .tarball_url = self ._get_attribute (release , 'tarball_url' )
57
+ self .tag_name = release ['tag_name' ]
67
58
68
59
#: "Commit" that this release targets
69
- self .target_commitish = self ._get_attribute (
70
- release , 'target_commitish'
71
- )
60
+ self .target_commitish = release ['target_commitish' ]
72
61
73
62
#: URITemplate to upload an asset with
74
- self .upload_urlt = self ._class_attribute (
75
- release , 'upload_url' , URITemplate
76
- )
63
+ self .upload_urlt = URITemplate (release ['upload_url' ])
77
64
78
- #: URL to download a zipball of the release
79
- self .zipball_url = self ._get_attribute (release , 'zipball_url' )
65
+ #: URLs to various attributes
66
+ for urltype in ['assets_url' , 'html_url' , 'tarball_url' ,
67
+ 'zipball_url' ]:
68
+ setattr (self , urltype , release [urltype ])
80
69
81
70
def _repr (self ):
82
71
return '<Release [{0}]>' .format (self .name )
@@ -131,21 +120,25 @@ def assets(self, number=-1, etag=None):
131
120
132
121
@requires_auth
133
122
def delete (self ):
134
- """Users with push access to the repository can delete a release.
123
+ """Delete this release.
124
+
125
+ Users with push access to the repository can delete a release.
135
126
136
127
:returns: True if successful; False if not successful
137
128
"""
138
129
url = self ._api
139
130
return self ._boolean (
140
- self ._delete (url , headers = Release . CUSTOM_HEADERS ),
131
+ self ._delete (url ),
141
132
204 ,
142
133
404
143
134
)
144
135
145
136
@requires_auth
146
137
def edit (self , tag_name = None , target_commitish = None , name = None , body = None ,
147
138
draft = None , prerelease = None ):
148
- """Users with push access to the repository can edit a release.
139
+ """Edit this release.
140
+
141
+ Users with push access to the repository can edit a release.
149
142
150
143
If the edit is successful, this object will update itself.
151
144
@@ -171,8 +164,7 @@ def edit(self, tag_name=None, target_commitish=None, name=None, body=None,
171
164
self ._remove_none (data )
172
165
173
166
r = self .session .patch (
174
- url , data = json .dumps (data ), headers = Release .CUSTOM_HEADERS
175
- )
167
+ url , data = json .dumps (data ))
176
168
177
169
successful = self ._boolean (r , 200 , 404 )
178
170
if successful :
@@ -204,42 +196,41 @@ def upload_asset(self, content_type, name, asset, label=None):
204
196
raise error_for (r )
205
197
206
198
207
- class Asset (GitHubCore ):
199
+ class Asset (models . GitHubCore ):
208
200
209
201
def _update_attributes (self , asset ):
210
- self ._api = self . _get_attribute ( asset , 'url' )
202
+ self ._api = asset [ 'url' ]
211
203
212
204
#: Content-Type provided when the asset was created
213
- self .content_type = self . _get_attribute ( asset , 'content_type' )
205
+ self .content_type = asset [ 'content_type' ]
214
206
215
207
#: Date the asset was created
216
- self .created_at = self . _strptime_attribute ( asset , 'created_at' )
208
+ self .created_at = asset [ 'created_at' ]
217
209
218
210
#: Number of times the asset was downloaded
219
- self .download_count = self . _get_attribute ( asset , 'download_count' )
211
+ self .download_count = asset [ 'download_count' ]
220
212
221
213
#: URL to download the asset.
222
214
#: Request headers must include ``Accept: application/octet-stream``.
223
215
self .download_url = self ._api
224
216
225
217
# User friendly download URL
226
- self .browser_download_url = self ._get_attribute (
227
- asset , 'browser_download_url' )
218
+ self .browser_download_url = asset ['browser_download_url' ]
228
219
229
220
#: GitHub id of the asset
230
- self .id = self . _get_attribute ( asset , 'id' )
221
+ self .id = asset [ 'id' ]
231
222
232
223
#: Short description of the asset
233
- self .label = self . _get_attribute ( asset , 'label' )
224
+ self .label = asset [ 'label' ]
234
225
235
226
#: Name of the asset
236
- self .name = self . _get_attribute ( asset , 'name' )
227
+ self .name = asset [ 'name' ]
237
228
238
229
#: Size of the asset
239
- self .size = self . _get_attribute ( asset , 'size' )
230
+ self .size = asset [ 'size' ]
240
231
241
232
#: State of the asset, e.g., "uploaded"
242
- self .state = self . _get_attribute ( asset , 'state' )
233
+ self .state = asset [ 'state' ]
243
234
244
235
#: Date the asset was updated
245
236
self .updated_at = self ._strptime_attribute (asset , 'updated_at' )
@@ -287,9 +278,7 @@ def delete(self):
287
278
"""
288
279
url = self ._api
289
280
return self ._boolean (
290
- self ._delete (url , headers = Release .CUSTOM_HEADERS ),
291
- 204 ,
292
- 404
281
+ self ._delete (url ), 204 , 404
293
282
)
294
283
295
284
def edit (self , name , label = None ):
@@ -305,8 +294,7 @@ def edit(self, name, label=None):
305
294
self ._remove_none (edit_data )
306
295
r = self ._patch (
307
296
self ._api ,
308
- data = json .dumps (edit_data ),
309
- headers = Release .CUSTOM_HEADERS
297
+ data = json .dumps (edit_data )
310
298
)
311
299
successful = self ._boolean (r , 200 , 404 )
312
300
if successful :
0 commit comments