build_manifest.py: Use CI_PROJECT_NAMESPACE instead of GITLAB_USER

GITLAB_USER_* variables represent the user *that triggered* the job,
which might not match the user that owns the namespace of the fork.

This happens frequently with rebase, where the one who triggers the
rebase is the one that appears in the GITLAB_USER_* vars.

Instead use the CI_PROJECT_NAMESPACE variable to search the user's
projects. If CI_PROJECT_NAMESPACE has the value of a Group namespace
search_user_namespace returns 404.
This commit is contained in:
Jordan Petridis 2018-11-13 12:52:17 +02:00
parent e3d2c345b6
commit 48f3063daf
No known key found for this signature in database
GPG key ID: 902CC06D159744F5

View file

@ -45,7 +45,7 @@ def preserve_ci_vars(func):
def wrapper():
try:
url = os.environ["CI_PROJECT_URL"]
user = os.environ["GITLAB_USER_LOGIN"]
user = os.environ["CI_PROJECT_NAMESPACE"]
except KeyError:
url = "invalid"
user = ""
@ -57,7 +57,7 @@ def preserve_ci_vars(func):
func()
os.environ["CI_PROJECT_URL"] = url
os.environ["GITLAB_USER_LOGIN"] = user
os.environ["CI_PROJECT_NAMESPACE"] = user
if private:
os.environ["READ_PROJECTS_TOKEN"] = private
@ -177,10 +177,14 @@ def test_search_user_namespace():
res = search_user_namespace("alatiera", "404-project-not-found")
assert res is None
# Passing a group namespace instead of user should return None
res = search_user_namespace("gstreamer", "gst-plugins-good")
assert res is None
def find_repository_sha(module: Tuple[str, int], branchname: str) -> Tuple[str, str]:
user_login: str = os.environ["GITLAB_USER_LOGIN"]
project = search_user_namespace(user_login, module[0])
namespace: str = os.environ["CI_PROJECT_NAMESPACE"]
project = search_user_namespace(namespace, module[0])
# Find a fork in the User's namespace
if project:
@ -219,7 +223,7 @@ def find_repository_sha(module: Tuple[str, int], branchname: str) -> Tuple[str,
@preserve_ci_vars
def test_find_repository_sha():
os.environ["CI_PROJECT_URL"] = "https://gitlab.freedesktop.org/gstreamer/gst-plugins-good"
os.environ["GITLAB_USER_LOGIN"] = "alatiera"
os.environ["CI_PROJECT_NAMESPACE"] = "alatiera"
del os.environ["READ_PROJECTS_TOKEN"]
# This should find the repository in the user namespace