@@ -34,8 +34,14 @@ if [[ -d "${LOCAL_REPO}/.git" ]]; then
3434fi
3535
3636PRIVATE_DEVCONTAINER_ENABLED=" $( get_metadata_value " private-devcontainer-enabled" " " ) "
37- # Check if repo is private by attempting to list files
38- if [[ " ${PRIVATE_DEVCONTAINER_ENABLED} " = " TRUE" ]] && ! git ls-remote " ${REPO_SRC} " & > /dev/null; then
37+ # Replace ssh URL with HTTPS URL
38+ https_url=" ${REPO_SRC/ git@ github.com:/ https:// github.com/ } "
39+ # Create GitHub API URL
40+ api_url=" https://api.github.com/repos/${https_url/ https: \/\/ github.com\/ / } "
41+ api_url=" ${api_url% .git} "
42+ # Check if repo is private
43+ private_status=$( curl --retry 5 -s " ${api_url} " | jq -r " .status" )
44+ if [[ " ${PRIVATE_DEVCONTAINER_ENABLED} " == " TRUE" && " ${private_status} " == 404 ]]; then
3945 # disable logs to not expose access token
4046 set +o xtrace
4147
@@ -57,11 +63,13 @@ if [[ "${PRIVATE_DEVCONTAINER_ENABLED}" = "TRUE" ]] && ! git ls-remote "${REPO_S
5763
5864 token=$( echo " ${response} " | head -n1)
5965 # Insert token into url
60- repo_auth_url=$( echo " ${REPO_SRC } " | sed " s/:\/\//:\/\/${token} @/" )
66+ repo_auth_url=$( echo " ${https_url } " | sed " s/:\/\//:\/\/${token} @/" )
6167
6268 # Clone the private repo
69+ set +o errexit
6370 response=$( git clone " ${repo_auth_url} " " ${LOCAL_REPO} " 2>&1 )
6471 git_status=$?
72+ set -o errexit
6573 if [[ ${git_status} -ne 0 ]]; then
6674 set_metadata " startup_script/status" " ERROR"
6775 set_metadata " startup_script/message" " Failed to clone the devcontainer GitHub repo. ERROR: ${response} "
@@ -72,8 +80,10 @@ if [[ "${PRIVATE_DEVCONTAINER_ENABLED}" = "TRUE" ]] && ! git ls-remote "${REPO_S
7280 set -o xtrace
7381else
7482 # GitHub repo is public
83+ set +o errexit
7584 response=$( git clone " ${REPO_SRC} " " ${LOCAL_REPO} " 2>&1 )
7685 git_status=$?
86+ set -o errexit
7787 if [[ ${git_status} -ne 0 ]]; then
7888 set_metadata " startup_script/status" " ERROR"
7989 set_metadata " startup_script/message" " Failed to clone the devcontainer GitHub repo. ERROR: ${response} "
0 commit comments