From ef150499795a805a9ed2071c586919ccb1c3353d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Pi=C3=A9dallu?= Date: Fri, 26 Jan 2024 22:52:33 +0100 Subject: [PATCH] Use direct API request for projects instead of search --- autoupdate_app_sources/rest_api.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/autoupdate_app_sources/rest_api.py b/autoupdate_app_sources/rest_api.py index d7da8a8..a76821a 100644 --- a/autoupdate_app_sources/rest_api.py +++ b/autoupdate_app_sources/rest_api.py @@ -52,14 +52,11 @@ class GitlabAPI: split = re.search("(?Phttps?://.+)/(?P[^/]+)/(?P[^/]+)/?$", upstream) self.upstream = split.group("host") 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: - projects = self.internal_api(f"projects?search={project}") - for project in projects: - if project["path_with_namespace"] == self.upstream_repo: - return project["id"] - raise ValueError(f"Project {project} not found") + project = self.internal_api(f"projects/{project.replace('/', '%2F')}") + return project["id"] def internal_api(self, uri: str): url = f"{self.upstream}/api/v4/{uri}" @@ -77,7 +74,7 @@ class GitlabAPI: { "sha": commit["id"], "commit": { - "author": { + "author": { "date": commit["committed_date"] } }