4
4
import os
5
5
6
6
from typing import Dict , Optional
7
- from github import Github , Repository , GithubException
7
+ from github import Github , Repository , GithubException , Organization
8
+
8
9
9
10
class IndexGenerator :
10
11
def __init__ (self , agency : str , verison : str , token : Optional [str ] = None ,):
@@ -33,6 +34,18 @@ def get_code_json(self, repo: Repository) -> Optional[Dict]:
33
34
except (json .JSONDecodeError , ValueError ) as e :
34
35
print (f"JSON Error: { str (e )} " )
35
36
return None
37
+
38
+ def save_code_json (self , repo : Repository , output_path : str ) -> Optional [str ]:
39
+
40
+ res = self .get_code_json (repo )
41
+
42
+ if res :
43
+ with open (output_path , 'w' ) as f :
44
+ json .dump (res , f , indent = 2 )
45
+ else :
46
+ print (f"Error getting codejson file!" )
47
+
48
+ return res
36
49
37
50
def update_index (self , index : Dict , code_json : Dict , org_name : str , repo_name : str ) -> None :
38
51
baseline = {
@@ -44,13 +57,35 @@ def update_index(self, index: Dict, code_json: Dict, org_name: str, repo_name: s
44
57
45
58
index ['releases' ].append (baseline )
46
59
47
- def process_organization (self , org_name : str ) -> None :
60
+ def get_org_repos (self , org_name : str ) -> list [ Organization ] :
48
61
try :
49
62
org = self .github .get_organization (org_name )
50
63
print (f"\n Processing organization: { org_name } " )
51
64
52
65
total_repos = org .public_repos
53
66
print (f"Found { total_repos } public repositories" )
67
+
68
+ return total_repos
69
+ except GithubException as e :
70
+ raise e
71
+
72
+ def save_organization_files (self , org_name : str , codeJSONPath ) -> None :
73
+ try :
74
+ org = self .github .get_organization (org_name )
75
+ total_repos = self .get_org_repos (org_name )
76
+
77
+ for id , repo in enumerate (org .get_repos (type = 'public' ), 1 ):
78
+ print (f"\n Saving codeJSON for { repo .name } [{ id } /{ total_repos } ]" )
79
+
80
+ repoPath = os .path .join (codeJSONPath , (repo .name + '.json' ))
81
+ code_json = self .save_code_json (repo ,repoPath )
82
+ except GithubException as e :
83
+ print (f"Error processing organization { org_name } : { str (e )} " )
84
+
85
+ def process_organization (self , org_name : str ) -> None :
86
+ try :
87
+ org = self .github .get_organization (org_name )
88
+ total_repos = self .get_org_repos (org_name )
54
89
55
90
for id , repo in enumerate (org .get_repos (type = 'public' ), 1 ):
56
91
print (f"\n Checking { repo .name } [{ id } /{ total_repos } ]" )
0 commit comments