Verified Commit 7ff13187 authored by Jordan Petridіs's avatar Jordan Petridіs 🌱
Browse files

build_manifest.py: Fix the api querries

Previously the script assumed that the best match will be the first
result, but that's not always the case apparently.
parent 39e2ddf7
......@@ -99,21 +99,21 @@ def request(path: str) -> List[Dict[str, str]]:
return request_raw(path, headers, project_url)
def request_wrap(path: str) -> List[Dict[str, str]]:
resp: List[Dict[str, str]] = request(path)
def get_project_branch(project_id: int, name: str) -> Dict[str, str]:
print(f"Searching for {name} branch in project {project_id}")
path = f"projects/{project_id}/repository/branches?search={name}"
results = request(path)
if not resp:
if not results:
return None
if not resp[0]:
return None
return resp[0]
# The api returns a list of projects that match the search
# we want the exact match, which might not be the first on the list
for project_res in results:
if project_res["name"] == name:
return project_res
def get_project_branch(project_id: int, name: str) -> Dict[str, str]:
print(f"Searching for {name} branch in project {project_id}")
path = f"projects/{project_id}/repository/branches?search={name}"
return request_wrap(path)
return None
@preserve_ci_vars
......@@ -141,7 +141,18 @@ def test_get_project_branch():
def search_user_namespace(user: str, project: str) -> Dict[str, str]:
print(f"Searching for {project} project in @{user} user's namespace")
path = f"users/{user}/projects?search={project}"
return request_wrap(path)
results = request(path)
if not results:
return None
# The api returns a list of projects that match the search
# we want the exact match, which might not be the first on the list
for project_res in results:
if project_res["path"] == project:
return project_res
return None
@preserve_ci_vars
......@@ -165,7 +176,7 @@ def test_search_user_namespace():
def search_group_namespace(group_id: str, project: str) -> Dict[str, str]:
print(f"Searching for {project} project in @{group_id} group namespace")
path = f"groups/{group_id}/search?scope=projects&search={project}"
return request_wrap(path)
return request(path)
@preserve_ci_vars
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment