Skip to content

Commit 48983cf

Browse files
committed
misc
1 parent f0c1f5c commit 48983cf

File tree

1 file changed

+24
-14
lines changed

1 file changed

+24
-14
lines changed

private-sec-reporting.py

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
import asyncio
44
import aiohttp
55
from rich import print
6+
from datetime import datetime
7+
import humanize
68

7-
org = "jupyter"
9+
orgs = ["jupyter", 'ipython', 'jupyterhub', 'jupyterlab']
810
token = os.getenv("GH_TOKEN")
911

10-
async def check_private_vulnerability_reporting(session, repo_name):
12+
async def check_private_vulnerability_reporting(session, org, repo_name):
1113
headers = {
1214
'Authorization': f'token {token}',
1315
'Accept': 'application/vnd.github.v3+json'
@@ -20,7 +22,7 @@ async def check_private_vulnerability_reporting(session, repo_name):
2022
return data.get('enabled', False)
2123
return False
2224

23-
async def get_org_repos(session):
25+
async def get_org_repos(session, org):
2426
headers = {
2527
'Authorization': f'token {token}',
2628
'Accept': 'application/vnd.github.v3+json'
@@ -46,22 +48,30 @@ async def get_org_repos(session):
4648

4749
async def main():
4850
async with aiohttp.ClientSession() as session:
49-
repos = await get_org_repos(session)
5051
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)
5454

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))
5760

58-
results = await asyncio.gather(*[task for _, task in tasks])
61+
results = await asyncio.gather(*[task for _,_,_, task in tasks])
5962

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+
6373
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})")
6575

6676
if __name__ == "__main__":
6777
asyncio.run(main())

0 commit comments

Comments
 (0)