Skip to content
This repository was archived by the owner on Oct 2, 2023. It is now read-only.

Commit ed7bf96

Browse files
atticus-sullivanDefelo
authored andcommitted
Remove to be deleted and (hopefully) fix formatting/linter hints
1 parent 30ace44 commit ed7bf96

File tree

1 file changed

+14
-53
lines changed
  • integrations/adventofcode

1 file changed

+14
-53
lines changed

integrations/adventofcode/cog.py

+14-53
Original file line numberDiff line numberDiff line change
@@ -152,55 +152,33 @@ def make_member_stats(member: dict) -> tuple[int, list[str]]:
152152
def escape_aoc_name(name: Optional[str]) -> str:
153153
return "".join(c for c in name if c.isalnum() or c in " _-") if name else ""
154154

155+
155156
# Alternative get facility
156157
def get_git_repo(url: str) -> Optional[str]:
157158
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+
]
162169

163170
for pattern, api in servers:
164171
if not (match := re.match(pattern, url)):
165172
continue
166173
_, user, repo, path = match.groups()
167174
if not (response := requests.get(api.format(user, repo))).ok:
168-
continue # TODO or exit here
175+
continue # TODO or exit here
169176
url = response.json()["html_url"] + (path or "")
170177
if not requests.head(url).ok:
171-
continue # TODO or exit here
178+
continue # TODO or exit here
172179
return url
173180
return None
174181

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}")
204182

205183
# Alternative parsing facility
206184
def parse_git_url(url: str) -> tuple[str, str]:
@@ -214,24 +192,7 @@ def parse_git_url(url: str) -> tuple[str, str]:
214192
if match is not None:
215193
user, repo = match.groups()
216194
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
235196

236197

237198
class AdventOfCodeCog(Cog, name="Advent of Code Integration"):

0 commit comments

Comments
 (0)