10000 Add protected parameter to branches method with simple unit test. · pythonthings/github3.py@96b48c7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 96b48c7

Browse files
committed
Add protected parameter to branches method with simple unit test.
1 parent 14cdaf9 commit 96b48c7

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

github3/repos/repo.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,18 +399,27 @@ def branch(self, name):
399399
json = self._json(self._get(url), 200)
400400
return self._instance_or_null(Branch, json)
401401

402-
def branches(self, number=-1, etag=None):
402+
def branches(self, number=-1, protected=False, etag=None):
403403
r"""Iterate over the branches in this repository.
404404
405405
:param int number: (optional), number of branches to return. Default:
406406
-1 returns all branches
407+
:param bool protected: (optional), True lists only protected branches.
408+
Default: False
407409
:param str etag: (optional), ETag from a previous request to the same
408410
endpoint
409411
:returns: generator of
410412
:class:`Branch <github3.repos.branch.Branch>`\ es
411413
"""
412414
url = self._build_url('branches', base_url=self._api)
413-
return self._iter(int(number), url, Branch, etag=etag)
415+
416+
# The Accept header will likely be removable once the feature is out of
417+
# preview mode. See: http://git.io/v4O1e
418+
headers = {'Accept': 'application/vnd.github.loki-preview+json'}
419+
420+
params = {'protected': '1'} if protected else None
421+
return self._iter(int(number), url, Branch, params, etag=etag,
422+
headers=headers)
414423

415424
def code_frequency(self, number=-1, etag=None):
416425
"""Iterate over the code frequency per week.

tests/unit/test_repos_repo.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,18 @@ def test_branches(self):
368368
self.session.get.assert_called_once_with(
369369
url_for('branches'),
370370
params={'per_page': 100},
371-
headers={}
371+
headers={'Accept': 'application/vnd.github.loki-preview+json'}
372+
)
373+
374+
def test_branches_protected(self):
375+
"""Test ability to iterate over protected branches in a Repository."""
376+
i = self.instance.branches(protected=True)
377+
self.get_next(i)
378+
379+
self.session.get.assert_called_once_with(
380+
url_for('branches'),
381+
params={'per_page': 100, 'protected': '1'},
382+
headers={'Accept': 'application/vnd.github.loki-preview+json'}
372383
)
373384

374385
def test_code_frequency(self):

0 commit comments

Comments
 (0)
0