8000 Add retrieving of the combined status for a RepoCommit · JPWKU/github3.py@2c81ae5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2c81ae5

Browse files
Vampiresigmavirus24
authored andcommitted
Add retrieving of the combined status for a RepoCommit
1 parent 9aa43ea commit 2c81ae5

File tree

5 files changed

+148
-3
lines changed

5 files changed

+148
-3
lines changed

AUTHORS.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,6 @@ Contributors
142142
- Alexander Koshelev <daevaorn@gmail.com>
143143

144144
- Gabi Davar (@mindw)
145+
146+
- Björn Kautler (@Vampire)
147+

docs/repos.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ This part of the documentation covers:
2222
- :class:`RepoCommit <github3.repos.commit.RepoCommit>`
2323
- :class:`Comparison <github3.repos.comparison.Comparison>`
2424
- :class:`Status <github3.repos.status.Status>`
25+
- :class:`CombinedStatus <github3.repos.status.CombinedStatus>`
2526
- :class:`ContributorStats <github3.repos.stats.ContributorStats>`
2627

2728
None of these objects should be instantiated directly by the user (developer).
@@ -153,6 +154,13 @@ about `comments <http://developer.github.com/v3/repos/comments/>`_.
153154

154155
---------
155156

157+
.. module:: github3.repos.status
158+
159+
.. autoclass:: github3.repos.status.CombinedStatus
160+
:members:
161+
162+
---------
163+
156164
.. module:: github3.repos.stats
157165

158166
.. autoclass:: github3.repos.stats.ContributorStats

example-notebooks/statuses-api.ipynb

Lines changed: 109 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
"language": "python",
4747
"metadata": {},
4848
"outputs": [],
49-
"prompt_number": 5
< 10000 /code>49+
"prompt_number": 1
5050
},
5151
{
5252
"cell_type": "markdown",
@@ -66,7 +66,7 @@
6666
"language": "python",
6767
"metadata": {},
6868
"outputs": [],
69-
"prompt_number": 7
69+
"prompt_number": 2
7070
},
7171
{
7272
"cell_type": "markdown",
@@ -130,7 +130,113 @@
130130
]
131131
}
132132
],
133-
"prompt_number": 8
133+
"prompt_number": 3
134+
},
135+
{
136+
"cell_type": "heading",
137+
"level": 2,
138+
"metadata": {},
139+
"source": [
140+
"Listing Combined Status Associated with a Reference"
141+
]
142+
},
143+
{
144+
"cell_type": "code",
145+
"collapsed": false,
146+
"input": [
147+
"import github3\n",
148+
"\n",
149+
"\n",
150+
"repository = github3.repository('sigmavirus24', 'github3.py')"
151+
],
152+
"language": "python",
153+
"metadata": {},
154+
"outputs": [],
155+
"prompt_number": 1
156+
},
157+
{
158+
"cell_type": "markdown",
159+
"metadata": {},
160+
"source": [
161+
"With a repository object, we can now retrieve the statuses from a number of different commit-like objects which we can retrieve using the repository's ``commit`` method."
162+
]
163+
},
164+
{
165+
"cell_type": "code",
166+
"collapsed": false,
167+
"input": [
168+
"commit = repository.commit('9df71a9772d5f43e332c855a32d4689f28289989')\n",
169+
"tag = repository.commit('0.9.3')\n",
170+
"branch = repository.commit('stable/0.9')"
171+
],
172+
"language": "python",
173+
"metadata": {},
174+
"outputs": [],
175+
"prompt_number": 2
176+
},
177+
{
178+
"cell_type": "markdown",
179+
"metadata": {},
180+
"source": [
181+
"Each of these bindings now hold a reference to a different ``RepoCommit`` object and each has a ``status`` method. We can retrieve the combined status about each reference and print them."
182+
]
183+
},
184+
{
185+
"cell_type": "code",
186+
"collapsed": false,
187+
"input": [
188+
"for ref in (commit, tag, branch):\n",
189+
" print('Showing combined status for \"{0.sha}\" ({0.html_url})'.format(ref))\n",
190+
" combined_status = ref.status()\n",
191+
" print(\" State: {0.state}; Total count: {0.total_count}\".format(combined_status))\n",
192+
" print(\" Statuses:\")\n",
193+
" for status in combined_status.statuses:\n",
194+
" print(\" State: {0.state}; Description: {0.description}; Context: {0.context}\".format(status))"
195+
],
196+
"language": "python",
197+
"metadata": {},
198+
"outputs": [
199+
{
200+
"output_type": "stream",
201+
"stream": "stdout",
202+
"text": [
203+
"Showing combined status for \"9df71a9772d5f43e332c855a32d4689f28289989\" (https://github.com/sigmavirus24/github3.py/commit/9df71a9772d5f43e332c855a32d4689f28289989)\n",
204+
" State: success; Total count: 1"
205+
]
206+
},
207+
{
208+
"output_type": "stream",
209+
"stream": "stdout",
210+
"text": [
211+
"\n",
212+
" Statuses:\n",
213+
" State: success; Description: The Travis CI build passed; Context: continuous-integration/travis-ci\n",
214+
"Showing combined status for \"52a3f30e05cf434285e775979f01f1a8355049a7\" (https://github.com/sigmavirus24/github3.py/commit/52a3f30e05cf434285e775979f01f1a8355049a7)\n",
215+
" State: success; Total count: 1"
216+
]
217+
},
218+
{
219+
"output_type": "stream",
220+
"stream": "stdout",
221+
"text": [
222+
"\n",
223+
" Statuses:\n",
224+
" State: success; Description: The Travis CI build passed; Context: continuous-integration/travis-ci\n",
225+
"Showing combined status for \"c4c3fc3ea3b56152303a1a856d7d7fe220b9b8b4\" (https://github.com/sigmavirus24/github3.py/commit/c4c3fc3ea3b56152303a1a856d7d7fe220b9b8b4)\n",
226+
" State: failure; Total count: 1"
227+
]
228+
},
229+
{
230+
"output_type": "stream",
231+
"stream": "stdout",
232+
"text": [
233+
"\n",
234+
" Statuses:\n",
235+
" State: failure; Description: The Travis CI build failed; Context: continuous-integration/travis-ci/push\n"
236+
]
237+
}
238+
],
239+
"prompt_number": 3
134240
},
135241
{
136242
"cell_type": "heading",

github3/repos/commit.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,16 @@ def patch(self):
9191
headers={'Accept': 'application/vnd.github.patch'})
9292
return resp.content if self._boolean(resp, 200, 404) else b''
9393

94+
def status(self):
95+
"""Retrieve the combined status for this commit.
96+
97+
:returns: the combined status for this commit
98+
:rtype: :class:`~github3.repos.status.Status`
99+
"""
100+
url = self._build_url('status', base_url=self._api)
101+
json = self._json(self._get(url), 200)
102+
return self._instance_or_null(status.CombinedStatus, json)
103+
94104
def statuses(self):
95105
"""Retrieve the statuses for this commit.
96106

github3/repos/status.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,21 @@ def _update_attributes(self, status):
4646

4747
def _repr(self):
4848
return '<Status [{s.id}:{s.state}]>'.format(s=self)
49+
50+
class CombinedStatus(GitHubCore):
51+
"""The :class:`CombinedStatus <CombinedStatus>` object. This represents combined
52+
information from the Repo Status API.
53+
54+
See also: http://developer.github.com/v3/repos/statuses/
55+
"""
56+
def _update_attributes(self, combined_status):
57+
#: State of the combined status, e.g., 'success', 'pending', 'failure'
58+
self.state = combined_status.get('state')
59+
#: Total count of sub-statuses
60+
self.total_count = combined_status.get('total_count')
61+
#: List of :class:`Status <github3.repos.status.Status>`
62+
#: objects.
63+
self.statuses = [Status(status) for status in combined_status.get('statuses')]
64+
65+
def _repr(self):
66+
return '<CombinedStatus [{s.state}:{s.total_count} sub-statuses]>'.format(s=self)

0 commit comments

Comments
 (0)
0