8000 Merge branch 'release-asset-label' into develop · pythonthings/github3.py@01fd26e · GitHub
[go: up one dir, main page]

Skip to content

Commit 01fd26e

Browse files
committed
Merge branch 'release-asset-label' into develop
2 parents c460f32 + d3e6a63 commit 01fd26e

27 files changed

+424
-18
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ build/
1616
*.egg
1717
.env
1818
.ipynb_checkpoints
19+
.cache/

AUTHORS.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,5 @@ Contributors
112112
- Chris Thompson (@notyetsecure)
113113

114114
- Bastien Gandouet (@b4stien)
115+
116+
- Usman Ehtesham Gul (@ueg1990)

dev-requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ pytest>=2.3.5
55
wheel==0.21.0
66
betamax>=0.5.0
77
betamax_matchers>=0.2.0
8+
tox>=2.2.0

docs/examples/github.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.. _github:
1+
.. _github_examples:
22

33
GitHub Examples
44
===============

docs/github.rst

Lines changed: 1 addition & 3 deletions
< 6293 td data-grid-cell-id="diff-5423bdf7b76511bbf7b0281cffa9e8616cd74d0431197b3b65482a84d6a40a4b-25-24-0" data-selected="false" role="gridcell" style="background-color:var(--diffBlob-deletionNum-bgColor, var(--diffBlob-deletion-bgColor-num));text-align:center" tabindex="-1" valign="top" class="focusable-grid-cell diff-line-number position-relative left-side">25
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,14 @@ you're looking for anonymous functions, you're most likely looking for the
1414
Examples
1515
--------
1616

17-
Examples utilizing this object can be found here_.
17+
Examples utilizing this object can be found :ref:`here <github_examples>`.
1818

1919
GitHub Object
2020
-------------
2121

2222
.. autoclass:: GitHub
2323
:inherited-members:
2424

-
.. links
26-
.. _here: examples/githubex.html
2725

2826
GitHubEnterprise Object
2927
-----------------------

github3/github.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from .structs import SearchIterator
2626
from .users import User, Key
2727
from .notifications import Thread
28+
from .licenses import License
2829
from uritemplate import URITemplate
2930

3031

@@ -699,6 +700,26 @@ def keys(self, number=-1, etag=None):
699700
url = self._build_url('user', 'keys')
700701
return self._iter(int(number), url, Key, etag=etag)
701702

703+
def license(self, name):
704+
"""Retrieve the license specified by the name.
705+
706+
:param string name: (required), name of license
707+
:returns: :class:`License <github3.licenses.License>`
708+
"""
709+
710+
url = self._build_url('licenses', name)
711+
json = self._json(self._get(url, headers=License.CUSTOM_HEADERS), 200)
712+
return self._instance_or_null(License, json)
713+
714+
def licenses(self, number=-1, etag=None):
715+
"""Iterate over open source licenses.
716+
717+
:returns: generator of :class:`License <github3.licenses.License>`
718+
"""
719+
url = self._build_url('licenses')
720+
return self._iter(int(number), url, License, etag=etag,
721+
headers=License.CUSTOM_HEADERS)
722+
702723
def login(self, username=None, password=None, token=None,
703724
two_factor_callback=None):
704725
"""Logs the user into GitHub for protected API calls.

github3/licenses.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
github3.licenses
4+
================
5+
6+
This module contains the classes relating to licenses
7+
8+
See also: https://developer.github.com/v3/licenses/
9+
"""
10+
from __future__ import unicode_literals
11+
12+
from .models import GitHubCore
13+
14+
15+
class License(GitHubCore):
16+
17+
CUSTOM_HEADERS = {
18+
'Accept': 'application/vnd.github.drax-preview+json'
19+
}
20+
21+
def _update_attributes(self, license):
22+
self.name = license.get('name')
23+
self.permitted = license.get('permitted')
24+
self.category = license.get('category')
25+
self.forbidden = license.get('forbidden')
26+
self.featured = license.get('featured')
27+
self.html_url = license.get('html_url')
28+
self.body = license.get('body')
29+
self.key = license.get('key')
30+
self.description = license.get('description')
31+
self.implementation = license.get('implementation')
32+
self.required = license.get('required')
33+
34+
def _repr(self):
35+
return '<License [{0}]>'.format(self.name)

github3/repos/branch.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ class Branch(GitHubCore):
1010
returns about a branch on a
1111
:class:`Repository <github3.repos.repo.Repository>`.
1212
"""
13+
14+
# The Accept header will likely be removable once the feature is out of
15+
# preview mode. See: http://git.io/v4O1e
16+
PREVIEW_HEADERS = {'Accept': 'application/vnd.github.loki-preview+json'}
17+
1318
def _update_attributes(self, branch):
1419
#: Name of the branch.
1520
self.name = branch.get('name')
@@ -20,6 +25,8 @@ def _update_attributes(self, branch):
2025
self.commit = RepoCommit(self.commit, self)
2126
#: Returns '_links' attribute.
2227
self.links = branch.get('_links', {})
28+
#: Provides the branch's protection status.
29+
self.protection = branch.get('protection')
2330

2431
def _repr(self):
2532
return '<Repository Branch [{0}]>'.format(self.name)

github3/repos/release.py

Lines changed: 6 additions & 4 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,13 @@ 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
"""
174-
headers = Release.CUSTOM_HEADERS.copy()
175-
headers.update({'Content-Type': content_type})
176-
url = self.upload_urlt.expand({'name': name})
175+
headers = {'Content-Type': content_type}
176+
params = {'name': name, 'label': label}
177+
self._remove_none(params)
178+
url = self.upload_urlt.expand(params)
177179
r = self._post(url, data=asset, json=False, headers=headers)
178180
if r.status_code in (201, 202):
179181
return Asset(r.json(), self)

github3/repos/repo.py

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
from .contents import Contents, validate_commmitter
2929
from .deployment import Deployment
3030
from .hook import Hook
31+
from ..licenses import License
3132
from .pages import PagesBuild, PagesInfo
3233
from .status import Status
3334
from .stats import ContributorStats
@@ -395,21 +396,26 @@ def branch(self, name):
395396
json = None
396397
if name:
397398
url = self._build_url('branches', name, base_url=self._api)
398-
json = self._json(self._get(url), 200)
399+
json = self._json(self._get(url, headers=Branch.PREVIEW_HEADERS),
400+
200)
399401
return self._instance_or_null(Branch, json)
400402

401-
def branches(self, number=-1, etag=None):
403+
def branches(self, number=-1, protected=False, etag=None):
402404
r"""Iterate over the branches in this repository.
403405
404406
:param int number: (optional), number of branches to return. Default:
405407
-1 returns all branches
408+
:param bool protected: (optional), True lists only protected branches.
409+
Default: False
406410
:param str etag: (optional), ETag from a previous request to the same
407411
endpoint
408412
:returns: generator of
409413
:class:`Branch <github3.repos.branch.Branch>`\ es
410414
"""
411415
url = self._build_url('branches', base_url=self._api)
412-
return self._iter(int(number), url, Branch, etag=etag)
416+
params = {'protected': '1'} if protected else None
417+
return self._iter(int(number), url, Branch, params, etag=etag,
418+
headers=Branch.PREVIEW_HEADERS)
413419

414420
def code_frequency(self, number=-1, etag=None):
415421
"""Iterate over the code frequency per week.
@@ -1410,6 +1416,15 @@ def latest_pages_build(self):
14101416
json = self._json(self._get(url), 200)
14111417
return self._instance_or_null(PagesBuild, json)
14121418

1419+
def license(self):
1420+
"""Get the contents of a license for the repo
1421+
1422+
:returns: :class:`License <github3.licenses.License>`
1423+
"""
1424+
url = self._build_url('license', base_url=self._api)
1425+
json = self._json(self._get(url, headers=License.CUSTOM_HEADERS), 200)
1426+
return self._instance_or_null(License, json)
1427+
14131428
@requires_auth
14141429
def mark_notifications(self, last_read=''):
14151430
"""Mark all notifications in this repository as read.
@@ -1653,6 +1668,31 @@ def release(self, id):
16531668
json = self._json(self._get(url), 200)
16541669
return self._instance_or_null(Release, json)
16551670

1671+
def release_latest(self):
1672+
"""Get the latest release.
1673+
1674+
Draft releases and prereleases are not returned by this endpoint.
1675+
1676+
:returns: :class:`Release <github3.repos.release.Release>`
1677+
"""
1678+
url = self._build_url('releases', 'latest', base_url=self._api)
1679+
json = self._json(self._get(url), 200)
1680+
return self._instance_or_null(Release, json)
1681+
1682+
def release_from_tag(self, tag_name):
1683+
"""Get a release by tag name.
1684+
1685+
release_from_tag() returns a release with specified tag
1686+
while release() returns a release with specified release id
1687+
1688+
:param str tag_name: (required) name of tag
1689+
:returns: :class:`Release <github3.repos.release.Release>`
1690+
"""
1691+
url = self._build_url('releases', 'tags', tag_name,
1692+
base_url=self._api)
1693+
json = self._json(self._get(url), 200)
1694+
return self._instance_or_null(Release, json)
1695+
16561696
def releases(self, number=-1, etag=None):
16571697
r"""Iterate over releases for this repository.
16581698

0 commit comments

Comments
 (0)
0