8000 Add a notebook for creating and listing statuses · helenst/github3.py@36b4a67 · GitHub
[go: up one dir, main page]

Skip to content

Commit 36b4a67

Browse files
committed
Add a notebook for creating and listing statuses
Related sigmavirus24#256
1 parent 020cfe6 commit 36b4a67

File tree

1 file changed

+201
-0
lines changed

1 file changed

+201
-0
lines changed

example-notebooks/statuses-api.ipynb

Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
{
2+
"metadata": {
3+
"name": "",
4+
"signature": "sha256:71986a4706e141c811d01b30504f39a773bc952ce68dfb45fbd9155fcbde0956"
5+
},
6+
"nbformat": 3,
7+
"nbformat_minor": 0,
8+
"worksheets": [
9+
{
10+
"cells": [
11+
{
12+
"cell_type": "heading",
13+
"level": 1,
14+
"metadata": {},
15+
"source": [
16+
"An Overview of the Statuses API in github3.py"
17+
]
18+
},
19+
{
20+
"cell_type": "markdown",
21+
"metadata": {},
22+
"source": [
23+
"GitHub's [Statuses API][statuses] is one of the more popular recent additions to GitHub's large and all-encompassing API. This API allows you to create and list statuses like those created by popular Continuous Integration services (e.g., Jenkins, Travis CI, etc.). github3.py provides unfettered access to these functions and the following should help explore that functionality.\n",
24+
"\n",
25+
"\n",
26+
"[statuses]: https://developer.github.com/v3/repos/statuses/"
27+
]
28+
},
29+
{
30+
"cell_type": "heading",
31+
"level": 2,
32+
"metadata": {},
33+
"source": [
34+
"Listing Statuses Associated with a Reference"
35+
]
36+
},
37+
{
38+
"cell_type": "code",
39+
"collapsed": false,
40+
"input": [
41+
"import github3\n",
42+
"\n",
43+
"\n",
44+
"repository = github3.repository('sigmavirus24', 'github3.py')"
45+
],
46+
"language": "python",
47+
"metadata": {},
48+
"outputs": [],
49+
"prompt_number": 5
50+
},
51+
{
52+
"cell_type": "markdown",
53+
"metadata": {},
54+
"source": [
55+
"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."
56+
]
57+
},
58+
{
59+
"cell_type": "code",
60+
"collapsed": false,
61+
"input": [
62+
"commit = repository.commit('9df71a9772d5f43e332c855a32d4689f28289989')\n",
63+
"tag = repository.commit('0.9.3')\n",
64+
"branch = repository.commit('stable/0.9')"
65+
],
66+
"language": "python",
67+
"metadata": {},
68+
"outputs": [],
69+
"prompt_number": 7
70+
},
71+
{
72+
"cell_type": "markdown",
73+
"metadata": {},
74+
"source": [
75+
"Each of these bindings now hold a reference to a different ``RepoCommit`` object and each has a ``statuses`` method. We can retrieve statuses about each reference and print them."
76+
]
77+
},
78+
{
79+
"cell_type": "code",
80+
"collapsed": false,
81+
"input": [
82+
"for ref in (commit, tag, branch):\n",
83+
" print('Showing statuses for \"{0.sha}\" ({0.html_url})'.format(ref))\n",
84+
" for status in ref.statuses():\n",
85+
" print(\" State: {0.state}; Description: {0.description}; Context: {0.context}\".format(status))"
86+
],
87+
"language": "python",
88+
"metadata": {},
89+
"outputs": [
90+
{
91+
"output_type": "stream",
92+
"stream": "stdout",
93+
"text": [
94+
"Showing statuses for \"9df71a9772d5f43e332c855a32d4689f28289989\" (https://github.com/sigmavirus24/github3.py/commit/9df71a9772d5f43e332c855a32d4689f28289989)\n",
95+
" State: success; Description: The Travis CI build passed; Context: continuous-integration/travis-ci"
96+
]
97+
},
98+
{
99+
"output_type": "stream",
100+
"stream": "stdout",
101+
"text": [
102+
"\n",
103+
" State: pending; Description: The Travis CI build is in progress; Context: continuous-integration/travis-ci\n",
104+
" State: pending; Description: The Travis CI build is in progress; Context: continuous-integration/travis-ci\n",
105+
"Showing statuses for \"52a3f30e05cf434285e775979f01f1a8355049a7\" (https://github.com/sigmavirus24/github3.py/commit/52a3f30e05cf434285e775979f01f1a8355049a7)\n",
106+
" State: success; Description: The Travis CI build passed; Context: continuous-integration/travis-ci"
107+
]
108+
},
109+
{
110+
"output_type": "stream",
111+
"stream": "stdout",
112+
"text": [
113+
"\n",
114+
" State: success; Description: The Travis CI build passed; Context: continuous-integration/travis-ci\n",
115+
" State: pending; Description: The Travis CI build is in progress; Context: continuous-integration/travis-ci\n",
116+
" State: pending; Description: The Travis CI build is in progress; Context: continuous-integration/travis-ci\n",
117+
" State: pending; Description: The Travis CI build is in progress; Context: continuous-integration/travis-ci\n",
118+
" State: pending; Description: The Travis CI build is in progress; Context: continuous-integration/travis-ci\n",
119+
"Showing statuses for \"6e97462ade3d8855644296e7a44b5463c7b222a6\" (https://github.com/sigmavirus24/github3.py/commit/6e97462ade3d8855644296e7a44b5463c7b222a6)\n",
120+
" State: success; Description: The Travis CI build passed; Context: continuous-integration/travis-ci"
121+
]
122+
},
123+
{
124+
"output_type": "stream",
125+
"stream": "stdout",
126+
"text": [
127+
"\n",
128+
" State: pending; Description: The Travis CI build is in progress; Context: continuous-integration/travis-ci\n",
129+
" State: pending; Description: The Travis CI build is in progress; Context: continuous-integration/travis-ci\n"
130+
]
131+
}
132+
],
133+
"prompt_number": 8
134+
},
135+
{
136+
"cell_type": "heading",
137+
"level": 2,
138+
"metadata": {},
139+
"source": [
140+
"Creating a Status for a Reference"
141+
]
142+
},
143+
{
144+
"cell_type": "code",
145+
"collapsed": false,
146+
"input": [
147+
"import github3\n",
148+
"import os\n",
149+
"\n",
150+
"g = github3.login(os.environ['GH_USERNAME'], os.environ['GH_PASSWORD'])\n",
151+
"repository = g.repository('sigmavirus24', 'github3.py')"
152+
],
153+
"language": "python",
154+
"metadata": {},
155+
"outputs": [],
156+
"prompt_number": 1
157+
},
158+
{
159+
"cell_type": "markdown",
160+
"metadata": {},
161+
"source": [
162+
"With our ``repository`` object, we can now create a status for an arbitrary commit using the ``create_status`` method."
163+
]
164+
},
165+
{
166+
"cell_type": "code",
167+
"collapsed": false,
168+
"input": [
169+
"status = repository.create_status(sha='020cfe6422e3b2a0a5ff985c9e1c0aa921555bd8',\n",
170+
" state='success',\n",
171+
" description='Documentation status',\n",
172+
" context='default')\n",
173+
"print('Status {0.state} for context {0.context} with description {0.description}'.format(status))"
174+
],
175+
"language": "python",
176+
"metadata": {},
177+
"outputs": [
178+
{
179+
"output_type": "stream",
180+
"stream": "stdout",
181+
"text": [
182+
"Status success for context default with description Documentation status\n"
183+
]
184+
}
185+
],
186+
"prompt_number": 2
187+
},
188+
{
189+
"cell_type": "markdown",
190+
"metadata": {},
191+
"source": [
192+
"---\n",
193+
"\n",
194+
"We now have a \"success\" status defined on our commit and can retrieve it by listing statuses (as described above)."
195+
]
196+
}
197+
],
198+
"metadata": {}
199+
}
200+
]
201+
}

0 commit comments

Comments
 (0)
0