From 572331753c3787dee4a6c0b6719c889af9646b81 Mon Sep 17 00:00:00 2001 From: Mahesh Bandara Wijerathna Date: Fri, 20 Jan 2023 00:03:31 +0530 Subject: [PATCH] fix: remote URL querying of repos cloned using an SSH key (#122) * fix: remote URL querying of repos cloned using an SSH key Fixes #120. * perf: improve `sed` scripts and minimize usage of conditionals * perf: remove unnecessary conditionals --- entrypoint.sh | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index a0a2806..3a7f940 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -70,20 +70,7 @@ echo_info "DESTINATION_BRANCH=$DESTINATION_BRANCH" # Determine repository url if [[ -z "$INPUT_DESTINATION_REPOSITORY" ]]; then # Try to query local repository's remote url if INPUT_DESTINATION_REPOSITORY is null - local_origin=$(git remote get-url origin) - - if [[ "$local_origin" == *.git ]]; then - origin_no_suffix="${local_origin%.*}" - else - origin_no_suffix="$local_origin" - fi - - repo="$(basename "${origin_no_suffix}")" - owner="$(basename "${origin_no_suffix%/${repo}}")" - - if [[ ! -z "$repo" ]]; then - CHECKOUT_REPOSITORY="$owner/$repo" - fi + CHECKOUT_REPOSITORY=$(git remote get-url origin | sed -r -e 's:https\://([^/]+)/([^/]+)/([^.]+)(.*):\2\/\3:g' -e 's:git@([^/]+)\:([^/]+)/([^.]+)(.*):\2\/\3:g') fi # Fallback to GITHUB_REPOSITORY if both INPUT_DESTINATION_REPOSITORY and CHECKOUT_REPOSITORY are unavailable