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
37import time , sys , signal , shutil , os , json , enlighten , emoji , blessed
48from dashing import *
59from collections import defaultdict
1115from fastcore .script import *
1216from ghapi .all import *
1317
18+ # Cell
1419term = Terminal ()
1520logfile = Path ("log.txt" )
1621
22+ # Cell
1723def 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
3138def _exit (msg ):
3239 print (msg , file = sys .stderr )
3340 sys .exit ()
3441
42+ # Cell
3543def 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 } \n Remaining calls: { rem } out of { quota } \n { w } " , file = sys .stderr )
3947
48+ # Cell
4049def _get_api ():
4150 path = Path .home ()/ ".ghtop_token"
4251 if path .is_file ():
@@ -48,6 +57,7 @@ def _get_api():
4857
4958api = _get_api ()
5059
60+ # Cell
5161Events = 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
5970def _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
6981def 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
8195def _pr_row (* its ): print (f"{ its [0 ]: <30} { its [1 ]: <6} { its [2 ]: <5} { its [3 ]: <6} { its [4 ]: <7} " )
8296def 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
96111def _push_to_log (e ): return f"{ e .actor .login } pushed { len (e .payload .commits )} commits to repo { e .repo .name } "
97112def _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
115131def simple (evts ):
116132 for ev in evts : print (f"{ ev .actor .login } { ev .type } { ev .repo .name } " )
117133
134+ # Cell
118135def _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 )
0 commit comments