1
0
Fork 0

Fix some gitlab instances that return 404 on url-encoded project paths, by calling search

This commit is contained in:
Félix Piédallu 2024-02-24 22:15:28 +01:00
parent 1b39a34a4c
commit 7fe5e1a8e2

View file

@ -25,7 +25,7 @@ class GithubAPI:
def internal_api(self, uri: str) -> Any:
url = f"https://api.github.com/{uri}"
r = requests.get(url, auth=self.auth)
assert r.status_code == 200, r
r.raise_for_status()
return r.json()
def tags(self) -> list[dict[str, str]]:
@ -66,7 +66,16 @@ class GitlabAPI:
return match.group(1)
def find_project_id(self, project: str) -> int:
project = self.internal_api(f"projects/{project.replace('/', '%2F')}")
try:
project = self.internal_api(f"projects/{project.replace('/', '%2F')}")
except requests.exceptions.HTTPError as err:
if err.response.status_code != 404:
raise
# Second chance for some buggy gitlab instances...
name = self.project_path.split("/")[-1]
projects = self.internal_api(f"projects?search={name}")
project = next(filter(lambda x: x.get("path_with_namespace") == self.project_path, projects))
assert isinstance(project, dict)
project_id = project.get("id", None)
return project_id
@ -74,7 +83,7 @@ class GitlabAPI:
def internal_api(self, uri: str) -> Any:
url = f"{self.forge_root}/api/v4/{uri}"
r = requests.get(url)
assert r.status_code == 200, r
r.raise_for_status()
return r.json()
def tags(self) -> list[dict[str, str]]:
@ -142,7 +151,7 @@ class GiteaForgejoAPI:
def internal_api(self, uri: str):
url = f"{self.forge_root}/api/v1/{uri}"
r = requests.get(url)
assert r.status_code == 200, r
r.raise_for_status()
return r.json()
def tags(self) -> list[dict[str, Any]]: