@@ -152,55 +152,33 @@ def make_member_stats(member: dict) -> tuple[int, list[str]]:
152
152
def escape_aoc_name (name : Optional [str ]) -> str :
153
153
return "" .join (c for c in name if c .isalnum () or c in " _-" ) if name else ""
154
154
155
+
155
156
# Alternative get facility
156
157
def get_git_repo (url : str ) -> Optional [str ]:
157
158
servers = [
158
- (r"^(https?://)?gitlab.com/([a-zA-Z0-9.\-_]+)/([a-zA-Z0-9.\-_]+)(/.*)?$" , "https://gitlab.com/api/v4/projects/{}%2F{}" ),
159
- (r"^(https?://)?gitea.com/([a-zA-Z0-9.\-_]+)/([a-zA-Z0-9.\-_]+)(/.*)?$" , "https://gitea.com/api/v1/repos/{user}/{repo}" ),
160
- (r"^(https?://)?github.com/([a-zA-Z0-9.\-_]+)/([a-zA-Z0-9.\-_]+)(/.*)?$" , "https://api.github.com/repos/{user}/{repo}" )
161
- ]
159
+ (
160
+ r"^(https?://)?gitlab.com/([a-zA-Z0-9.\-_]+)/([a-zA-Z0-9.\-_]+)(/.*)?$" , "https://gitlab.com/api/v4/projects/{}%2F{}"
161
+ ),
162
+ (
163
+ r"^(https?://)?gitea.com/([a-zA-Z0-9.\-_]+)/([a-zA-Z0-9.\-_]+)(/.*)?$" , "https://gitea.com/api/v1/repos/{user}/{repo}"
164
+ ),
165
+ (
166
+ r"^(https?://)?github.com/([a-zA-Z0-9.\-_]+)/([a-zA-Z0-9.\-_]+)(/.*)?$" , "https://api.github.com/repos/{user}/{repo}"
167
+ ),
168
+ ]
162
169
163
170
for pattern , api in servers :
164
171
if not (match := re .match (pattern , url )):
165
172
continue
166
173
_ , user , repo , path = match .groups ()
167
174
if not (response := requests .get (api .format (user , repo ))).ok :
168
- continue # TODO or exit here
175
+ continue # TODO or exit here
169
176
url = response .json ()["html_url" ] + (path or "" )
170
177
if not requests .head (url ).ok :
171
- continue # TODO or exit here
178
+ continue # TODO or exit here
172
179
return url
173
180
return None
174
181
175
- # TODO remove
176
- def get_repo (url : str , pattern : str , api : str ) -> Optional [str ]:
177
- if not (match := re .match (pattern , url )):
178
- return None
179
- _ , user , repo , path = match .groups ()
180
- if not (response := requests .get (api .format (user , repo ))).ok :
181
- return None
182
- url = response .json ()["html_url" ] + (path or "" )
183
- if not requests .head (url ).ok :
184
- return None
185
- return url
186
-
187
- # TODO remove
188
- def get_gitlab_repo (url : str ) -> Optional [str ]:
189
- return get_git_repo (url ,
190
- r"^(https?://)?gitlab.com/([a-zA-Z0-9.\-_]+)/([a-zA-Z0-9.\-_]+)(/.*)?$" ,
191
- "https://gitlab.com/api/v4/projects/{}%2F{}" )
192
-
193
- # TODO remove
194
- def get_gitea_repo (url : str ) -> Optional [str ]:
195
- return get_git_repo (url ,
196
- r"^(https?://)?gitea.com/([a-zA-Z0-9.\-_]+)/([a-zA-Z0-9.\-_]+)(/.*)?$" ,
197
- "https://gitea.com/api/v1/repos/{user}/{repo}" )
198
-
199
- # TODO remove
200
- def get_github_repo (url : str ) -> Optional [str ]:
201
- return get_git_repo (url ,
202
- r"^(https?://)?github.com/([a-zA-Z0-9.\-_]+)/([a-zA-Z0-9.\-_]+)(/.*)?$" ,
203
- "https://api.github.com/repos/{user}/{repo}" )
204
182
205
183
# Alternative parsing facility
206
184
def parse_git_url (url : str ) -> tuple [str , str ]:
@@ -214,24 +192,7 @@ def parse_git_url(url: str) -> tuple[str, str]:
214
192
if match is not None :
215
193
user , repo = match .groups ()
216
194
return user , repo
217
- return "" , "" # TODO how handle error
218
-
219
- # TODO remove
220
- def parse_url (url : str , pattern : str ) -> tuple [str , str ]:
221
- user , repo = re .match (pattern , url ).groups ()
222
- return user , repo
223
-
224
- # TODO remove
225
- def parse_gitlab_url (url : str ) -> tuple [str , str ]:
226
- return parse_git_url (url , r"^https://gitlab.com/([^/]+)/([^/]+).*" )
227
-
228
- # TODO remove
229
- def parse_gitea_url (url : str ) -> tuple [str , str ]:
230
- return parse_git_url (url , r"^https://gitea.com/([^/]+)/([^/]+).*" )
231
-
232
- # TODO remove
233
- def parse_github_url (url : str ) -> tuple [str , str ]:
234
- return parse_git_url (url , r"^https://github.com/([^/]+)/([^/]+).*" )
195
+ return "" , "" # TODO how handle error
235
196
236
197
237
198
class AdventOfCodeCog (Cog , name = "Advent of Code Integration" ):
0 commit comments