aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Medina <davidmedina9@gmail.com>2012-04-28 00:19:49 +0200
committerDavid Medina <davidmedina9@gmail.com>2012-04-28 22:35:30 +0200
commit1b1ccd6b86740157b2529614945a218d73049f4a (patch)
tree970b2dc73302268a8c0964e34d9b38aa1643d0d6
parentMerged pull request #3 from natw/git_data (diff)
downloadpython-github3-1b1ccd6b86740157b2529614945a218d73049f4a.tar.xz
python-github3-1b1ccd6b86740157b2529614945a218d73049f4a.zip
Litle fixs
-rw-r--r--pygithub3/requests/git_data/commits.py2
-rw-r--r--pygithub3/requests/git_data/references.py2
-rw-r--r--pygithub3/requests/git_data/trees.py6
-rw-r--r--pygithub3/services/base.py7
-rw-r--r--pygithub3/services/git_data/blobs.py14
-rw-r--r--pygithub3/services/git_data/commits.py19
-rw-r--r--pygithub3/services/git_data/references.py69
-rw-r--r--pygithub3/services/git_data/tags.py26
-rw-r--r--pygithub3/services/git_data/trees.py28
-rw-r--r--pygithub3/tests/services/test_git_data.py13
10 files changed, 101 insertions, 85 deletions
diff --git a/pygithub3/requests/git_data/commits.py b/pygithub3/requests/git_data/commits.py
index caf1e7d..a26e07d 100644
--- a/pygithub3/requests/git_data/commits.py
+++ b/pygithub3/requests/git_data/commits.py
@@ -1,7 +1,7 @@
# -*- encoding: utf-8 -*-
from pygithub3.requests.base import Request
-from pygithub3.resources.git_data import Commit
+from pygithub3.resources.repos import Commit
class Get(Request):
diff --git a/pygithub3/requests/git_data/references.py b/pygithub3/requests/git_data/references.py
index 99cf41a..2aac6a4 100644
--- a/pygithub3/requests/git_data/references.py
+++ b/pygithub3/requests/git_data/references.py
@@ -8,7 +8,7 @@ class Get(Request):
class List(Request):
- uri = 'repos/{user}/{repo}/git/refs'
+ uri = 'repos/{user}/{repo}/git/refs/{namespace}'
resource = Reference
diff --git a/pygithub3/requests/git_data/trees.py b/pygithub3/requests/git_data/trees.py
index bd1593f..11d6409 100644
--- a/pygithub3/requests/git_data/trees.py
+++ b/pygithub3/requests/git_data/trees.py
@@ -6,15 +6,11 @@ class Get(Request):
uri = 'repos/{user}/{repo}/git/trees/{sha}'
resource = Tree
- def clean_uri(self):
- if self.recursive:
- return self.uri + '?recursive=1'
-
class Create(Request):
uri = 'repos/{user}/{repo}/git/trees'
resource = Tree
body_schema = {
- 'schema': ('tree',),
+ 'schema': ('tree', 'base_tree'),
'required': ('tree',),
}
diff --git a/pygithub3/services/base.py b/pygithub3/services/base.py
index 886a666..1059371 100644
--- a/pygithub3/services/base.py
+++ b/pygithub3/services/base.py
@@ -80,6 +80,12 @@ class Service(object):
"""
self._client.set_token(token)
+ #TODO: Refact as decorator::
+ """
+ Reason: make_request and request_builder ... are confusing names
+ @precedence('user')
+ def list(self, sha, user=None):
+ """
def make_request(self, request, **kwargs):
if 'user' in kwargs:
kwargs['user'] = kwargs['user'] or self.get_user()
@@ -146,6 +152,7 @@ class Service(object):
return normal.Result(method)
+# XXX: Refact to set_<type> method
class MimeTypeMixin(object):
"""
Mimetype support to Services
diff --git a/pygithub3/services/git_data/blobs.py b/pygithub3/services/git_data/blobs.py
index 4f1a6e7..f6a2ff3 100644
--- a/pygithub3/services/git_data/blobs.py
+++ b/pygithub3/services/git_data/blobs.py
@@ -1,10 +1,10 @@
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
-from pygithub3.services.base import Service
+from pygithub3.services.base import Service, MimeTypeMixin
-class Blobs(Service):
+class Blobs(Service, MimeTypeMixin):
"""Consume `Blobs API <http://developer.github.com/v3/git/blobs/>`_"""
def get(self, sha, user=None, repo=None):
@@ -14,10 +14,12 @@ class Blobs(Service):
:param str user: Username
:param str repo: Repository
+ .. note::
+ Remember :ref:`config precedence`
"""
request = self.make_request('git_data.blobs.get', sha=sha,
- user=user, repo=repo)
- return self._get(request)
+ user=user, repo=repo)
+ return self._get(request, **self._get_mimetype_as_header())
def create(self, data, user=None, repo=None):
"""Create a blob
@@ -26,7 +28,9 @@ class Blobs(Service):
:param str user: Username
:param str repo: Repository
+ .. note::
+ Remember :ref:`config precedence`
"""
request = self.make_request('git_data.blobs.create', body=data,
- user=user, repo=repo)
+ user=user, repo=repo)
return self._post(request)
diff --git a/pygithub3/services/git_data/commits.py b/pygithub3/services/git_data/commits.py
index 25e8775..ddeed98 100644
--- a/pygithub3/services/git_data/commits.py
+++ b/pygithub3/services/git_data/commits.py
@@ -10,24 +10,27 @@ class Commits(Service):
def get(self, sha, user=None, repo=None):
"""get a commit from the current repo
- :param str sha: SHA of the Commit that you want.
+ :param str sha: SHA of the Commit that you want
:param str user: Username
:param str repo: Repository
+ .. note::
+ Remember :ref:`config precedence`
"""
request = self.make_request('git_data.commits.get', sha=sha,
- user=user, repo=repo)
+ user=user, repo=repo)
return self._get(request)
def create(self, data, user=None, repo=None):
"""create a commit on a repo
:param dict data: Input. See `github commits doc`_
- :param str user: username
- :param str repo: repository name
+ :param str user: Username
+ :param str repo: Repository
+ .. note::
+ Remember :ref:`config precedence`
"""
- return self._post(
- self.make_request('git_data.commits.create', user=user, repo=repo,
- body=data)
- )
+ request = self.make_request('git_data.commits.create', user=user,
+ repo=repo, body=data)
+ return self._post(request)
diff --git a/pygithub3/services/git_data/references.py b/pygithub3/services/git_data/references.py
index 3a24f90..0b46062 100644
--- a/pygithub3/services/git_data/references.py
+++ b/pygithub3/services/git_data/references.py
@@ -8,60 +8,66 @@ class References(Service):
"""Consume `References API <http://developer.github.com/v3/git/refs/>`_"""
def get(self, ref, user=None, repo=None):
- """Get a reference.
+ """ Get a reference
- .. note::
- Remember that branch references look like "heads/<branch_name>"
-
- :param str ref: the name of the reference to get
+ :param str ref: The name of the reference to get
:param str user: Username
:param str repo: Repository
+ .. note::
+ Remember :ref:`config precedence`
+
+ .. note::
+ Remember that branch references look like "heads/<branch_name>"
"""
- return self._get(
- self.make_request('git_data.references.get', ref=ref, user=user,
- repo=repo)
- )
+ request = self.make_request('git_data.references.get', ref=ref,
+ user=user, repo=repo)
+ return self._get(request)
def list(self, namespace='', user=None, repo=None):
- """List all the references
+ """ List all the references
:param str namespace: Limit the request to a particular type of
reference. For example, ``heads`` or ``tags``.
:param str user: Username
:param str repo: Repository
+ :returns: A :doc:`result`
+ .. note::
+ Remember :ref:`config precedence`
"""
- return self._get(
- self.make_request('git_data.references.list', user=user, repo=repo)
- )
+ request = self.make_request('git_data.references.list', user=user,
+ repo=repo, namespace=namespace)
+ return self._get_result(request)
- def create(self, body, user=None, repo=None):
- """Create a reference
+ def create(self, data, user=None, repo=None):
+ """ Create a reference
- :param dict body: Data describing the reference to create
+ :param dict data: Input. See `github refs doc`_
:param str user: Username
:param str repo: Repository
+ .. note::
+ Remember :ref:`config precedence`
"""
- return self._post(
- self.make_request('git_data.references.create', body=body,
- user=user, repo=repo)
- )
+ request = self.make_request('git_data.references.create', body=data,
+ user=user, repo=repo)
+ return self._post(request)
- def update(self, ref, body, user=None, repo=None):
- """Update an existing reference
+ def update(self, ref, data, user=None, repo=None):
+ """ Update an existing reference
:param str ref: The SHA of the reference to update
- :param dict body: Data to update the reference with
+ :param dict data: Input. See `github refs doc`_
:param str user: Username
:param str repo: Repository
+ .. note::
+ Remember :ref:`config precedence`
"""
- return self._patch(
- self.make_request('git_data.references.update', ref=ref, body=body,
- user=user, repo=repo)
- )
+ request = self.make_request('git_data.references.update', ref=ref,
+ body=data, user=user, repo=repo)
+ return self._patch(request)
def delete(self, ref, user=None, repo=None):
"""Delete a reference
@@ -70,8 +76,9 @@ class References(Service):
:param str user: Username
:param str repo: Repository
+ .. note::
+ Remember :ref:`config precedence`
"""
- return self._delete(
- self.make_request('git_data.references.delete', ref=ref, user=user,
- repo=repo)
- )
+ request = self.make_request('git_data.references.delete', ref=ref,
+ user=user, repo=repo)
+ return self._delete(request)
diff --git a/pygithub3/services/git_data/tags.py b/pygithub3/services/git_data/tags.py
index 03d38ac..337f6f0 100644
--- a/pygithub3/services/git_data/tags.py
+++ b/pygithub3/services/git_data/tags.py
@@ -8,27 +8,29 @@ class Tags(Service):
"""Consume `Tags API <http://developer.github.com/v3/git/tags/>`_"""
def get(self, sha, user=None, repo=None):
- """Get a tag
+ """ Get a tag
:param str sha: The sha of the tag to get.
:param str user: Username
:param str repo: Repository
+ .. note::
+ Remember :ref:`config precedence`
"""
- return self._get(
- self.make_request('git_data.tags.get', sha=sha, user=user,
- repo=repo)
- )
+ request = self.make_request('git_data.tags.get', sha=sha, user=user,
+ repo=repo)
+ return self._get(request)
- def create(self, body, user=None, repo=None):
- """Create a tag
+ def create(self, data, user=None, repo=None):
+ """ Create a tag
- :param dict body: Data describing the tag to create
+ :param dict data: Input. See `github tags doc`_
:param str user: Username
:param str repo: Repository
+ .. note::
+ Remember :ref:`config precedence`
"""
- return self._post(
- self.make_request('git_data.tags.create', body=body, user=user,
- repo=repo)
- )
+ request = self.make_request('git_data.tags.create', body=data,
+ user=user, repo=repo)
+ return self._post(request)
diff --git a/pygithub3/services/git_data/trees.py b/pygithub3/services/git_data/trees.py
index 00e010b..6032e74 100644
--- a/pygithub3/services/git_data/trees.py
+++ b/pygithub3/services/git_data/trees.py
@@ -8,7 +8,7 @@ class Trees(Service):
"""Consume `Trees API <http://developer.github.com/v3/git/trees/>`_"""
def get(self, sha, recursive=False, user=None, repo=None):
- """Get a tree object
+ """ Get a tree object
:param str sha: The SHA of the tree you want.
:param bool recursive: Whether to resolve each sub-tree belonging to
@@ -16,19 +16,23 @@ class Trees(Service):
:param str user: Username
:param str repo: Repository
+ .. note::
+ Remember :ref:`config precedence`
"""
- return self._get(
- self.make_request('git_data.trees.get', sha=sha,
- recursive=recursive, user=user, repo=repo)
- )
+ request = self.make_request('git_data.trees.get', sha=sha, user=user,
+ repo=repo)
+ return self._get(request, recursive=recursive)
- def create(self, body, user=None, repo=None):
- """Create a tree object
+ def create(self, data, user=None, repo=None):
+ """ Create a tree object
- :param dict body: Data describing the tree to create
+ :param dict data: Input. See `github trees doc`_
+ :param str user: Username
+ :param str repo: Repository
+ .. note::
+ Remember :ref:`config precedence`
"""
- return self._post(
- self.make_request('git_data.trees.create', body=body, user=user,
- repo=repo)
- )
+ request = self.make_request('git_data.trees.create', body=data,
+ user=user, repo=repo)
+ return self._post(request)
diff --git a/pygithub3/tests/services/test_git_data.py b/pygithub3/tests/services/test_git_data.py
index 45ef6d1..da1abf7 100644
--- a/pygithub3/tests/services/test_git_data.py
+++ b/pygithub3/tests/services/test_git_data.py
@@ -61,6 +61,7 @@ class TestCommitsService(TestCase):
('post', _('repos/octocat/repo/git/commits'))
)
+
@patch.object(requests.sessions.Session, 'request')
class TestReferencesService(TestCase):
def setUp(self):
@@ -75,8 +76,8 @@ class TestReferencesService(TestCase):
)
def test_LIST(self, reqm):
- reqm.return_value = mock_response()
- self.service.list()
+ reqm.return_value = mock_response_result()
+ self.service.list().all()
self.assertEqual(
reqm.call_args[0],
('get', _('repos/user/repo/git/refs'))
@@ -142,14 +143,6 @@ class TestTreesService(TestCase):
('get', _('repos/user/repo/git/trees/abc123'))
)
- def test_GET_recursive(self, reqm):
- reqm.return_value = mock_response()
- self.service.get('abc123', recursive=True)
- self.assertEqual(
- reqm.call_args[0],
- ('get', _('repos/user/repo/git/trees/abc123?recursive=1'))
- )
-
def test_CREATE(self, reqm):
reqm.return_value = mock_response('post')
self.service.create({