Skip to content

Commit 7e671d5

Browse files
committed
sidebar
1 parent 63358af commit 7e671d5

File tree

12 files changed

+316
-20
lines changed

12 files changed

+316
-20
lines changed

02_auth.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"cell_type": "markdown",
1414
"metadata": {},
1515
"source": [
16-
"# auth\n",
16+
"# Authentication\n",
1717
"> Helpers for creating GitHub API tokens"
1818
]
1919
},

04_event.ipynb

Lines changed: 107 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@
2828
"from fastcore.utils import *\n",
2929
"from fastcore.foundation import *\n",
3030
"from ghapi.core import *\n",
31+
"from ghapi.page import *\n",
3132
"\n",
32-
"import time"
33+
"import time\n",
34+
"from itertools import islice"
3335
]
3436
},
3537
{
@@ -50,6 +52,72 @@
5052
"# TODO only new events"
5153
]
5254
},
55+
{
56+
"cell_type": "code",
57+
"execution_count": null,
58+
"metadata": {},
59+
"outputs": [],
60+
"source": [
61+
"#export\n",
62+
"def _list_events(username=None, org=None, owner=None, repo=None):\n",
63+
" if (username or org or owner) and \\\n",
64+
" not (bool(username) ^ bool(org) ^ bool(owner)): raise Exception('Can not pass more than one of username, org, and owner')\n",
65+
" if (owner and not repo) or (repo and not owner): 'Must pass both repo and owner, if passing either'\n",
66+
" if owner: return api.activity.list_public_events_for_repo_network,{'owner':owner,'repo':repo}\n",
67+
" if org: return api.activity.list_public_org_events,{'org':org}\n",
68+
" if username: return api.activity.list_public_events_for_user,{'username':username}\n",
69+
" return api.activity.list_public_events,{}"
70+
]
71+
},
72+
{
73+
"cell_type": "code",
74+
"execution_count": null,
75+
"metadata": {},
76+
"outputs": [],
77+
"source": [
78+
"#export\n",
79+
"@patch\n",
80+
"def list_events(self:GhApi, username=None, org=None, owner=None, repo=None, per_page=30, page=1):\n",
81+
" \"Fetch public events for repo network, org, user, or all\"\n",
82+
" oper,kwargs = _list_events(username=username, org=org, owner=owner, repo=repo)\n",
83+
" return oper(per_page=per_page, page=page, **kwargs)"
84+
]
85+
},
86+
{
87+
"cell_type": "code",
88+
"execution_count": null,
89+
"metadata": {},
90+
"outputs": [],
91+
"source": [
92+
"#export\n",
93+
"@patch\n",
94+
"def list_events_parallel(self:GhApi, username=None, org=None, owner=None, repo=None, per_page=30, n_pages=8):\n",
95+
" \"Fetch as many events from `list_events` in parallel as available\"\n",
96+
" oper,kwargs = _list_events(username=username, org=org, owner=owner, repo=repo)\n",
97+
" return pages(oper, n_pages, per_page=per_page, **kwargs).concat()"
98+
]
99+
},
100+
{
101+
"cell_type": "code",
102+
"execution_count": null,
103+
"metadata": {},
104+
"outputs": [
105+
{
106+
"data": {
107+
"text/plain": [
108+
"(240, 'fastai')"
109+
]
110+
},
111+
"execution_count": null,
112+
"metadata": {},
113+
"output_type": "execute_result"
114+
}
115+
],
116+
"source": [
117+
"ev = api.list_events_parallel(org='fastai')\n",
118+
"len(ev),ev[0].org.login"
119+
]
120+
},
53121
{
54122
"cell_type": "code",
55123
"execution_count": null,
@@ -62,12 +130,47 @@
62130
" if types: types=setify(types)\n",
63131
" seen = set()\n",
64132
" while True:\n",
65-
" evts = [o for o in api.activity.list_public_events() if o.id not in seen]\n",
66-
" print('***', len(evts))\n",
133+
" evts = [o for o in api.list_events_parallel(n_pages=2) if o.id not in seen]\n",
134+
" print('\\n***', len(evts))\n",
67135
" for o in evts:\n",
68136
" seen.add(o.id)\n",
69137
" if not types or o.type in types: yield o\n",
70-
" time.sleep(0.5)"
138+
" time.sleep(0.6)"
139+
]
140+
},
141+
{
142+
"cell_type": "code",
143+
"execution_count": null,
144+
"metadata": {},
145+
"outputs": [
146+
{
147+
"name": "stdout",
148+
"output_type": "stream",
149+
"text": [
150+
"\n",
151+
"*** 60\n",
152+
"14505512015 14505511995 14505511993 14505511981 14505511975 14505511976 14505511971 14505511970 14505511968 14505511963 14505511921 14505511920 14505511889 \n",
153+
"*** 28\n",
154+
"14505512077 14505512069 14505512063 14505512061 14505512053 14505512051 14505512048 14505512040 14505512034 \n",
155+
"*** 38\n",
156+
"14505512248 14505512218 14505512215 14505512210 14505512198 14505512092 \n",
157+
"*** 41\n",
158+
"14505512340 14505512326 14505512325 14505512314 14505512313 14505512315 14505512311 14505512304 14505512307 14505512289 14505512277 14505512271 14505512261 14505512257 \n",
159+
"*** 43\n",
160+
"14505512456 14505512454 14505512450 14505512445 14505512429 14505512427 14505512408 14505512403 14505512395 14505512380 14505512366 14505512362 14505512355 14505512353 \n",
161+
"*** 32\n",
162+
"14505512515 14505512505 14505512504 14505512495 14505512486 14505512477 14505512458 \n",
163+
"*** 38\n",
164+
"14505512598 14505512600 14505512582 14505512566 14505512558 14505512549 14505512538 14505512530 14505512523 \n",
165+
"*** 60\n",
166+
"14505512763 14505512761 14505512740 14505512727 14505512723 14505512720 14505512716 14505512712 14505512709 14505512705 14505512701 14505512688 14505512679 14505512668 14505512669 14505512666 14505512655 \n",
167+
"*** 42\n",
168+
"14505512843 14505512838 14505512841 14505512839 14505512835 14505512833 14505512831 14505512809 14505512811 14505512803 14505512800 "
169+
]
170+
}
171+
],
172+
"source": [
173+
"for o in islice(fetch_events('PullRequestEvent'), 100): print(o.id, end=' ')"
71174
]
72175
},
73176
{

docs/_data/sidebars/home_sidebar.yml

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,29 @@ entries:
1010
title: Overview
1111
url: /
1212
- output: web,pdf
13-
title: Getting started with GitHub Actions
14-
url: tutorial_actions.html
15-
- output: web,pdf
16-
title: API details
13+
title: GhApi details
1714
url: core.html
1815
- output: web,pdf
19-
title: GitHub Actions
16+
title: GitHub Actions details
2017
url: actions.html
18+
- output: web,pdf
19+
title: Authentication
20+
url: auth.html
21+
- output: web,pdf
22+
title: Pagination
23+
url: page.html
24+
- output: web,pdf
25+
title: The events API
26+
url: event.html
2127
- output: web,pdf
2228
title: Command line interface
2329
url: cli.html
2430
- output: web,pdf
2531
title: Full GitHub API reference
2632
url: fullapi.html
33+
- output: web,pdf
34+
title: Getting started with GitHub Actions
35+
url: tutorial_actions.html
2736
- output: web,pdf
2837
title: Internal - OpenAPI Parser
2938
url: build_lib.html

docs/auth.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22

3-
title: auth
3+
title: Authentication
44

55

66
keywords: fastai

docs/event.html

Lines changed: 154 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,119 @@
7474

7575
<div class="cell border-box-sizing code_cell rendered">
7676

77+
</div>
78+
{% endraw %}
79+
80+
{% raw %}
81+
82+
<div class="cell border-box-sizing code_cell rendered">
83+
84+
<div class="output_wrapper">
85+
<div class="output">
86+
87+
<div class="output_area">
88+
89+
90+
<div class="output_markdown rendered_html output_subarea ">
91+
<h4 id="GhApi.list_events" class="doc_header"><code>GhApi.list_events</code><a href="https://github.com/fastai/ghapi/tree/master/ghapi/event.py#L25" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>GhApi.list_events</code>(<strong><code>username</code></strong>=<em><code>None</code></em>, <strong><code>org</code></strong>=<em><code>None</code></em>, <strong><code>owner</code></strong>=<em><code>None</code></em>, <strong><code>repo</code></strong>=<em><code>None</code></em>, <strong><code>per_page</code></strong>=<em><code>30</code></em>, <strong><code>page</code></strong>=<em><code>1</code></em>)</p>
92+
</blockquote>
93+
<p>Fetch public events for repo network, org, user, or all</p>
94+
95+
</div>
96+
97+
</div>
98+
99+
</div>
100+
</div>
101+
102+
</div>
103+
{% endraw %}
104+
105+
{% raw %}
106+
107+
<div class="cell border-box-sizing code_cell rendered">
108+
109+
</div>
110+
{% endraw %}
111+
112+
{% raw %}
113+
114+
<div class="cell border-box-sizing code_cell rendered">
115+
116+
<div class="output_wrapper">
117+
<div class="output">
118+
119+
<div class="output_area">
120+
121+
122+
<div class="output_markdown rendered_html output_subarea ">
123+
<h4 id="GhApi.list_events_parallel" class="doc_header"><code>GhApi.list_events_parallel</code><a href="https://github.com/fastai/ghapi/tree/master/ghapi/event.py#L32" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>GhApi.list_events_parallel</code>(<strong><code>username</code></strong>=<em><code>None</code></em>, <strong><code>org</code></strong>=<em><code>None</code></em>, <strong><code>owner</code></strong>=<em><code>None</code></em>, <strong><code>repo</code></strong>=<em><code>None</code></em>, <strong><code>per_page</code></strong>=<em><code>30</code></em>, <strong><code>n_pages</code></strong>=<em><code>8</code></em>)</p>
124+
</blockquote>
125+
<p>Fetch as many events from <code>list_events</code> in parallel as available</p>
126+
127+
</div>
128+
129+
</div>
130+
131+
</div>
132+
</div>
133+
134+
</div>
135+
{% endraw %}
136+
137+
{% raw %}
138+
139+
<div class="cell border-box-sizing code_cell rendered">
140+
141+
</div>
142+
{% endraw %}
143+
144+
{% raw %}
145+
146+
<div class="cell border-box-sizing code_cell rendered">
147+
<div class="input">
148+
149+
<div class="inner_cell">
150+
<div class="input_area">
151+
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">ev</span> <span class="o">=</span> <span class="n">api</span><span class="o">.</span><span class="n">list_events_parallel</span><span class="p">(</span><span class="n">org</span><span class="o">=</span><span class="s1">&#39;fastai&#39;</span><span class="p">)</span>
152+
<span class="nb">len</span><span class="p">(</span><span class="n">ev</span><span class="p">),</span><span class="n">ev</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">org</span><span class="o">.</span><span class="n">login</span>
153+
</pre></div>
154+
155+
</div>
156+
</div>
157+
</div>
158+
159+
<div class="output_wrapper">
160+
<div class="output">
161+
162+
<div class="output_area">
163+
164+
165+
166+
<div class="output_text output_subarea output_execute_result">
167+
<pre>(240, &#39;fastai&#39;)</pre>
168+
</div>
169+
170+
</div>
171+
172+
</div>
173+
</div>
174+
175+
</div>
176+
{% endraw %}
177+
178+
{% raw %}
179+
180+
<div class="cell border-box-sizing code_cell rendered">
181+
77182
<div class="output_wrapper">
78183
<div class="output">
79184

80185
<div class="output_area">
81186

82187

83188
<div class="output_markdown rendered_html output_subarea ">
84-
<h4 id="fetch_events" class="doc_header"><code>fetch_events</code><a href="https://github.com/fastai/ghapi/tree/master/ghapi/event.py#L13" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>fetch_events</code>(<strong><code>types</code></strong>=<em><code>None</code></em>)</p>
189+
<h4 id="fetch_events" class="doc_header"><code>fetch_events</code><a href="https://github.com/fastai/ghapi/tree/master/ghapi/event.py#L39" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>fetch_events</code>(<strong><code>types</code></strong>=<em><code>None</code></em>)</p>
85190
</blockquote>
86191
<p>Generate an infinite stream of events optionally filtered to <code>types</code></p>
87192

@@ -107,6 +212,54 @@ <h4 id="fetch_events" class="doc_header"><code>fetch_events</code><a href="https
107212
<div class="cell border-box-sizing code_cell rendered">
108213
<div class="input">
109214

215+
<div class="inner_cell">
216+
<div class="input_area">
217+
<div class=" highlight hl-ipython3"><pre><span></span><span class="k">for</span> <span class="n">o</span> <span class="ow">in</span> <span class="n">islice</span><span class="p">(</span><span class="n">fetch_events</span><span class="p">(</span><span class="s1">&#39;PullRequestEvent&#39;</span><span class="p">),</span> <span class="mi">100</span><span class="p">):</span> <span class="nb">print</span><span class="p">(</span><span class="n">o</span><span class="o">.</span><span class="n">id</span><span class="p">,</span> <span class="n">end</span><span class="o">=</span><span class="s1">&#39; &#39;</span><span class="p">)</span>
218+
</pre></div>
219+
220+
</div>
221+
</div>
222+
</div>
223+
224+
<div class="output_wrapper">
225+
<div class="output">
226+
227+
<div class="output_area">
228+
229+
<div class="output_subarea output_stream output_stdout output_text">
230+
<pre>
231+
*** 60
232+
14505512015 14505511995 14505511993 14505511981 14505511975 14505511976 14505511971 14505511970 14505511968 14505511963 14505511921 14505511920 14505511889
233+
*** 28
234+
14505512077 14505512069 14505512063 14505512061 14505512053 14505512051 14505512048 14505512040 14505512034
235+
*** 38
236+
14505512248 14505512218 14505512215 14505512210 14505512198 14505512092
237+
*** 41
238+
14505512340 14505512326 14505512325 14505512314 14505512313 14505512315 14505512311 14505512304 14505512307 14505512289 14505512277 14505512271 14505512261 14505512257
239+
*** 43
240+
14505512456 14505512454 14505512450 14505512445 14505512429 14505512427 14505512408 14505512403 14505512395 14505512380 14505512366 14505512362 14505512355 14505512353
241+
*** 32
242+
14505512515 14505512505 14505512504 14505512495 14505512486 14505512477 14505512458
243+
*** 38
244+
14505512598 14505512600 14505512582 14505512566 14505512558 14505512549 14505512538 14505512530 14505512523
245+
*** 60
246+
14505512763 14505512761 14505512740 14505512727 14505512723 14505512720 14505512716 14505512712 14505512709 14505512705 14505512701 14505512688 14505512679 14505512668 14505512669 14505512666 14505512655
247+
*** 42
248+
14505512843 14505512838 14505512841 14505512839 14505512835 14505512833 14505512831 14505512809 14505512811 14505512803 14505512800 </pre>
249+
</div>
250+
</div>
251+
252+
</div>
253+
</div>
254+
255+
</div>
256+
{% endraw %}
257+
258+
{% raw %}
259+
260+
<div class="cell border-box-sizing code_cell rendered">
261+
<div class="input">
262+
110263
<div class="inner_cell">
111264
<div class="input_area">
112265
<div class=" highlight hl-ipython3"><pre><span></span><span class="nb">next</span><span class="p">(</span><span class="n">fetch_events</span><span class="p">(</span><span class="s1">&#39;PullRequestEvent&#39;</span><span class="p">))</span>

docs/sidebar.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
{
22
"ghapi": {
33
"Overview": "/",
4-
"Getting started with GitHub Actions": "tutorial_actions.html",
5-
"API details": "core.html",
6-
"GitHub Actions": "actions.html",
4+
"GhApi details": "core.html",
5+
"GitHub Actions details": "actions.html",
6+
"Authentication": "auth.html",
7+
"Pagination": "page.html",
8+
"The events API": "event.html",
79
"Command line interface": "cli.html",
810
"Full GitHub API reference": "fullapi.html",
11+
"Getting started with GitHub Actions": "tutorial_actions.html",
912
"Internal - OpenAPI Parser": "build_lib.html"
1013
}
11-
}
14+
}

ghapi/_nbdev.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@
5252
"parse_link_hdr": "03_page.ipynb",
5353
"GhApi.last_page": "03_page.ipynb",
5454
"pages": "03_page.ipynb",
55+
"GhApi.list_events": "04_event.ipynb",
56+
"GhApi.list_events_parallel": "04_event.ipynb",
5557
"fetch_events": "04_event.ipynb",
5658
"ghapi": "10_cli.ipynb",
5759
"ghpath": "10_cli.ipynb",

0 commit comments

Comments
 (0)