@@ -29,7 +29,7 @@ def status_message(message: str) -> None:
29
29
def load_schema () -> Dict [str , Any ]:
30
30
"""Load the JSON schema for validation"""
31
31
try :
32
- with open (SCHEMA_PATH , 'r' ) as f :
32
+ with open (SCHEMA_PATH , "r" ) as f :
33
33
return json .load (f )
34
34
except json .JSONDecodeError as e :
35
35
error_exit (f"Invalid JSON in schema file: { e } " )
@@ -42,7 +42,7 @@ def load_schema() -> Dict[str, Any]:
42
42
def load_manifest (manifest_path : Path ) -> Dict [str , Any ]:
43
43
"""Load and parse a manifest file with schema validation"""
44
44
try :
45
- with open (manifest_path , 'r' ) as f :
45
+ with open (manifest_path , "r" ) as f :
46
46
manifest = json .load (f )
47
47
48
48
# Get the schema
@@ -70,7 +70,7 @@ def find_server_manifests(servers_dir: Path) -> List[Path]:
70
70
error_exit (f"Servers directory not found: { servers_dir } " )
71
71
72
72
server_files = []
73
- for file_path in servers_dir .glob (' *.json' ):
73
+ for file_path in servers_dir .glob (" *.json" ):
74
74
if file_path .is_file ():
75
75
server_files .append (file_path )
76
76
@@ -86,39 +86,39 @@ def extract_github_repos(server_manifests: List[Path]) -> Dict[str, str]:
86
86
manifest = load_manifest (manifest_path )
87
87
88
88
# Check if manifest has GitHub repository URL
89
- if ' repository' in manifest :
90
- repo_url = manifest [' repository' ]
89
+ if " repository" in manifest :
90
+ repo_url = manifest [" repository" ]
91
91
92
92
# Handle both string and dictionary repository formats
93
- if isinstance (repo_url , str ) and repo_url .startswith (' https://github.com/' ):
93
+ if isinstance (repo_url , str ) and repo_url .startswith (" https://github.com/" ):
94
94
github_repos [server_name ] = repo_url
95
- elif (isinstance (repo_url , dict ) and ' url' in repo_url and
96
- isinstance (repo_url [' url' ], str ) and
97
- repo_url [' url' ].startswith (' https://github.com/' )):
98
- github_repos [server_name ] = repo_url [' url' ]
95
+ elif (isinstance (repo_url , dict ) and " url" in repo_url and
96
+ isinstance (repo_url [" url" ], str ) and
97
+ repo_url [" url" ].startswith (" https://github.com/" )):
98
+ github_repos [server_name ] = repo_url [" url" ]
99
99
100
100
return github_repos
101
101
102
102
103
103
def fetch_github_stars_batch (repo_urls : List [str ]) -> Dict [str , int ]:
104
104
"""Fetch GitHub stars for multiple repositories using GraphQL API"""
105
105
# Get GitHub token from environment variable
106
- github_token = os .environ .get (' GITHUB_TOKEN' )
106
+ github_token = os .environ .get (" GITHUB_TOKEN" )
107
107
108
108
# Prepare headers
109
109
headers = {
110
- ' Content-Type' : ' application/json' ,
110
+ " Content-Type" : " application/json" ,
111
111
}
112
112
113
113
# Add authorization if token is provided
114
114
if github_token :
115
- headers [' Authorization' ] = f"Bearer { github_token } "
115
+ headers [" Authorization" ] = f"Bearer { github_token } "
116
116
117
117
# Extract owner and repo from URLs
118
118
repos = []
119
119
for url in repo_urls :
120
- if url .startswith (' https://github.com/' ):
121
- parts = url .replace (' https://github.com/' , '' ).split ('/' )
120
+ if url .startswith (" https://github.com/" ):
121
+ parts = url .replace (" https://github.com/" , "" ).split ("/" )
122
122
if len (parts ) >= 2 :
123
123
owner , repo = parts [0 ], parts [1 ]
124
124
repos .append ((owner , repo ))
@@ -147,9 +147,9 @@ def fetch_github_stars_batch(repo_urls: List[str]) -> Dict[str, int]:
147
147
variables [f"repo{ i } " ] = repo
148
148
149
149
# Join the query parts with proper line length
150
- variable_defs = ', ' .join (f' $owner{ i } : String!, $repo{ i } : String!'
150
+ variable_defs = ", " .join (f" $owner{ i } : String!, $repo{ i } : String!"
151
151
for i in range (len (batch )))
152
- query_body = ' ' .join (query_parts )
152
+ query_body = " " .join (query_parts )
153
153
154
154
query = f"""query ({ variable_defs } ) {{
155
155
{ query_body }
@@ -160,7 +160,7 @@ def fetch_github_stars_batch(repo_urls: List[str]) -> Dict[str, int]:
160
160
response = requests .post (
161
161
GITHUB_API_URL ,
162
162
headers = headers ,
163
- json = {' query' : query , ' variables' : variables }
163
+ json = {" query" : query , " variables" : variables }
164
164
)
165
165
166
166
# Check for errors
@@ -179,20 +179,20 @@ def fetch_github_stars_batch(repo_urls: List[str]) -> Dict[str, int]:
179
179
data = response .json ()
180
180
181
181
# Check for GraphQL errors
182
- if ' errors' in data :
182
+ if " errors" in data :
183
183
print (f"⚠️ GraphQL errors: { data ['errors' ]} " )
184
184
continue
185
185
186
186
# Extract star counts
187
187
for i , (owner , repo ) in enumerate (batch ):
188
188
repo_key = f"repo{ i } "
189
- if repo_key in data [' data' ] and data [' data' ][repo_key ]:
190
- url = data [' data' ][repo_key ][' url' ]
191
- star_count = data [' data' ][repo_key ][' stargazerCount' ]
189
+ if repo_key in data [" data" ] and data [" data" ][repo_key ]:
190
+ url = data [" data" ][repo_key ][" url" ]
191
+ star_count = data [" data" ][repo_key ][" stargazerCount" ]
192
192
stars [url ] = star_count
193
- if url .startswith (' https://github.com/' ):
193
+ if url .startswith (" https://github.com/" ):
194
194
returned_parts = url .replace (
195
- ' https://github.com/' , '' ).split ('/' )
195
+ " https://github.com/" , "" ).split ("/" )
196
196
if len (returned_parts ) >= 2 :
197
197
returned_owner , returned_repo = returned_parts [0 ], returned_parts [1 ]
198
198
if owner != returned_owner :
@@ -243,13 +243,13 @@ def generate_servers_json(server_manifests: List[Path], output_path: Path) -> Di
243
243
244
244
# Use the entire manifest as is, preserving all fields
245
245
# Ensure the name field at minimum is present
246
- if ' name' not in manifest :
247
- manifest [' name' ] = server_name
246
+ if " name" not in manifest :
247
+ manifest [" name" ] = server_name
248
248
249
249
servers_data [server_name ] = manifest
250
250
251
251
# Write servers.json
252
- with open (output_path , 'w' ) as f :
252
+ with open (output_path , "w" ) as f :
253
253
json .dump (servers_data , f , indent = 2 )
254
254
255
255
return servers_data
@@ -260,7 +260,7 @@ def generate_stars_json(stars: Dict[str, int], output_path: Path) -> None:
260
260
status_message ("Generating stars.json..." )
261
261
262
262
# Write stars.json
263
- with open (output_path , 'w' ) as f :
263
+ with open (output_path , "w" ) as f :
264
264
json .dump (stars , f , indent = 2 )
265
265
266
266
0 commit comments