From 5639bdce64977bd4082b7ff8f05d29f9734d1a9f Mon Sep 17 00:00:00 2001
From: jurgenhaas <juergen@paragon-es.de>
Date: Tue, 31 May 2022 16:06:38 +0200
Subject: [PATCH] gitlab-ci-cd/drupal#28 Make it work in pipelines too

---
 .gitignore |  1 +
 bin/merge  | 20 ++++++++++++--------
 2 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/.gitignore b/.gitignore
index e69de29..f174204 100644
--- a/.gitignore
+++ b/.gitignore
@@ -0,0 +1 @@
+/.ahoy.l3d
diff --git a/bin/merge b/bin/merge
index fa07528..99a6520 100755
--- a/bin/merge
+++ b/bin/merge
@@ -71,14 +71,18 @@ if [[ "$host1" != "$host2" ]]; then
   exit 4
 fi
 
-echo "Find project ID from remote URL ..."
-# shellcheck disable=SC2001
-path="$(echo "$path" | sed -e 's,\..*,,g')"
-gitlab 200 GET projects?search="$path"
-PRJID=$(echo "$result"  | jq -r .[0]."id")
-if [[ $(isNumeric "$PRJID") -eq 1 ]]; then
-  echo "Can not find project ID"
-  exit 5
+if [[ -n ${CI_PROJECT_ID} ]]; then
+  PRJID=$CI_PROJECT_ID
+else
+  echo "Find project ID from remote URL ..."
+  # shellcheck disable=SC2001
+  path="$(echo "$path" | sed -e 's,\..*,,g')"
+  gitlab 200 GET projects?search="$path"
+  PRJID=$(echo "$result"  | jq -r .[0]."id")
+  if [[ $(isNumeric "$PRJID") -eq 1 ]]; then
+    echo "Can not find project ID"
+    exit 5
+  fi
 fi
 
 echo "Create merge request ..."
-- 
GitLab