1
0
Fork 0

Merge pull request #1979 from Salamandar/fix_gitlab

Use direct API request for projects instead of search
This commit is contained in:
Alexandre Aubin 2024-01-26 23:00:15 +01:00 committed by GitHub
commit e74cb5522a

View file

@ -52,14 +52,11 @@ class GitlabAPI:
split = re.search("(?P<host>https?://.+)/(?P<group>[^/]+)/(?P<project>[^/]+)/?$", upstream) split = re.search("(?P<host>https?://.+)/(?P<group>[^/]+)/(?P<project>[^/]+)/?$", upstream)
self.upstream = split.group("host") self.upstream = split.group("host")
self.upstream_repo = f"{split.group('group')}/{split.group('project')}" self.upstream_repo = f"{split.group('group')}/{split.group('project')}"
self.project_id = self.find_project_id(split.group('project')) self.project_id = self.find_project_id(self.upstream_repo)
def find_project_id(self, project: str) -> int: def find_project_id(self, project: str) -> int:
projects = self.internal_api(f"projects?search={project}") project = self.internal_api(f"projects/{project.replace('/', '%2F')}")
for project in projects: return project["id"]
if project["path_with_namespace"] == self.upstream_repo:
return project["id"]
raise ValueError(f"Project {project} not found")
def internal_api(self, uri: str): def internal_api(self, uri: str):
url = f"{self.upstream}/api/v4/{uri}" url = f"{self.upstream}/api/v4/{uri}"
@ -77,7 +74,7 @@ class GitlabAPI:
{ {
"sha": commit["id"], "sha": commit["id"],
"commit": { "commit": {
"author": { "author": {
"date": commit["committed_date"] "date": commit["committed_date"]
} }
} }