From e943a55e90671b62f1d3bab789670a40584e784f Mon Sep 17 00:00:00 2001
From: Tim Jaacks <tim.jaacks@seco.com>
Date: Tue, 21 Mar 2023 12:41:10 +0100
Subject: [PATCH] Use project path instead of name in integration branch name

Usually project name and path are identical after project creation. It
is possible, though, to change the name of a project without changing
its path.
When triggering a pipeline on the integration branch, we are using the
CI_PROJECT_NAME variable to reference the project. Unexpectedly, this
variable contains the *path*, not the *name* of the project (see
https://gitlab.com/gitlab-org/gitlab/-/issues/20030).
Hence we have to use the project path in all other places where the
integration branch name is constructed in our Python code.
---
 manifest-integration-jobs.yml                        | 3 +++
 scripts/check_if_integration_branch_is_up_to_date.py | 2 +-
 scripts/integrate_into_manifest.py                   | 2 +-
 scripts/merge_into_manifest.py                       | 2 +-
 scripts/update_submodule.py                          | 2 +-
 5 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/manifest-integration-jobs.yml b/manifest-integration-jobs.yml
index fe049d0d..a317acd0 100644
--- a/manifest-integration-jobs.yml
+++ b/manifest-integration-jobs.yml
@@ -55,6 +55,9 @@ build:
     - if: $CI_MERGE_REQUEST_IID
   trigger:
     project: $TARGET_PROJECT
+    # Attention: CI_PROJECT_NAME contains the *path*, not the *name* of the project.
+    # Usually these are equal, but it is possible to change the name of a project
+    # without changing its path. See https://gitlab.com/gitlab-org/gitlab/-/issues/20030
     branch: "integrate/${CI_PROJECT_NAME}/${CI_COMMIT_REF_NAME}/into/${TARGET_BRANCH}"
     strategy: depend
 
diff --git a/scripts/check_if_integration_branch_is_up_to_date.py b/scripts/check_if_integration_branch_is_up_to_date.py
index e2192be8..009048a8 100755
--- a/scripts/check_if_integration_branch_is_up_to_date.py
+++ b/scripts/check_if_integration_branch_is_up_to_date.py
@@ -106,7 +106,7 @@ def main():
         )
 
     integration_branch_name = common.integration_branch_name(
-        source_project.name, merge_request.source_branch, args.target_branch
+        source_project.path, merge_request.source_branch, args.target_branch
     )
 
     if check_if_integration_branch_is_up_to_date(
diff --git a/scripts/integrate_into_manifest.py b/scripts/integrate_into_manifest.py
index 464fe8d2..8f6e0ab5 100755
--- a/scripts/integrate_into_manifest.py
+++ b/scripts/integrate_into_manifest.py
@@ -122,7 +122,7 @@ def integrate_into_manifest(
         else:
             # Create integration branch (delete former one if already exists)
             integration_branch = common.integration_branch_name(
-                project.name, merge_request.source_branch, manifest_branch
+                project.path, merge_request.source_branch, manifest_branch
             )
             for ref in manifest_repo.references:
                 if integration_branch == ref.name:
diff --git a/scripts/merge_into_manifest.py b/scripts/merge_into_manifest.py
index 00f199f6..0e9fee45 100755
--- a/scripts/merge_into_manifest.py
+++ b/scripts/merge_into_manifest.py
@@ -56,7 +56,7 @@ def merge_into_manifest(
     target_branch = manifest_branch
 
     integration_branch = common.integration_branch_name(
-        project.name, original_branch, target_branch
+        project.path, original_branch, target_branch
     )
 
     # Create merge request. If there already is a merge request, we assume that it has
diff --git a/scripts/update_submodule.py b/scripts/update_submodule.py
index f908a082..e184ad1d 100755
--- a/scripts/update_submodule.py
+++ b/scripts/update_submodule.py
@@ -252,7 +252,7 @@ def update_submodule_and_include_ref(
 
     # Construct integration branch name
     integration_branch_name = common.integration_branch_name(
-        submodule_project.name, integration_branch_suffix, branch
+        submodule_project.path, integration_branch_suffix, branch
     )
 
     # Construct commit message
-- 
GitLab