Skip to content

Commit cccb753

Browse files
committed
async
1 parent 7bac0ae commit cccb753

File tree

1 file changed

+42
-34
lines changed

1 file changed

+42
-34
lines changed

private-sec-reporting.py

Lines changed: 42 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
11
import os
2-
import requests
3-
import os
42
import json
5-
org = "jupyter"
3+
import asyncio
4+
import aiohttp
5+
from rich import print
66

7+
org = "jupyter"
78
token = os.getenv("GH_TOKEN")
89

9-
def check_private_vulnerability_reporting(repo_name):
10+
async def check_private_vulnerability_reporting(session, repo_name):
1011
headers = {
1112
'Authorization': f'token {token}',
1213
'Accept': 'application/vnd.github.v3+json'
1314
}
1415
url = f'https://api.github.com/repos/{org}/{repo_name}/private-vulnerability-reporting'
1516

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)
2021
return False
2122

22-
def get_org_repos():
23+
async def get_org_repos(session):
2324
headers = {
2425
'Authorization': f'token {token}',
2526
'Accept': 'application/vnd.github.v3+json'
@@ -29,31 +30,38 @@ def get_org_repos():
2930
page = 1
3031
while True:
3132
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
4444

4545
return repos
4646

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

Comments
 (0)