Skip to content

Commit 167d600

Browse files
committed
Add statuses service.
1 parent 989af83 commit 167d600

File tree

3 files changed

+79
-1
lines changed

3 files changed

+79
-1
lines changed

pygithub3/services/repos/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from .keys import Keys
99
from .watchers import Watchers
1010
from .hooks import Hooks
11+
from .statuses import Statuses
1112

1213

1314
class Repo(Service):
@@ -21,6 +22,7 @@ def __init__(self, **config):
2122
self.keys = Keys(**config)
2223
self.watchers = Watchers(**config)
2324
self.hooks = Hooks(**config)
25+
self.statuses = Statuses(**config)
2426
super(Repo, self).__init__(**config)
2527

2628
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, Hooks)
7+
Forks, Keys, Watchers, 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
@@ -416,3 +416,25 @@ def test_DELETE(self, request_method):
416416
self.hs.delete(1)
417417
self.assertEqual(request_method.call_args[0],
418418
('delete', _('repos/oct/re_oct/hooks/1')))
419+
420+
@dummy_json
421+
@patch.object(requests.sessions.Session, 'request')
422+
class TestStatusesService(TestCase):
423+
424+
def setUp(self):
425+
self.ss = Statuses(user='oct', repo='re_oct')
426+
427+
def test_LIST(self, request_method):
428+
request_method.return_value = mock_response_result()
429+
self.ss.list(sha='e3bc').all()
430+
self.assertEqual(request_method.call_args[0],
431+
('get', _('repos/oct/re_oct/statuses/e3bc')))
432+
433+
def test_CREATE(self, request_method):
434+
request_method.return_value = mock_response('post')
435+
self.ss.create({"state": "success",
436+
"target_url": "https://example.com/build/status",
437+
"description": "The build succeeded!"},
438+
sha='e3bc')
439+
self.assertEqual(request_method.call_args[0],
440+
('post', _('repos/oct/re_oct/statuses/e3bc')))

0 commit comments

Comments
 (0)