1
1
import os
2
- import requests
3
- import os
4
2
import json
5
- org = "jupyter"
3
+ import asyncio
4
+ import aiohttp
5
+ from rich import print
6
6
7
+ org = "jupyter"
7
8
token = os .getenv ("GH_TOKEN" )
8
9
9
- def check_private_vulnerability_reporting (repo_name ):
10
+ async def check_private_vulnerability_reporting (session , repo_name ):
10
11
headers = {
11
12
'Authorization' : f'token { token } ' ,
12
13
'Accept' : 'application/vnd.github.v3+json'
13
14
}
14
15
url = f'https://api.github.com/repos/{ org } /{ repo_name } /private-vulnerability-reporting'
15
16
16
- response = requests .get (url , headers = headers )
17
-
18
- if response . status_code == 200 :
19
- return response . json () .get ('enabled' , False )
17
+ async with session .get (url , headers = headers ) as response :
18
+ if response . status == 200 :
19
+ data = await response . json ()
20
+ return data .get ('enabled' , False )
20
21
return False
21
22
22
- def get_org_repos ():
23
+ async def get_org_repos (session ):
23
24
headers = {
24
25
'Authorization' : f'token { token } ' ,
25
26
'Accept' : 'application/vnd.github.v3+json'
@@ -29,31 +30,38 @@ def get_org_repos():
29
30
page = 1
30
31
while True :
31
32
url = f'https://api.github.com/orgs/{ org } /repos?page={ page } &per_page=100'
32
- response = requests .get (url , headers = headers )
33
-
34
- if response .status_code != 200 :
35
- print (f"Error fetching repos: { response .status_code } " )
36
- break
37
-
38
- page_repos = response .json ()
39
- if not page_repos :
40
- break
41
-
42
- repos .extend (page_repos )
43
- page += 1
33
+ async with session .get (url , headers = headers ) as response :
34
+ if response .status != 200 :
35
+ print (f"Error fetching repos: { response .status } " )
36
+ break
37
+
38
+ page_repos = await response .json ()
39
+ if not page_repos :
40
+ break
41
+
42
+ repos .extend (page_repos )
43
+ page += 1
44
44
45
45
return repos
46
46
47
- # Get all repos and check their vulnerability reporting status
48
- repos = get_org_repos ()
49
- results = {}
50
- from rich import print
51
- for repo in repos :
52
- repo_name = repo ['name' ]
53
- repo_is_private = repo ['private' ]
54
- if repo_is_private :
55
- print (f"{ repo_name :>25} : [yellow]Private[/yellow]" )
56
- continue
57
- has_vuln_reporting = check_private_vulnerability_reporting (repo_name )
58
- results [repo_name ] = has_vuln_reporting
59
- print (f"{ repo_name :>25} : { '[green]Enabled[/green]' if has_vuln_reporting else '[red]Disabled[/red]' } " )
47
+ async def main ():
48
+ async with aiohttp .ClientSession () as session :
49
+ repos = await get_org_repos (session )
50
+ tasks = []
51
+
52
+ for repo in repos :
53
+ repo_name = repo ['name' ]
54
+ if repo ['private' ]:
55
+ print (f"{ repo_name :>25} : [yellow]Private[/yellow]" )
56
+ continue
57
+
58
+ task = check_private_vulnerability_reporting (session , repo_name )
59
+ tasks .append ((repo_name , task ))
60
+
61
+ results = await asyncio .gather (* [task for _ , task in tasks ])
62
+
63
+ for (repo_name , _ ), has_vuln_reporting in zip (tasks , results ):
64
+ print (f"{ repo_name :>25} : { '[green]Enabled[/green]' if has_vuln_reporting else '[red]Disabled[/red]' } " )
65
+
66
+ if __name__ == "__main__" :
67
+ asyncio .run (main ())
0 commit comments