8000 Add Release.assets attribute · waynr/github3.py@47cba93 · GitHub
[go: up one dir, main page]

Skip to content

Commit 47cba93

Browse files
committed
Add Release.assets attribute
The JSON describing a release includes complete information on its assets. Add Release.assets attribute with a list of Assets. This is cheaper for the application than making a separate request via Release.iter_assets(). Leave Release.iter_assets() in place, in case someone has a use for it, but mention Release.assets in its documentation.
1 parent 480349c commit 47cba93

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

github3/repos/release.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ class Release(GitHubCore):
2222
def __init__(self, release, session=None):
2323
super(Release, self).__init__(release, session)
2424
self._api = release.get('url')
25+
#: List of :class:`Asset <Asset>` objects for this release
26+
self.assets = [Asset(i, self) for i in release.get('assets', [])]
2527
#: URL for uploaded assets
2628
self.assets_url = release.get('assets_url')
2729
#: Body of the release (the description)
@@ -104,7 +106,9 @@ def edit(self, tag_name=None, target_commitish=None, name=None, body=None,
104106
return successful
105107

106108
def iter_assets(self, number=-1, etag=None):
107-
"""Iterate over the assets available for this release.
109+
"""Iterate over the assets available for this release. The same
110+
information is available, without an additional network access,
111+
from the :attr:`assets` attribute.
108112
109113
:param int number: (optional), Number of assets to return
110114
:param str etag: (optional), last ETag header sent

tests/unit/test_repos_release.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,18 @@ class TestRelease(UnitHelper):
1515
example_data = {
1616
"url": releases_url("/1"),
1717
"html_url": "https://github.com/octocat/Hello-World/releases/v1.0.0",
18+
"assets": [{
19+
"url": releases_url("/assets/1"),
20+
"id": 1,
21+
"name": "example.zip",
22+
"label": "short description",
23+
"state": "uploaded",
24+
"content_type": "application/zip",
25+
"size": 1024,
26+
"download_count": 42,
27+
"created_at": "2013-02-27T19:35:32Z",
28+
"updated_at": "2013-02-27T19:35:32Z"
29+
}],
1830
"assets_url": releases_url("/1/assets"),
1931
"upload_url": releases_url("/1/assets{?name}"),
2032
"id": 1,
@@ -29,6 +41,10 @@ class TestRelease(UnitHelper):
2941
}
3042

3143
# Attribute tests
44+
def test_assets(self):
45+
assert self.instance.assets is not None
46+
assert isinstance(self.instance.assets[0], Asset)
47+
3248
def test_has_upload_urlt(self):
3349
assert self.instance.upload_urlt is not None
3450

0 commit comments

Comments
 (0)
0