Skip to content

Commit 65a4134

Browse files
committed
Add support for specifying a release asset label at upload.
1 parent 24893ec commit 65a4134

2 files changed

Lines changed: 24 additions & 4 deletions

File tree

github3/repos/release.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ def edit(self, tag_name=None, target_commitish=None, name=None, body=None,
160160
return successful
161161

162162
@requires_auth
163-
def upload_asset(self, content_type, name, asset):
163+
def upload_asset(self, content_type, name, asset, label=None):
164164
"""Upload an asset to this release.
165165
166166
All parameters are required.
@@ -169,11 +169,14 @@ def upload_asset(self, content_type, name, asset):
169169
a list of common media types
170170
:param str name: The name of the file
171171
:param asset: The file or bytes object to upload.
172+
:param label: (optional), An alternate short description of the asset.
172173
:returns: :class:`Asset <Asset>`
173174
"""
174175
headers = Release.CUSTOM_HEADERS.copy()
175176
headers.update({'Content-Type': content_type})
176-
url = self.upload_urlt.expand({'name': name})
177+
params = {'name': name, 'label': label}
178+
self._remove_none(params)
179+
url = self.upload_urlt.expand(params)
177180
r = self._post(url, data=asset, json=False, headers=headers)
178181
if r.status_code in (201, 202):
179182
return Asset(r.json(), self)

tests/integration/test_repos_release.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,28 @@ def test_upload_asset(self):
7777
)
7878
with open(__file__) as fd:
7979
asset = release.upload_asset(
80-
'text/plain', 'test_repos_release.py', fd.read()
81-
)
80+
'text/plain', 'test_repos_release.py', fd.read(),
81+
)
8282
assert isinstance(asset, github3.repos.release.Asset)
8383
release.delete()
8484

85+
def test_upload_asset_with_a_label(self):
86+
"""Test the ability to upload an asset to a release with a label."""
87+
self.token_login()
88+
cassette_name = self.cassette_name('upload_asset_with_a_label')
89+
with self.recorder.use_cassette(cassette_name):
90+
repository = self.gh.repository('github3py', 'github3.py')
91+
release = repository.create_release(
92+
'0.8.0.pre', 'develop', '0.8.0 fake release with upload',
93+
'To be deleted'
94+
)
95+
with open(__file__) as fd:
96+
asset = release.upload_asset(
97+
'text/plain', 'test_repos_release.py', fd.read(),
98+
'test-label',
99+
)
100+
assert isinstance(asset, github3.repos.release.Asset)
101+
release.delete()
85102

86103
class TestAsset(IntegrationHelper):
87104
def test_delete(self):

0 commit comments

Comments
 (0)