Skip to content

Commit cb89e80

Browse files
committed
add parse method for org files
Signed-off-by: Isaac Milarsky <imilarsky@gmail.com>
1 parent 06b2acc commit cb89e80

1 file changed

Lines changed: 23 additions & 3 deletions

File tree

codejson_index_generator/parsers.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import os
55

66
from typing import Dict, Optional
7-
from github import Github, Repository, GithubException
7+
from github import Github, Repository, GithubException, Organization
88

99

1010
class IndexGenerator:
@@ -38,7 +38,7 @@ def get_code_json(self, repo: Repository) -> Optional[Dict]:
3838
def save_code_json(self, repo: Repository, output_path: str) -> Optional[str]:
3939

4040
res = self.get_code_json(repo)
41-
41+
4242
if res:
4343
with open(output_path, 'w') as f:
4444
json.dump(res, f, indent=2)
@@ -57,13 +57,33 @@ def update_index(self, index: Dict, code_json: Dict, org_name: str, repo_name: s
5757

5858
index['releases'].append(baseline)
5959

60-
def process_organization(self, org_name: str) -> None:
60+
def get_org_repos(self, org_name: str) -> List[Organization]:
6161
try:
6262
org = self.github.get_organization(org_name)
6363
print(f"\nProcessing organization: {org_name}")
6464

6565
total_repos = org.public_repos
6666
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+
total_repos = self.get_org_repos(org_name)
75+
76+
for id, repo in enumerate(org.get_repos(type='public'), 1):
77+
print(f"\n Saving codeJSON for {repo.name} [{id}/{total_repos}]")
78+
79+
repoPath = os.path.join(codeJSONPath, (repo.name + '.json'))
80+
code_json = self.save_code_json(repoPath)
81+
except GithubException as e:
82+
print(f"Error processing organization {org_name}: {str(e)}")
83+
84+
def process_organization(self, org_name: str) -> None:
85+
try:
86+
total_repos = self.get_org_repos(org_name)
6787

6888
for id, repo in enumerate(org.get_repos(type='public'), 1):
6989
print(f"\nChecking {repo.name} [{id}/{total_repos}]")

0 commit comments

Comments
 (0)