8000 Correct Status' documentation string · pythonthings/github3.py@00eea06 · GitHub
[go: up one dir, main page]

Skip to content

Commit 00eea06

Browse files
mindwsigmavirus24
authored andcommitted
Correct Status' documentation string
- Update @Vampire's work to account for Empty. - Add tests for combined status - Add changelog entry
1 parent 2c81ae5 commit 00eea06

File tree

6 files changed

+104
-9
lines changed

6 files changed

+104
-9
lines changed

LATEST_VERSION_NOTES.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ Unreleased
77
- Deprecate ``Organization#events`` in favor of ``Organization#public_events``.
88
- Fix test failtures on windows caused by unclosed file handles.
99
- Add ``Tag.tagger_as_User`` which attempts to return the tagger as as User.
10+
- Add ``Repo.statuses`` and a corresponding ``repo.status.CombinedStatus`` to
11+
get a combined view of commit statuses for a given ref.
1012

1113
1.0.0a4: 2016-02-19
1214
~~~~~~~~~~~~~~~~~~~

docs/repos.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,6 @@ about `comments <http://developer.github.com/v3/repos/comments/>`_.
154154

155155
---------
156156

157-
.. module:: github3.repos.status
158-
159157
.. autoclass:: github3.repos.status.CombinedStatus
160158
:members:
161159

github3/repos/commit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def status(self):
9595
"""Retrieve the combined status for this commit.
9696
9797
:returns: the combined status for this commit
98-
:rtype: :class:`~github3.repos.status.Status`
98+
:rtype: :class:`~github3.repos.status.CombinedStatus`
9999
"""
100100
url = self._build_url('status', base_url=self._api)
101101
json = self._json(self._get(url), 200)

github3/repos/status.py

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,37 @@ def _update_attributes(self, status):
4747
def _repr(self):
4848
return '<Status [{s.id}:{s.state}]>'.format(s=self)
4949

50+
5051
class CombinedStatus(GitHubCore):
51-
"""The :class:`CombinedStatus <CombinedStatus>` object. This represents combined
52-
information from the Repo Status API.
52+
"""The :class:`CombinedStatus <CombinedStatus>` object. This represents
53+
combined information from the Repo Status API.
5354
5455
See also: http://developer.github.com/v3/repos/statuses/
5556
"""
5657
def _update_attributes(self, combined_status):
5758
#: State of the combined status, e.g., 'success', 'pending', 'failure'
58-
self.state = combined_status.get('state')
59+
self.state = self._get_attribute(combined_status, 'state')
60+
61+
#: ref's SHA
62+
self.sha = self._get_attribute(combined_status, 'sha')
63+
5964
#: Total count of sub-statuses
60-
self.total_count = combined_status.get('total_count')
65+
self.total_count = self._get_attribute(combined_status, 'total_count')
66+
6167
#: List of :class:`Status <github3.repos.status.Status>`
6268
#: objects.
63-
self.statuses = [Status(status) for status in combined_status.get('statuses')]
69+
statuses = self._get_attribute(combined_status, 'statuses', [])
70+
self.statuses = [Status(s) for s in statuses]
71+
72+
from . import Repository
73+
#: Repository the combined status belongs too.
74+
self.repository = self._class_attribute(
75+
combined_status, 'repository', Repository, self
76+
)
77+
78+
#: commit URL
79+
self.commit_url = self._get_attribute(combined_status, 'commit_url')
6480

6581
def _repr(self):
66-
return '<CombinedStatus [{s.state}:{s.total_count} sub-statuses]>'.format(s=self)
82+
f = '<CombinedStatus [{s.state}:{s.total_count} sub-statuses]>'
83+
return f.format(s=self)
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{
2+
"state": "success",
3+
"sha": "6dcb09b5b57875f334f61aebed695e2e4193db5e",
4+
"total_count": 2,
5+
"statuses": [
6+
{
7+
"created_at": "2012-07-20T01:19:13Z",
8+
"updated_at": "2012-07-20T01:19:13Z",
9+
"state": "success",
10+
"target_url": "https://ci.example.com/1000/output",
11+
"description": "Build has completed successfully",
12+
"id": 1,
13+
"url": "https://api.github.com/repos/octocat/Hello-World/statuses/6dcb09b5b57875f334f61aebed695e2e4193db5e",
14+
"context": "continuous-integration/jenkins"
15+
},
16+
{
17+
"created_at": "2012-08-20T01:19:13Z",
18+
"updated_at": "2012-08-20T01:19:13Z",
19+
"state": "success",
20+
"target_url": "https://ci.example.com/2000/output",
21+
"description": "Testing has completed successfully",
22+
"id": 2,
23+
"url": "https://api.github.com/repos/octocat/Hello-World/statuses/6dcb09b5b57875f334f61aebed695e2e4193db5e",
24+
"context": "security/brakeman"
25+
}
26+
],
27+
"repository": {
28+
"id": 1296269,
29+
"owner": {
30+
"login": "octocat",
31+
"id": 1,
32+
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
33+
"gravatar_id": "",
34+
"url": "https://api.github.com/users/octocat",
35+
"html_url": "https://github.com/octocat",
36+
"followers_url": "https://api.github.com/users/octocat/followers",
37+
"following_url": "https://api.github.com/users/octocat/following{/other_user}",
38+
"gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",
39+
"starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",
40+
"subscriptions_url": "https://api.github.com/users/octocat/subscriptions",
41+
"organizations_url": "https://api.github.com/users/octocat/orgs",
42+
"repos_url": "https://api.github.com/users/octocat/repos",
43+
"events_url": "https://api.github.com/users/octocat/events{/privacy}",
44+
"received_events_url": "https://api.github.com/users/octocat/received_events",
45+
"type": "User",
46+
"site_admin": false
47+
},
48+
"name": "Hello-World",
49+
"full_name": "octocat/Hello-World",
50+
"description": "This your first repo!",
51+
"private": false,
52+
"fork": false,
53+
"url": "https://api.github.com/repos/octocat/Hello-World",
54+
"html_url": "https://github.com/octocat/Hello-World"
55+
},
56+
"commit_url": "https://api.github.com/repos/octocat/Hello-World/6dcb09b5b57875f334f61aebed695e2e4193db5e",
57+
"url": "https://api.github.com/repos/octocat/Hello-World/6dcb09b5b57875f334f61aebed695e2e4193db5e/status"
58+
}

tests/unit/test_repos_status.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import github3
2+
3+
from .helper import (UnitHelper, create_example_data_helper)
4+
5+
get_combined_status_example_data = \
6+
create_example_data_helper('repos_combined_status_example')
7+
8+
9+
class TestCombinedStatus(UnitHelper):
10+
11+
"""Commit unit test."""
12+
13+
described_class = github3.repos.status.CombinedStatus
14+
example_data = get_combined_status_example_data()
15+
16+
def test_repr(self):
17+
assert repr(self.instance).startswith('<CombinedStatus')
18+
19+
def test_statuses(self):
20+
assert len(self.instance.statuses) == self.instance.total_count

0 commit comments

Comments
 (0)
0