diff options
author | 2012-03-04 18:27:50 +0100 | |
---|---|---|
committer | 2012-03-04 18:27:50 +0100 | |
commit | b9ad335335f9562d5cf033783b41fe40dd6efc03 (patch) | |
tree | b7d381b753eef33db0d71a1777720806e80ade03 /pygithub3 | |
parent | Refactor result. Now it's a package (diff) | |
download | python-github3-b9ad335335f9562d5cf033783b41fe40dd6efc03.tar.xz python-github3-b9ad335335f9562d5cf033783b41fe40dd6efc03.zip |
Get repository's commits supported with new result
Diffstat (limited to 'pygithub3')
-rw-r--r-- | pygithub3/core/result/__init__.py | 1 | ||||
-rw-r--r-- | pygithub3/core/result/link.py | 2 | ||||
-rw-r--r-- | pygithub3/core/result/normal.py | 24 | ||||
-rw-r--r-- | pygithub3/requests/repos/commits.py | 4 | ||||
-rw-r--r-- | pygithub3/resources/repos.py | 17 | ||||
-rw-r--r-- | pygithub3/services/base.py | 10 | ||||
-rw-r--r-- | pygithub3/services/repos/commits.py | 33 | ||||
-rw-r--r-- | pygithub3/tests/services/test_repos.py | 2 |
8 files changed, 60 insertions, 33 deletions
diff --git a/pygithub3/core/result/__init__.py b/pygithub3/core/result/__init__.py index e69de29..dae354a 100644 --- a/pygithub3/core/result/__init__.py +++ b/pygithub3/core/result/__init__.py @@ -0,0 +1 @@ +# -*- encoding: utf-8 -*- diff --git a/pygithub3/core/result/link.py b/pygithub3/core/result/link.py index b6a614f..dae8407 100644 --- a/pygithub3/core/result/link.py +++ b/pygithub3/core/result/link.py @@ -21,7 +21,7 @@ class Link(str): for param, values in parse_qs(self.query).items()]) def __init__(self, object_): - super(Link, self).__init__(object_) + str.__init__(object_) parsed = parse_link_value(self) for url in parsed: setattr(self, parsed[url]['rel'], Link.Url(url)) diff --git a/pygithub3/core/result/normal.py b/pygithub3/core/result/normal.py index c38a915..7f0e888 100644 --- a/pygithub3/core/result/normal.py +++ b/pygithub3/core/result/normal.py @@ -87,29 +87,29 @@ class Result(base.Result): def __init__(self, method): super(Result, self).__init__(method) - self.counter = 0 - self.cached = False + self._counter = 0 + self._cached = False - def get_cached(func): + def _get_cached(func): def wrapper(self): - if self.cached: - if str(self.counter) in self.getter.cache: - page = Page(self.getter, self.counter) - self.counter += 1 + if self._cached: + if str(self._counter) in self.getter.cache: + page = Page(self.getter, self._counter) + self._counter += 1 return page self._reset() raise StopIteration return func(self) return wrapper - @get_cached + @_get_cached def __next__(self): if self.getter.next: - self.counter += 1 - return Page(self.getter, self.counter) + self._counter += 1 + return Page(self.getter, self._counter) self._reset() raise StopIteration def _reset(self): - self.counter = 1 - self.cached = True + self._counter = 1 + self._cached = True diff --git a/pygithub3/requests/repos/commits.py b/pygithub3/requests/repos/commits.py index 49df2a1..c31ad04 100644 --- a/pygithub3/requests/repos/commits.py +++ b/pygithub3/requests/repos/commits.py @@ -2,7 +2,7 @@ # -*- encoding: utf-8 -*- from . import Request -from pygithub3.resources.repos import Commit, GitCommit, Comment, Diff +from pygithub3.resources.repos import GitCommit, Comment, Diff class List(Request): @@ -14,7 +14,7 @@ class List(Request): class Get(Request): uri = 'repos/{user}/{repo}/commits/{sha}' - resource = Commit + resource = GitCommit class List_comments(Request): diff --git a/pygithub3/resources/repos.py b/pygithub3/resources/repos.py index 9d8ebf6..c7ec5e8 100644 --- a/pygithub3/resources/repos.py +++ b/pygithub3/resources/repos.py @@ -40,14 +40,13 @@ class Committer(Resource): return '<Committer (%s)>' % getattr(self, 'name', '') -class GitCommit(Resource): +class Commit(Resource): - _maps = {'author': Author, 'committer': Committer, 'tree': 'self'} - _collection_maps = {'parents': 'self'} + _maps = {'author': Author, 'committer': Committer} + #_maps.update({'tree': GitCommit}) def __str__(self): - return '<GitCommit (%s:%s)>' % (getattr(self, 'sha', ''), - getattr(self, 'message', '')) + return '<Commit (%s)>' % getattr(self, 'author', '') class Stats(Resource): @@ -60,14 +59,14 @@ class File(Resource): return '<File (%s)>' % getattr(self, 'filename', '') -class Commit(Resource): +class GitCommit(Resource): - _maps = {'commit': GitCommit, 'author': User, 'committer': User, + _maps = {'author': User, 'committer': User, 'commit': Commit, 'stats': Stats} - _collection_maps = {'parents': GitCommit, 'files': File} + _collection_maps = {'parents': 'self', 'files': File} def __str__(self): - return '<Commit (%s)>' % getattr(self, 'author', '') + return '<GitCommit (%s)>' % getattr(self, 'sha', '') class Comment(Resource): diff --git a/pygithub3/services/base.py b/pygithub3/services/base.py index 1357815..886a666 100644 --- a/pygithub3/services/base.py +++ b/pygithub3/services/base.py @@ -2,7 +2,7 @@ # -*- encoding: utf-8 -*- from pygithub3.core.client import Client -from pygithub3.core import result +from pygithub3.core.result import smart, normal from pygithub3.requests.base import Factory from pygithub3.core.errors import NotFound @@ -138,8 +138,12 @@ class Service(object): return request.resource.loads(response.content) def _get_result(self, request, **kwargs): - method = result.smart.Method(self._client.get, request, **kwargs) - return result.smart.Result(method) + method = smart.Method(self._client.get, request, **kwargs) + return smart.Result(method) + + def _get_normal_result(self, request, **kwargs): + method = normal.Method(self._client.get, request, **kwargs) + return normal.Result(method) class MimeTypeMixin(object): diff --git a/pygithub3/services/repos/commits.py b/pygithub3/services/repos/commits.py index fd29fc0..4ba1ff1 100644 --- a/pygithub3/services/repos/commits.py +++ b/pygithub3/services/repos/commits.py @@ -12,10 +12,35 @@ class Commits(Service, MimeTypeMixin): This service support :ref:`mimetypes-section` configuration """ - #TODO: Pagination structure differs from usual - #def list(self, user=None, repo=None, sha='', path=''): - #request = self.make_request('repos.commits.list', user=user, repo=repo) - #return self._get_result(request, sha=sha, path=path) + def list(self, user=None, repo=None, sha=None, path=None): + """ Get repository's commits + + :param str user: Username + :param str repo: Repository + :param str sha: Sha or branch to start listing commits from + :param str path: Only commits containing this file path will be returned + :returns: A :doc:`result` + + .. note:: + Remember :ref:`config precedence` + + .. warning:: + Usually a repository has thousand of commits, so be careful when + consume the result. You should filter with ``sha`` or directly + clone the repository + + :: + + commits_service.list(user='octocat', repo='oct_repo') + commits_service.list(user='octocat', repo='oct_repo', sha='dev') + commits_service.list(user='django', repo='django', sha='master', + path='django/db/utils.py') + """ + request = self.make_request('repos.commits.list', user=user, repo=repo) + params = {} + params.update(sha and {'sha': sha} or {}) + params.update(path and {'path': path} or {}) + return self._get_normal_result(request, **params) def get(self, sha, user=None, repo=None): """ Get a single commit diff --git a/pygithub3/tests/services/test_repos.py b/pygithub3/tests/services/test_repos.py index bc5ed52..fd15fe9 100644 --- a/pygithub3/tests/services/test_repos.py +++ b/pygithub3/tests/services/test_repos.py @@ -179,13 +179,11 @@ class TestCommitsService(TestCase): def setUp(self): self.cs = Commits(user='oct', repo='re_oct') - """ def test_LIST(self, request_method): request_method.return_value = mock_response_result() self.cs.list().all() self.assertEqual(request_method.call_args[0], ('get', _('repos/oct/re_oct/commits'))) - """ def test_GET(self, request_method): request_method.return_value = mock_response() |