Skip to content

Commit e2b386d

Browse files
committed
tail evts
1 parent 33fd60d commit e2b386d

File tree

3 files changed

+24
-7
lines changed

3 files changed

+24
-7
lines changed

‎ghtop/ghtop.py‎

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
__all__ = ['term', 'logfile', 'github_auth_device', 'limit_cb', 'api', 'Events', 'print_event', 'tail_events', 'watch_users', 'quad_logs', 'simple', 'main']
1+
# AUTOGENERATED! DO NOT EDIT! File to edit: nbs/00_ghtop.ipynb (unless otherwise specified).
22

3+
__all__ = ['term', 'logfile', 'github_auth_device', 'limit_cb', 'api', 'Events', 'print_event', 'tail_events',
4+
'watch_users', 'quad_logs', 'simple', 'main']
5+
6+
# Cell
37
import time, sys, signal, shutil, os, json, enlighten, emoji, blessed
48
from dashing import *
59
from collections import defaultdict
@@ -11,9 +15,11 @@
1115
from fastcore.script import *
1216
from ghapi.all import *
1317

18+
# Cell
1419
term = Terminal()
1520
logfile = Path("log.txt")
1621

22+
# Cell
1723
def github_auth_device(wb='', n_polls=9999):
1824
"Authenticate with GitHub, polling up to `n_polls` times to wait for completion"
1925
auth = GhDeviceAuth()
@@ -28,15 +34,18 @@ def github_auth_device(wb='', n_polls=9999):
2834
print("Authenticated with GitHub")
2935
return token
3036

37+
# Cell
3138
def _exit(msg):
3239
print(msg, file=sys.stderr)
3340
sys.exit()
3441

42+
# Cell
3543
def limit_cb(rem,quota):
3644
"Callback to warn user when close to using up hourly quota"
3745
w='WARNING '*7
3846
if rem < 1000: print(f"{w}\nRemaining calls: {rem} out of {quota}\n{w}", file=sys.stderr)
3947

48+
# Cell
4049
def _get_api():
4150
path = Path.home()/".ghtop_token"
4251
if path.is_file():
@@ -48,6 +57,7 @@ def _get_api():
4857

4958
api = _get_api()
5059

60+
# Cell
5161
Events = dict(
5262
IssuesEvent_closed=('⭐', 'closed', noop),
5363
IssuesEvent_opened=('📫', 'opened', noop),
@@ -56,6 +66,7 @@ def _get_api():
5666
PullRequestEvent_closed=('✔', 'closed a pull request', term.green),
5767
)
5868

69+
# Cell
5970
def _to_log(e):
6071
login,repo,pay = e.actor.login,e.repo.name,e.payload
6172
typ = e.type + (f'_{pay.action}' if e.type in ('PullRequestEvent','IssuesEvent') else '')
@@ -66,18 +77,21 @@ def _to_log(e):
6677
return color(f'{emoji} {login} {msg}{xtra} on repo {repo[:20]} ("{d.title[:50]}...")')
6778
elif e.type == "ReleaseEvent": return f'🚀 {login} released {e.payload.release.tag_name} of {repo}'
6879

80+
# Cell
6981
def print_event(e, commits_counter):
7082
res = _to_log(e)
7183
if res: print(res)
7284
elif e.type == "PushEvent": [commits_counter.update() for c in e.payload.commits]
7385
elif e.type == "SecurityAdvisoryEvent": print(term.blink("SECURITY ADVISORY"))
7486

75-
def tail_events():
87+
# Cell
88+
def tail_events(evt):
7689
"Print events from `fetch_events` along with a counter of push events"
7790
manager = enlighten.get_manager()
7891
commits = manager.counter(desc='Commits', unit='commits', color='green')
79-
for ev in fetch_events(): print_event(ev, commits)
92+
for ev in evt: print_event(ev, commits)
8093

94+
# Cell
8195
def _pr_row(*its): print(f"{its[0]: <30} {its[1]: <6} {its[2]: <5} {its[3]: <6} {its[4]: <7}")
8296
def watch_users(evts):
8397
"Print a table of the users with the most events"
@@ -93,6 +107,7 @@ def watch_users(evts):
93107
for u in sorted_users[:20]:
94108
_pr_row(*u, *itemgetter('PullRequestEvent','IssuesEvent','PushEvent')(users_events[u[0]]))
95109

110+
# Cell
96111
def _push_to_log(e): return f"{e.actor.login} pushed {len(e.payload.commits)} commits to repo {e.repo.name}"
97112
def _logwin(title,color): return Log(title=title,border_color=2,color=color)
98113

@@ -112,9 +127,11 @@ def quad_logs(evts):
112127
if x.type in d: d[x.type].append(f(x)[:95])
113128
ui.display()
114129

130+
# Cell
115131
def simple(evts):
116132
for ev in evts: print(f"{ev.actor.login} {ev.type} {ev.repo.name}")
117133

134+
# Cell
118135
def _signal_handler(sig, frame):
119136
if sig != signal.SIGINT: return
120137
print(term.exit_fullscreen(),term.clear(),term.normal)
@@ -136,4 +153,4 @@ def main(mode: Param("Operation mode to run", _OpModes),
136153
if filtval and not filt: _exit("Must pass `filter_type` if passing `filter_value`")
137154
kwargs = {filt:filtval} if filt else {}
138155
evts = api.fetch_events(types=types, incl_bot=include_bots, **kwargs)
139-
_funcs[mode](evts)
156+
_funcs[mode](evts)

‎nbs/00_ghtop.ipynb‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,11 +246,11 @@
246246
"outputs": [],
247247
"source": [
248248
"#export\n",
249-
"def tail_events():\n",
249+
"def tail_events(evt):\n",
250250
" \"Print events from `fetch_events` along with a counter of push events\"\n",
251251
" manager = enlighten.get_manager()\n",
252252
" commits = manager.counter(desc='Commits', unit='commits', color='green')\n",
253-
" for ev in fetch_events(): print_event(ev, commits)"
253+
" for ev in evt: print_event(ev, commits)"
254254
]
255255
},
256256
{

‎settings.ini‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ author_email = j@fast.ai
66
copyright = Nat Friedman
77
description = See what is happening on GitHub in real time
88
keywords = python
9-
version = 0.0.4
9+
version = 0.0.5
1010
min_python = 3.6
1111
audience = Developers
1212
language = English

0 commit comments

Comments
 (0)