From 438bf882d0ecdbb49616c38455d30fbdfdc63936 Mon Sep 17 00:00:00 2001
From: Sheogorath <sheogorath@shivering-isles.com>
Date: Tue, 23 Jun 2020 16:35:45 +0200
Subject: [PATCH] Make `setup-github-mirror.sh` URL aware

Previously one had to manually take the repository slug from the URL in
order to set up a github mirror. This patch makes the script aware of
the slug's position in the github URL and will grab it from there.
---
 setup-github-mirror.sh | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/setup-github-mirror.sh b/setup-github-mirror.sh
index 397e723..2f418f4 100755
--- a/setup-github-mirror.sh
+++ b/setup-github-mirror.sh
@@ -16,6 +16,10 @@ EOF
 fi
 REPO_SLUG="$1"
 
+if grep 'https://github.com/' <<< "$REPO_SLUG"; then
+  REPO_SLUG="$(sed -Ee 's/^https:\/\/github\.com\/([^/]+\/[^/]+).*/\1/' <<< "$REPO_SLUG")"
+fi
+
 # Load configs
 SCRIPT_DIR=$(dirname $0)
 
@@ -133,4 +137,3 @@ curl --header "PRIVATE-TOKEN: ${ACCESS_TOKEN}" \
 "${GITLAB_URL}/api/v4/projects/${GITLAB_PROJECT_ID}/deploy_keys/${MIRROR_KEY_ID}" > /dev/null
 
 echo "./mirror.sh 'https://github.com/${REPO_SLUG}.git' '${GITLAB_PROJECT_URL}'"
-
-- 
GitLab