Skip to content

Commit 06b2acc

Browse files
committed
add save code json method
Signed-off-by: Isaac Milarsky <imilarsky@gmail.com>
1 parent 8bd22ce commit 06b2acc

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

codejson_index_generator/parsers.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from typing import Dict, Optional
77
from github import Github, Repository, GithubException
88

9+
910
class IndexGenerator:
1011
def __init__(self, agency: str, verison: str, token: Optional[str] = None,):
1112
self.github = Github(token) if token else Github()
@@ -33,6 +34,18 @@ def get_code_json(self, repo: Repository) -> Optional[Dict]:
3334
except (json.JSONDecodeError, ValueError) as e:
3435
print(f"JSON Error: {str(e)}")
3536
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
3649

3750
def update_index(self, index: Dict, code_json: Dict, org_name: str, repo_name: str) -> None:
3851
baseline = {

0 commit comments

Comments
 (0)