aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Medina <davidmedina9@gmail.com>2012-05-12 19:04:23 +0200
committerDavid Medina <davidmedina9@gmail.com>2012-05-12 22:47:09 +0200
commit24a3ed5dcd2264a64e234ea7bd526049fafe7616 (patch)
tree6131f221a9bf9b596dc139715d4e79f090bb55c3
parentDeleted 'dispatch' decorator. No sense (diff)
downloadpython-github3-24a3ed5dcd2264a64e234ea7bd526049fafe7616.tar.xz
python-github3-24a3ed5dcd2264a64e234ea7bd526049fafe7616.zip
Some fixes/typos and 'validate_body' related
Diffstat (limited to '')
-rw-r--r--docs/pull_requests.rst8
-rw-r--r--pygithub3/core/client.py2
-rw-r--r--pygithub3/requests/pull_requests/__init__.py20
-rw-r--r--pygithub3/requests/pull_requests/comments.py15
-rw-r--r--pygithub3/resources/pull_requests.py2
-rw-r--r--pygithub3/services/pull_requests/__init__.py40
-rw-r--r--pygithub3/services/pull_requests/comments.py31
-rw-r--r--pygithub3/tests/services/test_pull_requests.py19
8 files changed, 84 insertions, 53 deletions
diff --git a/docs/pull_requests.rst b/docs/pull_requests.rst
index 40c3435..09313eb 100644
--- a/docs/pull_requests.rst
+++ b/docs/pull_requests.rst
@@ -7,11 +7,10 @@ Pull Requests service
from pygithub3 import Github
- gh = Github()
+ gh = Github(user='octocat', repo='sample')
pull_requests = gh.pull_requests.list().all()
- for pr in pull_requests:
- commits = gh.pull_requests.list_commits(pr.number).all()
+ pull_request_commits = gh.pull_requests.list_commits(2512).all()
Pull Requests
-------------
@@ -31,3 +30,6 @@ Pull Request Comments
.. autoclass:: pygithub3.services.pull_requests.Comments
:members:
+
+.. _github pullrequests doc: http://developer.github.com/v3/pulls
+.. _github pullrequests comments doc: http://developer.github.com/v3/pulls/comments
diff --git a/pygithub3/core/client.py b/pygithub3/core/client.py
index eadb18e..ee7c97f 100644
--- a/pygithub3/core/client.py
+++ b/pygithub3/core/client.py
@@ -81,7 +81,7 @@ class Client(object):
def get(self, request, **kwargs):
response = self.request('get', request, **kwargs)
- # there are valid GET responses that != 200
+ assert response.status_code == 200
return response
def post(self, request, **kwargs):
diff --git a/pygithub3/requests/pull_requests/__init__.py b/pygithub3/requests/pull_requests/__init__.py
index bd03f3e..f25572d 100644
--- a/pygithub3/requests/pull_requests/__init__.py
+++ b/pygithub3/requests/pull_requests/__init__.py
@@ -1,5 +1,6 @@
+# -*- encoding: utf-8 -*-
+
from pygithub3.requests.base import Request, ValidationError
-from pygithub3.resources.base import Raw
from pygithub3.resources.pull_requests import PullRequest, File
from pygithub3.resources.repos import Commit
@@ -22,11 +23,12 @@ class Create(Request):
'required': ('base', 'head'),
}
- def validate_body(self, parsed):
- if (not ('title' in parsed and 'body' in parsed) and
- not 'issue' in parsed):
+ def clean_body(self):
+ if (not ('title' in self.body and 'body' in self.body) and
+ not 'issue' in self.body):
raise ValidationError('pull request creation requires either an '
'issue number or a title and body')
+ return self.body
class Update(Request):
uri = 'repos/{user}/{repo}/pulls/{number}'
@@ -36,10 +38,12 @@ class Update(Request):
'required': (),
}
- def validate_body(self, body):
- if 'state' in body and body['state'] not in ['open', 'closed']:
+ def clean_body(self):
+ if ('state' in self.body and
+ self.body['state'] not in ['open', 'closed']):
raise ValidationError('If a state is specified, it must be one '
'of "open" or "closed"')
+ return self.body
class List_commits(Request):
@@ -52,14 +56,12 @@ class List_files(Request):
resource = File
-class Merge_status(Request):
+class Is_merged(Request):
uri = 'repos/{user}/{repo}/pulls/{number}/merge'
- resource = Raw
class Merge(Request):
uri = 'repos/{user}/{repo}/pulls/{number}/merge'
- resource = Raw
body_schema = {
'schema': ('commit_message',),
'required': (),
diff --git a/pygithub3/requests/pull_requests/comments.py b/pygithub3/requests/pull_requests/comments.py
index fa1e5b6..dd69894 100644
--- a/pygithub3/requests/pull_requests/comments.py
+++ b/pygithub3/requests/pull_requests/comments.py
@@ -1,4 +1,6 @@
-from pygithub3.requests.base import Request
+# -*- encoding: utf-8 -*-
+
+from pygithub3.requests.base import Request, ValidationError
from pygithub3.resources.pull_requests import Comment
@@ -20,13 +22,14 @@ class Create(Request):
'required': ('body',),
}
- def validate_body(self, body):
- if (not ('commit_id' in body and
- 'path' in body and
- 'position' in body) and
- not 'in_reply_to' in body):
+ def clean_body(self):
+ if (not ('commit_id' in self.body and
+ 'path' in self.body and
+ 'position' in self.body) and
+ not 'in_reply_to' in self.body):
raise ValidationError('supply either in_reply_to or commit_id, '
'path, and position')
+ return self.body
class Edit(Request):
diff --git a/pygithub3/resources/pull_requests.py b/pygithub3/resources/pull_requests.py
index 1fe2623..a28e0fe 100644
--- a/pygithub3/resources/pull_requests.py
+++ b/pygithub3/resources/pull_requests.py
@@ -1,3 +1,5 @@
+# -*- encoding: utf-8 -*-
+
from .base import Resource
diff --git a/pygithub3/services/pull_requests/__init__.py b/pygithub3/services/pull_requests/__init__.py
index 66d9e58..545f862 100644
--- a/pygithub3/services/pull_requests/__init__.py
+++ b/pygithub3/services/pull_requests/__init__.py
@@ -1,4 +1,5 @@
-from pygithub3.exceptions import BadRequest, NotFound
+# -*- encoding: utf-8 -*-
+
from pygithub3.services.base import Service, MimeTypeMixin
from .comments import Comments
@@ -15,7 +16,10 @@ class PullRequests(Service, MimeTypeMixin):
:param str user: Username
:param str repo: Repository
+ :returns: A :doc:`result`
+ .. note::
+ Remember :ref:`config precedence`
"""
return self._get_result(
self.make_request('pull_requests.list', user=user, repo=repo)
@@ -28,37 +32,43 @@ class PullRequests(Service, MimeTypeMixin):
:param str user: Username
:param str repo: Repository
+ .. note::
+ Remember :ref:`config precedence`
"""
return self._get(
self.make_request('pull_requests.get', number=number, user=user,
repo=repo)
)
- def create(self, body, user=None, repo=None):
+ def create(self, data, user=None, repo=None):
"""Create a pull request
- :param dict body: Data for the new pull request
+ :param dict data: Input. See `github pullrequests doc`_
:param str user: Username
:param str repo: Repository
+ .. note::
+ Remember :ref:`config precedence`
"""
return self._post(
- self.make_request('pull_requests.create', body=body, user=user,
+ self.make_request('pull_requests.create', body=data, user=user,
repo=repo)
)
- def update(self, number, body, user=None, repo=None):
+ def update(self, number, data, user=None, repo=None):
"""Update a pull request
:param str number: The number of the the pull request to update
- :param dict body: The data to update the pull request with
+ :param dict data: Input. See `github pullrequests doc`_
:param str user: Username
:param str repo: Repository
+ .. note::
+ Remember :ref:`config precedence`
"""
return self._patch(
self.make_request('pull_requests.update', number=number,
- body=body, user=user, repo=repo)
+ body=data, user=user, repo=repo)
)
def list_commits(self, number, user=None, repo=None):
@@ -67,7 +77,10 @@ class PullRequests(Service, MimeTypeMixin):
:param str number: The number of the pull request to list commits for
:param str user: Username
:param str repo: Repository
+ :returns: A :doc:`result`
+ .. note::
+ Remember :ref:`config precedence`
"""
return self._get_result(
self.make_request('pull_requests.list_commits', number=number,
@@ -80,23 +93,28 @@ class PullRequests(Service, MimeTypeMixin):
:param str number: The number of the pull request to list files for
:param str user: Username
:param str repo: Repository
+ :returns: A :doc:`result`
+ .. note::
+ Remember :ref:`config precedence`
"""
return self._get_result(
self.make_request('pull_requests.list_files', number=number,
user=user, repo=repo)
)
- def merge_status(self, number, user=None, repo=None):
+ def is_merged(self, number, user=None, repo=None):
"""Gets whether a pull request has been merged or not.
:param str number: The pull request to check
:param str user: Username
:param str repo: Repository
+ .. note::
+ Remember :ref:`config precedence`
"""
return self._bool(
- self.make_request('pull_requests.merge_status', number=number,
+ self.make_request('pull_requests.is_merged', number=number,
user=user, repo=repo)
)
@@ -104,9 +122,13 @@ class PullRequests(Service, MimeTypeMixin):
"""Merge a pull request.
:param str number: The pull request to merge
+ :param str message: Message of pull request
:param str user: Username
:param str repo: Repository
+ .. note::
+ Remember :ref:`config precedence`
+
This currently raises an HTTP 405 error if the request is not
mergable.
diff --git a/pygithub3/services/pull_requests/comments.py b/pygithub3/services/pull_requests/comments.py
index 3aa6d0e..2edbfdf 100644
--- a/pygithub3/services/pull_requests/comments.py
+++ b/pygithub3/services/pull_requests/comments.py
@@ -1,11 +1,10 @@
+# -*- encoding: utf-8 -*-
from pygithub3.services.base import Service, MimeTypeMixin
class Comments(Service, MimeTypeMixin):
"""Consume `Review Comments API
- <http://developer.github.com/v3/pulls/comments/>`_
-
- """
+ <http://developer.github.com/v3/pulls/comments/>`_ """
def list(self, number, user=None, repo=None):
"""List all the comments for a pull request
@@ -13,7 +12,10 @@ class Comments(Service, MimeTypeMixin):
:param str number: The number of the pull request
:param str user: Username
:param str repo: Repository
+ :returns: A :doc:`result`
+ .. note::
+ Remember :ref:`config precedence`
"""
return self._get_result(
self.make_request('pull_requests.comments.list', number=number,
@@ -27,37 +29,44 @@ class Comments(Service, MimeTypeMixin):
:param str user: Username
:param str repo: Repository
+ .. note::
+ Remember :ref:`config precedence`
"""
return self._get(
self.make_request('pull_requests.comments.get', number=number,
user=user, repo=repo)
)
- def create(self, number, body, user=None, repo=None):
+ def create(self, number, data, user=None, repo=None):
"""Create a comment
:param str number: the pull request to comment on
+ :param dict data: Input. See `github pullrequests comments doc`_
:param str user: Username
:param str repo: Repository
+ .. note::
+ Remember :ref:`config precedence`
"""
return self._post(
self.make_request('pull_requests.comments.create', number=number,
- body=body, user=user, repo=repo)
+ body=data, user=user, repo=repo)
)
- def edit(self, number, body, user=None, repo=None):
+ def update(self, number, message, user=None, repo=None):
"""Edit a comment
:param str number: The id of the comment to edit
+ :param str message: Comment message
:param str user: Username
:param str repo: Repository
+ .. note::
+ Remember :ref:`config precedence`
"""
- return self._patch(
- self.make_request('pull_requests.comments.edit', number=number,
- body=body, user=user, repo=repo)
- )
+ request = self.make_request('pull_requests.comments.edit',
+ number=number, body={'body': message}, user=user, repo=repo)
+ return self._patch(request)
def delete(self, number, user=None, repo=None):
"""Delete a comment
@@ -66,6 +75,8 @@ class Comments(Service, MimeTypeMixin):
:param str user: Username
:param str repo: Repository
+ .. note::
+ Remember :ref:`config precedence`
"""
return self._delete(
self.make_request('pull_requests.comments.delete', number=number,
diff --git a/pygithub3/tests/services/test_pull_requests.py b/pygithub3/tests/services/test_pull_requests.py
index 7fc15b7..93646df 100644
--- a/pygithub3/tests/services/test_pull_requests.py
+++ b/pygithub3/tests/services/test_pull_requests.py
@@ -7,8 +7,7 @@ from nose.tools import raises
from pygithub3.tests.utils.core import TestCase
from pygithub3.services.pull_requests import PullRequests, Comments
-from pygithub3.resources.base import json
-from pygithub3.requests.base import ValidationError
+from pygithub3.requests.base import ValidationError, json
from pygithub3.tests.utils.base import (mock_response, mock_response_result,
mock_json)
from pygithub3.tests.utils.services import _
@@ -107,19 +106,9 @@ class TestPullRequestsService(TestCase):
('get', _('repos/user/repo/pulls/123/files'))
)
- def test_MERGE_STATUS_true(self, reqm):
- reqm.return_value = mock_response(204)
- resp = self.service.merge_status(123)
- self.assertEqual(True, resp)
- self.assertEqual(
- reqm.call_args[0],
- ('head', _('repos/user/repo/pulls/123/merge'))
- )
-
- def test_MERGE_STATUS_false(self, reqm):
- reqm.return_value = mock_response(404)
- resp = self.service.merge_status(123)
- self.assertEqual(False, resp)
+ def test_IS_MERGED(self, reqm):
+ resp = self.service.is_merged(123)
+ self.assertTrue(resp)
self.assertEqual(
reqm.call_args[0],
('head', _('repos/user/repo/pulls/123/merge'))