Merge pull request #2054 from Salamandar/fix_gitlab
Fix some gitlab instances that return 404 on url-encoded project paths, by calling search
This commit is contained in:
commit
721dae2c2a
1 changed files with 13 additions and 4 deletions
|
@ -25,7 +25,7 @@ class GithubAPI:
|
||||||
def internal_api(self, uri: str) -> Any:
|
def internal_api(self, uri: str) -> Any:
|
||||||
url = f"https://api.github.com/{uri}"
|
url = f"https://api.github.com/{uri}"
|
||||||
r = requests.get(url, auth=self.auth)
|
r = requests.get(url, auth=self.auth)
|
||||||
assert r.status_code == 200, r
|
r.raise_for_status()
|
||||||
return r.json()
|
return r.json()
|
||||||
|
|
||||||
def tags(self) -> list[dict[str, str]]:
|
def tags(self) -> list[dict[str, str]]:
|
||||||
|
@ -66,7 +66,16 @@ class GitlabAPI:
|
||||||
return match.group(1)
|
return match.group(1)
|
||||||
|
|
||||||
def find_project_id(self, project: str) -> int:
|
def find_project_id(self, project: str) -> int:
|
||||||
|
try:
|
||||||
project = self.internal_api(f"projects/{project.replace('/', '%2F')}")
|
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)
|
assert isinstance(project, dict)
|
||||||
project_id = project.get("id", None)
|
project_id = project.get("id", None)
|
||||||
return project_id
|
return project_id
|
||||||
|
@ -74,7 +83,7 @@ class GitlabAPI:
|
||||||
def internal_api(self, uri: str) -> Any:
|
def internal_api(self, uri: str) -> Any:
|
||||||
url = f"{self.forge_root}/api/v4/{uri}"
|
url = f"{self.forge_root}/api/v4/{uri}"
|
||||||
r = requests.get(url)
|
r = requests.get(url)
|
||||||
assert r.status_code == 200, r
|
r.raise_for_status()
|
||||||
return r.json()
|
return r.json()
|
||||||
|
|
||||||
def tags(self) -> list[dict[str, str]]:
|
def tags(self) -> list[dict[str, str]]:
|
||||||
|
@ -142,7 +151,7 @@ class GiteaForgejoAPI:
|
||||||
def internal_api(self, uri: str):
|
def internal_api(self, uri: str):
|
||||||
url = f"{self.forge_root}/api/v1/{uri}"
|
url = f"{self.forge_root}/api/v1/{uri}"
|
||||||
r = requests.get(url)
|
r = requests.get(url)
|
||||||
assert r.status_code == 200, r
|
r.raise_for_status()
|
||||||
return r.json()
|
return r.json()
|
||||||
|
|
||||||
def tags(self) -> list[dict[str, Any]]:
|
def tags(self) -> list[dict[str, Any]]:
|
||||||
|
|
Loading…
Reference in a new issue