aboutsummaryrefslogtreecommitdiffstats
path: root/pygithub3
diff options
context:
space:
mode:
authorConor Branagan <conor.branagan@gmail.com>2012-04-11 17:11:08 -0400
committerAlejandro Gómez <alejandroogomez@gmail.com>2012-05-27 19:54:28 +0200
commit61c438619634c80a9fb5579beb0a6609eaf00f2d (patch)
tree1f4897572042ff397ee02e24b58215316fefdd5c /pygithub3
parentMerge pull request #11 from dsc/patch-1 (diff)
downloadpython-github3-61c438619634c80a9fb5579beb0a6609eaf00f2d.tar.xz
python-github3-61c438619634c80a9fb5579beb0a6609eaf00f2d.zip
Add issues service for issues, comments and events. has tests and updated docs
Diffstat (limited to 'pygithub3')
-rw-r--r--pygithub3/github.py5
-rw-r--r--pygithub3/requests/issues/__init__.py51
-rw-r--r--pygithub3/requests/issues/comments.py42
-rw-r--r--pygithub3/requests/issues/events.py22
-rw-r--r--pygithub3/resources/issues.py31
-rw-r--r--pygithub3/services/issues/__init__.py82
-rw-r--r--pygithub3/services/issues/comments.py75
-rw-r--r--pygithub3/services/issues/events.py42
-rw-r--r--pygithub3/tests/services/test_issues.py115
9 files changed, 465 insertions, 0 deletions
diff --git a/pygithub3/github.py b/pygithub3/github.py
index 87c4a6d..5f95505 100644
--- a/pygithub3/github.py
+++ b/pygithub3/github.py
@@ -19,11 +19,16 @@ class Github(object):
from pygithub3.services.gists import Gist
from pygithub3.services.git_data import GitData
from pygithub3.services.pull_requests import PullRequests
+ from pygithub3.services.issues import Issue
self._users = User(**config)
self._repos = Repo(**config)
self._gists = Gist(**config)
self._git_data = GitData(**config)
self._pull_requests = PullRequests(**config)
+ self._users = User(**config)
+ self._repos = Repo(**config)
+ self._gists = Gist(**config)
+ self._issues = Issue(**config)
@property
def remaining_requests(self):
diff --git a/pygithub3/requests/issues/__init__.py b/pygithub3/requests/issues/__init__.py
new file mode 100644
index 0000000..ca8afb1
--- /dev/null
+++ b/pygithub3/requests/issues/__init__.py
@@ -0,0 +1,51 @@
+#!/usr/bin/env python
+# -*- encoding: utf-8 -*-
+
+from pygithub3.requests.base import Request, ValidationError
+from pygithub3.resources.issues import Issue
+
+class List(Request):
+
+ uri = 'issues'
+ resource = Issue
+ body_schema = {
+ 'schema': ('filter', 'state', 'labels', 'sort', 'direction', 'since'),
+ 'required': ()
+ }
+
+
+class List_by_repo(Request):
+
+ uri = 'repos/{user}/{repo}/issues'
+ resource = Issue
+ body_schema = {
+ 'schema': ('milestone', 'state', 'assignee', 'mentioned', 'labels',
+ 'sort', 'direction', 'since'),
+ 'required': ()
+ }
+
+
+class Get(Request):
+
+ uri = 'repos/{user}/{repo}/issues/{number}'
+ resource = Issue
+
+
+class Create(Request):
+
+ uri = 'repos/{user}/{repo}/issues'
+ resource = Issue
+ body_schema = {
+ 'schema': ('title', 'body', 'assignee', 'milestone', 'labels'),
+ 'required': ('title', )
+ }
+
+
+class Edit(Request):
+
+ uri = 'repos/{user}/{repo}/issues/{number}'
+ resource = Issue
+ body_schema = {
+ 'schema': ('title', 'body', 'assignee', 'state', 'milestone', 'lables'),
+ 'required': ()
+ } \ No newline at end of file
diff --git a/pygithub3/requests/issues/comments.py b/pygithub3/requests/issues/comments.py
new file mode 100644
index 0000000..0601db3
--- /dev/null
+++ b/pygithub3/requests/issues/comments.py
@@ -0,0 +1,42 @@
+#!/usr/bin/env python
+# -*- encoding: utf-8 -*-
+
+from pygithub3.requests.base import Request, ValidationError
+from pygithub3.resources.issues import Comment
+
+class List(Request):
+
+ uri = 'repos/{user}/{repo}/issues/{number}/comments'
+ resource = Comment
+
+
+class Get(Request):
+
+ uri = 'repos/{user}/{repo}/issues/comments/{id}'
+ resource = Comment
+
+
+class Create(Request):
+
+ uri = 'repos/{user}/{repo}/issues/{number}/comments'
+ resource = Comment
+ body_schema = {
+ 'schema': ('body', ),
+ 'required': ('body', )
+ }
+
+
+class Edit(Request):
+
+ uri = 'repos/{user}/{repo}/issues/comments/{id}'
+ resource = Comment
+ body_schema = {
+ 'schema': ('body', ),
+ 'required': ('body', )
+ }
+
+
+class Delete(Request):
+
+ uri = 'repos/{user}/{repo}/issues/comments/{id}'
+ resource = Comment \ No newline at end of file
diff --git a/pygithub3/requests/issues/events.py b/pygithub3/requests/issues/events.py
new file mode 100644
index 0000000..dfefe7e
--- /dev/null
+++ b/pygithub3/requests/issues/events.py
@@ -0,0 +1,22 @@
+#!/usr/bin/env python
+# -*- encoding: utf-8 -*-
+
+from pygithub3.requests.base import Request, ValidationError
+from pygithub3.resources.issues import Event
+
+class List_by_issue(Request):
+
+ uri = 'repos/{user}/{repo}/issues/{number}/events'
+ resource = Event
+
+
+class List_by_repo(Request):
+
+ uri = 'repos/{user}/{repo}/issues/events'
+ resource = Event
+
+
+class Get(Request):
+
+ uri = 'repos/{user}/{repo}/issues/events/{id}'
+ resource = Event
diff --git a/pygithub3/resources/issues.py b/pygithub3/resources/issues.py
new file mode 100644
index 0000000..ce5b304
--- /dev/null
+++ b/pygithub3/resources/issues.py
@@ -0,0 +1,31 @@
+#!/usr/bin/env python
+# -*- encoding: utf-8 -*-
+
+from .base import Resource
+from .users import User
+
+class Issue(Resource):
+
+ _dates = ('created_at', 'updated_at')
+ _maps = {'assignee': User}
+
+ def __str__(self):
+ return '<Issue (%s)>' % getattr(self, 'number', '')
+
+
+class Comment(Resource):
+
+ _dates = ('created_at', 'update_at')
+ _maps = {'user': User}
+
+ def __str__(self):
+ return '<Comment (%s)>' % (getattr(self, 'user', ''))
+
+
+class Event(Resource):
+
+ _dates = ('created_at', )
+ _maps = {'actor': User}
+
+ def __str__(self):
+ return '<Event (%s)>' % (getattr(self, 'commit_id', '')) \ No newline at end of file
diff --git a/pygithub3/services/issues/__init__.py b/pygithub3/services/issues/__init__.py
new file mode 100644
index 0000000..0699f9e
--- /dev/null
+++ b/pygithub3/services/issues/__init__.py
@@ -0,0 +1,82 @@
+#!/usr/bin/env python
+# -*- encoding: utf-8 -*-
+
+from pygithub3.services.base import Service
+from .comments import Comments
+from .events import Events
+
+class Issue(Service):
+ """ Consume `Issues API <http://developer.github.com/v3/issues>`_ """
+
+ def __init__(self, **config):
+ self.comments = Comments(**config)
+ self.events = Events(**config)
+ super(Issue, self).__init__(**config)
+
+ def list(self, data={}):
+ """ List your issues
+
+ :param dict data: Input. See `github issues doc`_
+ :returns: A :doc:`result`
+
+ .. warning::
+ You must be authenticated
+ """
+ request = self.request_builder('issues.list', body=data)
+ return self._get_result(request)
+
+ def list_by_repo(self, user, repo, data={}):
+ """ List issues for a repo
+
+ :param dict data: Input. See `github issues doc`_
+ :returns: A :doc:`result`
+ """
+ request = self.request_builder('issues.list_by_repo', user=user,
+ repo=repo, body=data)
+ return self._get_result(request)
+
+ def get(self, user, repo, number):
+ """ Get a single issue
+
+ :param str user: Username
+ :param str repo: Repo name
+ :param int number: Issue number
+ """
+ request = self.request_builder('issues.get', user=user, repo=repo,
+ number=number)
+ return self._get(request)
+
+ def create(self, user, repo, data):
+ """ Create an issue
+
+ :param str user: Username
+ :param str repo: Repo name
+ :param dict data: Input. See `github issues doc`_
+
+ .. warning::
+ You must be authenticated
+
+ ::
+
+ issues_service.create(dict(title='My test issue',
+ body='This needs to be fixed ASAP.',
+ assignee='copitux'))
+ """
+ request = self.request_builder('issues.create', user=user, repo=repo,
+ body=data)
+ return self._post(request)
+
+ def update(self, user, repo, number, data):
+ """ Edit an issue
+
+ :param str user: Username
+ :param str repo: Repo name
+ :param int number: Issue number
+ :param dict data: Input. See `github issues doc`_
+
+ .. warning::
+ You must be authenticated
+ """
+ request = self.request_builder('issues.edit', user=user, repo=repo,
+ number=number, body=data)
+ return self._patch(request) \ No newline at end of file
diff --git a/pygithub3/services/issues/comments.py b/pygithub3/services/issues/comments.py
new file mode 100644
index 0000000..f367a58
--- /dev/null
+++ b/pygithub3/services/issues/comments.py
@@ -0,0 +1,75 @@
+#!/usr/bin/env python
+# -*- encoding: utf-8 -*-
+
+from pygithub3.services.base import Service
+
+class Comments(Service):
+ """ Consume `Comments API
+ <http://developer.github.com/v3/issues/comments>`_ """
+
+ def list(self, user, repo, number):
+ """ List comments for an issue
+
+ :param str user: Username
+ :param str repo: Repo name
+ :param int number: Issue number
+ :returns: A :doc:`result`
+ """
+ request = self.request_builder('issues.comments.list', user=user,
+ repo=repo, number=number)
+ return self._get_result(request)
+
+ def get(self, user, repo, id):
+ """ Get a single comment
+
+ :param str user: Username
+ :param str repo: Repo name
+ :param int id: Comment id
+ """
+ request = self.request_builder('issues.comments.get', user=user,
+ repo=repo, id=id)
+ return self._get(request)
+
+ def create(self, user, repo, number, message):
+ """ Create a comment on an issue
+
+ :param str user: Username
+ :param str repo: Repo name
+ :param int number: Issue number
+ :param str message: Comment message
+
+ .. warning::
+ You must be authenticated
+ """
+ request = self.request_builder('issues.comments.create', user=user,
+ repo=repo, number=number, body={'body': message})
+ return self._post(request)
+
+ def update(self, user, repo, id, message):
+ """ Update a comment on an issue
+
+ :param str user: Username
+ :param str repo: Repo name
+ :param int id: Issue id
+ :param str message: Comment message
+
+ .. warning::
+ You must be authenticated
+ """
+ request = self.request_builder('issues.comments.edit', user=user,
+ repo=repo, id=id, body={'body': message})
+ return self._patch(request)
+
+ def delete(self, user, repo, id):
+ """ Delete a single comment
+
+ :param str user: Username
+ :param str repo: Repo name
+ :param int id: Comment id
+
+ ... warning::
+ You must be authenticated
+ """
+ request = self.request_builder('issues.comments.delete', user=user,
+ repo=repo, id=id)
+ self._delete(request) \ No newline at end of file
diff --git a/pygithub3/services/issues/events.py b/pygithub3/services/issues/events.py
new file mode 100644
index 0000000..0111db4
--- /dev/null
+++ b/pygithub3/services/issues/events.py
@@ -0,0 +1,42 @@
+#!/usr/bin/env python
+# -*- encoding: utf-8 -*-
+
+from pygithub3.services.base import Service
+
+class Events(Service):
+ """ Consume `Events API
+ <http://developer.github.com/v3/issues/events>`_ """
+
+ def list_by_issue(self, user, repo, number):
+ """ List events for an issue
+
+ :param str user: Username
+ :param str repo: Repo name
+ :param int number: Issue number
+ :returns: A :doc:`result`
+ """
+ request = self.request_builder('issues.events.list_by_issue',
+ user=user, repo=repo, number=number)
+ return self._get_result(request)
+
+ def list_by_repo(self, user, repo):
+ """ List events for a repository
+
+ :param str user: Username
+ :param str repo: Repo name
+ :returns: A :doc:`result`
+ """
+ request = self.request_builder('issues.events.list_by_repo',
+ user=user, repo=repo)
+ return self._get_result(request)
+
+ def get(self, user, repo, id):
+ """ Get a single event
+
+ :param str user: Username
+ :param str repo: Repo name
+ :param int id: Comment id
+ """
+ request = self.request_builder('issues.events.get', user=user,
+ repo=repo, id=id)
+ return self._get(request) \ No newline at end of file
diff --git a/pygithub3/tests/services/test_issues.py b/pygithub3/tests/services/test_issues.py
new file mode 100644
index 0000000..dfc56ca
--- /dev/null
+++ b/pygithub3/tests/services/test_issues.py
@@ -0,0 +1,115 @@
+#!/usr/bin/env python
+# -*- encoding: utf-8 -*-
+
+import requests
+from mock import patch, Mock
+
+from pygithub3.tests.utils.core import TestCase
+from pygithub3.resources.base import json
+from pygithub3.services.issues import Issue, Comments, Events
+from pygithub3.tests.utils.base import (mock_response, mock_response_result,
+ mock_json)
+from pygithub3.tests.utils.services import _
+
+json.dumps = Mock(side_effect=mock_json)
+json.loads = Mock(side_effect=mock_json)
+
+
+@patch.object(requests.sessions.Session, 'request')
+class TestIssuesService(TestCase):
+
+ def setUp(self):
+ self.isu = Issue()
+
+ def test_LIST_without_user(self, request_method):
+ request_method.return_value = mock_response_result()
+ self.isu.list().all()
+ self.assertEqual(request_method.call_args[0], ('get', _('issues')))
+
+ def test_LIST_by_repo(self, request_method):
+ request_method.return_value = mock_response_result()
+ self.isu.list_by_repo('octocat', 'Hello-World').all()
+ self.assertEqual(request_method.call_args[0],
+ ('get', _('repos/octocat/Hello-World/issues')))
+
+ def test_GET(self, request_method):
+ request_method.return_value = mock_response()
+ self.isu.get('octocat', 'Hello-World', 1)
+ self.assertEqual(request_method.call_args[0],
+ ('get', _('repos/octocat/Hello-World/issues/1')))
+
+ def test_CREATE(self, request_method):
+ request_method.return_value = mock_response('post')
+ self.isu.create('octocat', 'Hello-World',
+ dict(title='My issue', body='Fix this issue'))
+ self.assertEqual(request_method.call_args[0],
+ ('post', _('repos/octocat/Hello-World/issues')))
+
+ def test_UPDATE(self, request_method):
+ request_method.return_value = mock_response('patch')
+ self.isu.update('octocat', 'Hello-World', 1,
+ {'body': 'edited'})
+ self.assertEqual(request_method.call_args[0],
+ ('patch', _('repos/octocat/Hello-World/issues/1')))
+
+
+@patch.object(requests.sessions.Session, 'request')
+class TestCommentService(TestCase):
+
+ def setUp(self):
+ self.cs = Comments()
+
+ def test_LIST(self, request_method):
+ request_method.return_value = mock_response_result()
+ self.cs.list('octocat', 'Hello-World', 1).all()
+ self.assertEqual(request_method.call_args[0],
+ ('get', _('repos/octocat/Hello-World/issues/1/comments')))
+
+ def test_GET(self, request_method):
+ request_method.return_value = mock_response()
+ self.cs.get('octocat', 'Hello-World', 1)
+ self.assertEqual(request_method.call_args[0],
+ ('get', _('repos/octocat/Hello-World/issues/comments/1')))
+
+ def test_CREATE(self, request_method):
+ request_method.return_value = mock_response('post')
+ self.cs.create('octocat', 'Hello-World', 1, 'comment')
+ self.assertEqual(request_method.call_args[0],
+ ('post', _('repos/octocat/Hello-World/issues/1/comments')))
+
+ def test_UPDATE(self, request_method):
+ request_method.return_value = mock_response('patch')
+ self.cs.update('octocat', 'Hello-World', 1, 'new comment')
+ self.assertEqual(request_method.call_args[0],
+ ('patch', _('repos/octocat/Hello-World/issues/comments/1')))
+
+ def test_DELETE(self, request_method):
+ request_method.return_value = mock_response('delete')
+ self.cs.delete('octocat', 'Hello-World', 1)
+ self.assertEqual(request_method.call_args[0],
+ ('delete', _('repos/octocat/Hello-World/issues/comments/1')))
+
+
+@patch.object(requests.sessions.Session, 'request')
+class TestEventsService(TestCase):
+
+ def setUp(self):
+ self.ev = Events()
+
+ def test_LIST_by_issue(self, request_method):
+ request_method.return_value = mock_response_result()
+ self.ev.list_by_issue('octocat', 'Hello-World', 1).all()
+ self.assertEqual(request_method.call_args[0],
+ ('get', _('repos/octocat/Hello-World/issues/1/events')))
+
+ def test_LIST_by_repo(self, request_method):
+ request_method.return_value = mock_response_result()
+ self.ev.list_by_repo('octocat', 'Hello-World').all()
+ self.assertEqual(request_method.call_args[0],
+ ('get', _('repos/octocat/Hello-World/issues/events')))
+
+ def test_GET(self, request_method):
+ request_method.return_value = mock_response()
+ self.ev.get('octocat', 'Hello-World', 1)
+ self.assertEqual(request_method.call_args[0],
+ ('get', _('repos/octocat/Hello-World/issues/events/1'))) \ No newline at end of file