build_manifest.py: search user namespaces instead of global

Previously find_repository_sha would do a global search of
all the projects in the gitlab instance. This ports it to
use the user namespace endpoint.

Additionally seems like the else: block never worked.
This commit is contained in:
Jordan Petridis 2018-10-24 17:34:58 +03:00
parent 0b9a8b5cac
commit ea5459e127
No known key found for this signature in database
GPG key ID: 902CC06D159744F5

View file

@ -122,37 +122,29 @@ def test_get_hostname():
def find_repository_sha(module: str, branchname: str) -> Tuple[str, str]: def find_repository_sha(module: str, branchname: str) -> Tuple[str, str]:
# FIXME: This does global search query in the whole gitlab instance. project = search_user_namespace(os.environ["GITLAB_USER_LOGIN"], module)
# It has been working so far by a miracle. It should be limited only to
# the current namespace instead.
for project in request('projects?search=' + module):
if project['name'] != module:
continue
if 'namespace' not in project:
# print("No 'namespace' in: %s - ignoring?" % project, file=sys.stderr)
continue
if project:
id = project['id'] id = project['id']
if project['namespace']['path'] in useful_namespaces: # If we have a branch with same name, use it.
if project['namespace']['path'] == user_namespace: branch = get_project_branch(id, branchname)
# If we have a branch with same name, use it. if branch is not None:
branch = get_project_branch(id, branchname) name = project['namespace']['path']
if branch is not None: print(f"{name}/{branchname}")
name = project['namespace']['path']
print(f"{name}/{branchname}")
return 'user', branch['commit']['id'] return 'user', branch['commit']['id']
else: # This won't work until gstreamer migrates to gitlab
branch = get_project_branch(id, branchname) else:
if branch is not None: id = 'FIXME: query the gstreamer group in fd.o'
print(f"gstreamer/{branchname}") branch = get_project_branch(id, branchname)
return 'gstreamer', branch['commit']['id'] if branch is not None:
print(f"gstreamer/{branchname}")
return 'gstreamer', branch['commit']['id']
branch = get_project_branch(id, 'master') branch = get_project_branch(id, 'master')
if branch is not None: if branch is not None:
print('gstreamer/master') print('gstreamer/master')
return 'gstreamer', branch.attributes['commit']['id'] return 'gstreamer', branch.attributes['commit']['id']
print('origin/master') print('origin/master')
return 'origin', 'master' return 'origin', 'master'