Skip to content

Commit 18a8668

Browse files
committed
Merge copitux#29 from jone:statuses
2 parents af6bdbb + a1882ae commit 18a8668

File tree

7 files changed

+117
-1
lines changed

7 files changed

+117
-1
lines changed

AUTHORS.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,4 @@ Patches and Suggestions
3232
- Jason A. Donenfeld <Jason@zx2c4.com>
3333
- Brad Montgomery <http://about.me/bkmontgomery>
3434
- Thomas Whitton <mail@thomaswhitton.com>
35+
- Jonas Baumann <https://github.com/jone>

docs/repos.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,12 @@ Hooks
144144
.. autoclass:: pygithub3.services.repos.Hooks
145145
:members:
146146

147+
Statuses
148+
---------
149+
150+
.. autoclass:: pygithub3.services.repos.Statuses
151+
:members:
152+
147153
.. _github repos doc: http://developer.github.com/v3/repos
148154
.. _github collaborators doc: http://developer.github.com/v3/repos/collaborators
149155
.. _github commits doc: http://developer.github.com/v3/repos/commits
@@ -152,3 +158,4 @@ Hooks
152158
.. _github keys doc: http://developer.github.com/v3/repos/keys
153159
.. _github watching doc: http://developer.github.com/v3/repos/watching
154160
.. _github hooks doc: http://developer.github.com/v3/repos/hooks
161+
.. _github statuses doc: http://developer.github.com/v3/repos/statuses
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env python
2+
# -*- encoding: utf-8 -*-
3+
4+
from . import Request
5+
6+
from pygithub3.resources.repos import Status
7+
8+
9+
class List(Request):
10+
11+
uri = 'repos/{user}/{repo}/statuses/{sha}'
12+
resource = Status
13+
14+
15+
class Create(Request):
16+
17+
uri = '/repos/{user}/{repo}/statuses/{sha}'
18+
resource = Status
19+
body_schema = {
20+
'schema': ('state', 'target_url', 'description'),
21+
'required': ('state',)}

pygithub3/resources/repos.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,12 @@ class Hook(Resource):
115115

116116
def __str__(self):
117117
return '<Hook (%s)>' % getattr(self, 'name', '')
118+
119+
120+
class Status(Resource):
121+
122+
_dates = ('created_at', 'updated_at')
123+
_maps = {'creator': User}
124+
125+
def __str__(self):
126+
return '<Status (%s)>' % getattr(self, 'state', '')

pygithub3/services/repos/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from .watchers import Watchers
1010
from .stargazers import Stargazers
1111
from .hooks import Hooks
12+
from .statuses import Statuses
1213

1314

1415
class Repo(Service):
@@ -23,6 +24,7 @@ def __init__(self, **config):
2324
self.watchers = Watchers(**config)
2425
self.stargazers = Stargazers(**config)
2526
self.hooks = Hooks(**config)
27+
self.statuses = Statuses(**config)
2628
super(Repo, self).__init__(**config)
2729

2830
def list(self, user=None, type='all', sort='full_name', direction='desc'):
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/usr/bin/env python
2+
# -*- encoding: utf-8 -*-
3+
4+
from . import Service
5+
6+
7+
class Statuses(Service):
8+
""" Consume `Repo Statuses API
9+
<http://developer.github.com/v3/repos/statuses>`_ """
10+
11+
def list(self, sha=None, user=None, repo=None):
12+
""" Get repository's collaborators
13+
14+
:param str sha: Commit's sha
15+
:param str user: Username
16+
:param str repo: Repository
17+
:returns: A :doc:`result`
18+
19+
.. note::
20+
Remember :ref:`config precedence`
21+
"""
22+
23+
request = self.make_request('repos.statuses.list',
24+
sha=sha, user=user, repo=repo)
25+
return self._get_result(request)
26+
27+
def create(self, data, sha, user=None, repo=None):
28+
""" Create a status
29+
30+
:param dict data: Input. See `github statuses doc`_
31+
:param str sha: Commit's sha
32+
:param str user: Username
33+
:param str repo: Repository
34+
35+
.. note::
36+
Remember :ref:`config precedence`
37+
38+
.. warning::
39+
You must be authenticated
40+
41+
::
42+
43+
data = {
44+
"state": "success",
45+
"target_url": "https://example.com/build/status",
46+
"description": "The build succeeded!"
47+
}
48+
statuses_service.create(data, '6dcb09', user='octocat',
49+
repo='oct_repo')
50+
"""
51+
52+
request = self.make_request('repos.statuses.create',
53+
sha=sha, user=user, repo=repo, body=data)
54+
return self._post(request)

pygithub3/tests/services/test_repos.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from mock import patch
55

66
from pygithub3.services.repos import (Repo, Collaborators, Commits, Downloads,
7-
Forks, Keys, Watchers, Stargazers, Hooks)
7+
Forks, Keys, Watchers, Stargazers, Hooks, Statuses)
88
from pygithub3.tests.utils.base import (dummy_json, mock_response,
99
mock_response_result)
1010
from pygithub3.tests.utils.core import TestCase
@@ -459,3 +459,25 @@ def test_DELETE(self, request_method):
459459
self.hs.delete(1)
460460
self.assertEqual(request_method.call_args[0],
461461
('delete', _('repos/oct/re_oct/hooks/1')))
462+
463+
@dummy_json
464+
@patch.object(requests.sessions.Session, 'request')
465+
class TestStatusesService(TestCase):
466+
467+
def setUp(self):
468+
self.ss = Statuses(user='oct', repo='re_oct')
469+
470+
def test_LIST(self, request_method):
471+
request_method.return_value = mock_response_result()
472+
self.ss.list(sha='e3bc').all()
473+
self.assertEqual(request_method.call_args[0],
474+
('get', _('repos/oct/re_oct/statuses/e3bc')))
475+
476+
def test_CREATE(self, request_method):
477+
request_method.return_value = mock_response('post')
478+
self.ss.create({"state": "success",
479+
"target_url": "https://example.com/build/status",
480+
"description": "The build succeeded!"},
481+
sha='e3bc')
482+
self.assertEqual(request_method.call_args[0],
483+
('post', _('repos/oct/re_oct/statuses/e3bc')))

0 commit comments

Comments
 (0)