3
3
import asyncio
4
4
import aiohttp
5
5
from rich import print
6
+ from datetime import datetime
7
+ import humanize
6
8
7
- org = "jupyter"
9
+ orgs = [ "jupyter" , 'ipython' , 'jupyterhub' , 'jupyterlab' ]
8
10
token = os .getenv ("GH_TOKEN" )
9
11
10
- async def check_private_vulnerability_reporting (session , repo_name ):
12
+ async def check_private_vulnerability_reporting (session , org , repo_name ):
11
13
headers = {
12
14
'Authorization' : f'token { token } ' ,
13
15
'Accept' : 'application/vnd.github.v3+json'
@@ -20,7 +22,7 @@ async def check_private_vulnerability_reporting(session, repo_name):
20
22
return data .get ('enabled' , False )
21
23
return False
22
24
23
- async def get_org_repos (session ):
25
+ async def get_org_repos (session , org ):
24
26
headers = {
25
27
'Authorization' : f'token { token } ' ,
26
28
'Accept' : 'application/vnd.github.v3+json'
@@ -46,22 +48,30 @@ async def get_org_repos(session):
46
48
47
49
async def main ():
48
50
async with aiohttp .ClientSession () as session :
49
- repos = await get_org_repos (session )
50
51
tasks = []
51
-
52
- for repo in repos :
53
- repo_name = repo ['name' ]
52
+ for org in orgs :
53
+ repos = await get_org_repos (session , org )
54
54
55
- task = check_private_vulnerability_reporting (session , repo_name )
56
- tasks .append ((repo_name , task ))
55
+ for repo in sorted (repos , key = lambda x : x ['name' ]):
56
+ repo_name = repo ['name' ]
57
+
58
+ task = check_private_vulnerability_reporting (session , org , repo_name )
59
+ tasks .append ((repo , org , repo_name , task ))
57
60
58
- results = await asyncio .gather (* [task for _ , task in tasks ])
61
+ results = await asyncio .gather (* [task for _ ,_ , _ , task in tasks ])
59
62
60
- for repo , (repo_name , _ ), has_vuln_reporting in zip (repos ,tasks , results ):
61
- if repo ['private' ]:
62
- print (f"{ repo_name :>25} : [yellow]Private[/yellow] { '[green]Enabled[/green]' if has_vuln_reporting else '[red]Disabled[/red]' } " )
63
+ for (repo , org , repo_name , _ ), has_vuln_reporting in zip (tasks , results ):
64
+ last_activity = repo ['pushed_at' ]
65
+ last_activity_date = datetime .fromisoformat (last_activity ).strftime ("%Y-%m-%d" )
66
+ last_activity_ago_human = humanize .naturaltime (datetime .now (datetime .fromisoformat (last_activity ).tzinfo ) - datetime .fromisoformat (last_activity ))
67
+
68
+ if repo ['archived' ]:
69
+ print (f"{ org + '/' + repo_name :<55} : [yellow]Archived { 'Enabled' if has_vuln_reporting else 'Disabled[/yellow]' } " )
70
+ elif repo ['private' ]:
71
+ print (f"{ org + '/' + repo_name :<55} : [yellow]Private { 'Enabled' if has_vuln_reporting else 'Disabled[/yellow]' } –– last activity: { last_activity_date } ({ last_activity_ago_human } )" )
72
+
63
73
else :
64
- print (f"{ repo_name :>25 } : { '[green]Enabled[/green]' if has_vuln_reporting else '[red]Disabled[/red]' } " )
74
+ print (f"{ org + '/' + repo_name :<55 } : { '[green]Enabled[/green]' if has_vuln_reporting else '[red]Disabled[/red]' } –– last activity: { last_activity_date } ( { last_activity_ago_human } ) " )
65
75
66
76
if __name__ == "__main__" :
67
77
asyncio .run (main ())
0 commit comments