Skip to content

Commit f7abcfd

Browse files
committed
Update services.repos.Repo
1 parent 567e89c commit f7abcfd

File tree

4 files changed

+36
-9
lines changed

4 files changed

+36
-9
lines changed

pygithub3/requests/repos/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,9 @@ class List_branches(Request):
8787

8888
uri = 'repos/{user}/{repo}/branches'
8989
resource = Branch
90+
91+
92+
class Get_branch(Request):
93+
94+
uri = 'repos/{user}/{repo}/branches/{branch}'
95+
resource = Branch

pygithub3/resources/repos.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#!/usr/bin/env python
21
# -*- encoding: utf-8 -*-
32

43
from pygithub3.core.compat import OrderedDict

pygithub3/services/repos/__init__.py

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
#!/usr/bin/env python
21
# -*- encoding: utf-8 -*-
32

4-
from pygithub3.services.base import Service, MimeTypeMixin
3+
from pygithub3.services.base import Service
54
from .collaborators import Collaborators
65
from .commits import Commits
76
from .downloads import Downloads
@@ -24,11 +23,13 @@ def __init__(self, **config):
2423
self.hooks = Hooks(**config)
2524
super(Repo, self).__init__(**config)
2625

27-
def list(self, user=None, type='all'):
26+
def list(self, user=None, type='all', sort='full_name', direction='desc'):
2827
""" Get user's repositories
2928
3029
:param str user: Username
31-
:param str type: Filter by type (optional). See `github repos doc`_
30+
:param str type: *all*, owner, public, private, member
31+
:param str sort: created, updated, pushed, *full_name*
32+
:param str direction: asc or *desc*
3233
:returns: A :doc:`result`
3334
3435
If you call it without user and you are authenticated, get the
@@ -43,13 +44,14 @@ def list(self, user=None, type='all'):
4344
repo_service.list(type='private')
4445
"""
4546
request = self.request_builder('repos.list', user=user)
46-
return self._get_result(request, type=type)
47+
return self._get_result(request, type=type, sort=sort,
48+
direction=direction)
4749

4850
def list_by_org(self, org, type='all'):
4951
""" Get organization's repositories
5052
5153
:param str org: Organization name
52-
:param str type: Filter by type (optional). See `github repos doc`_
54+
:param str type: *all*, public, member, private
5355
:returns: A :doc:`result`
5456
5557
::
@@ -147,7 +149,7 @@ def list_contributors(self, user=None, repo=None):
147149
def list_contributors_with_anonymous(self, user=None, repo=None):
148150
""" Like :attr:`~pygithub3.services.repos.Repo.list_contributors` plus
149151
anonymous """
150-
return self.__list_contributors(user, repo, anom=True)
152+
return self.__list_contributors(user, repo, anon=True)
151153

152154
def list_languages(self, user=None, repo=None):
153155
""" Get repository's languages
@@ -202,3 +204,17 @@ def list_branches(self, user=None, repo=None):
202204
request = self.make_request('repos.list_branches',
203205
user=user, repo=repo)
204206
return self._get_result(request)
207+
208+
def get_branch(self, branchname, user=None, repo=None):
209+
""" Get branch
210+
211+
:param str user: Username
212+
:param str repo: Repository
213+
:param str branchname
214+
215+
.. note::
216+
Remember :ref:`config precedence`
217+
"""
218+
request = self.make_request('repos.get_branch', user=user,
219+
repo=repo, branch=branchname)
220+
return self._get(request)

pygithub3/tests/services/test_repos.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def test_LIST_contributors_with_anonymous(self, request_method):
110110
self.rs.list_contributors_with_anonymous().all()
111111
self.assertEqual(request_method.call_args[0],
112112
('get', _('repos/octocat/octocat_repo/contributors')))
113-
self.assertEqual(request_method.call_args[1]['params']['anom'], True)
113+
self.assertEqual(request_method.call_args[1]['params']['anon'], True)
114114

115115
def test_LIST_languages(self, request_method):
116116
request_method.return_value = mock_response()
@@ -136,6 +136,12 @@ def test_LIST_branches(self, request_method):
136136
self.assertEqual(request_method.call_args[0],
137137
('get', _('repos/octocat/octocat_repo/branches')))
138138

139+
def test_GET_branch(self, request_method):
140+
request_method.return_value = mock_response()
141+
self.rs.get_branch('master')
142+
self.assertEqual(request_method.call_args[0],
143+
('get', _('repos/octocat/octocat_repo/branches/master')))
144+
139145

140146
@dummy_json
141147
@patch.object(requests.sessions.Session, 'request')

0 commit comments

Comments
 (0)