From e1b3e08b3de9514cca35faaf2804b7a1f5da9c0f Mon Sep 17 00:00:00 2001 From: Alex Esseling Date: Mon, 20 Jan 2025 15:48:12 +0100 Subject: [PATCH] fix: streamline authentication process by removing redundant gh auth status calls --- src/entrypoint.sh | 15 +++++---------- src/sync_template.sh | 19 +------------------ 2 files changed, 6 insertions(+), 28 deletions(-) diff --git a/src/entrypoint.sh b/src/entrypoint.sh index f77fc36e..9a0779c1 100755 --- a/src/entrypoint.sh +++ b/src/entrypoint.sh @@ -157,22 +157,17 @@ function git_init() { else info "the source repository is located within GitHub." if [[ -n "${SOURCE_GH_TOKEN}" ]]; then - unset GITHUB_TOKEN - info "login to the source repository" - gh auth login --git-protocol "https" --hostname "${SOURCE_REPO_HOSTNAME}" --with-token <<< "${SOURCE_GH_TOKEN}" - info "login to the target repository" + unset GITHUB_TOKEN + gh auth login --git-protocol "https" --hostname "${SOURCE_REPO_HOSTNAME}" --with-token <<< "${SOURCE_GH_TOKEN}" if [[ -n "${TARGET_GH_TOKEN}" ]]; then gh auth login --git-protocol "https" --hostname "${SOURCE_REPO_HOSTNAME}" --with-token <<< "${TARGET_GH_TOKEN}" - fi - gh auth status --hostname "${source_repo_hostname}" - gh auth switch - gh auth status --hostname "${source_repo_hostname}" + fi + gh auth switch gh auth setup-git --hostname "${source_repo_hostname}" info "done set git global configuration" else info "default token to be used" - gh auth setup-git --hostname "${source_repo_hostname}" - gh auth status --hostname "${source_repo_hostname}" + gh auth setup-git --hostname "${source_repo_hostname}" fi fi echo "::endgroup::" diff --git a/src/sync_template.sh b/src/sync_template.sh index 24847dd4..0409d7c6 100755 --- a/src/sync_template.sh +++ b/src/sync_template.sh @@ -58,22 +58,6 @@ IS_FORCE_PUSH_PR="${IS_FORCE_PUSH_PR:-"false"}" IS_KEEP_BRANCH_ON_PR_CLEANUP="${IS_KEEP_BRANCH_ON_PR_CLEANUP:-"false"}" GIT_REMOTE_PULL_PARAMS="${GIT_REMOTE_PULL_PARAMS:---allow-unrelated-histories --squash --strategy=recursive -X theirs}" -# Error is located here -info "logged in as" -gh auth status --hostname "${source_repo_hostname}" -# Check if the repository exists - -gh repo list --visibility public -gh auth status --active -gh repo list --visibility private - -if gh repo view "$SOURCE_REPO" &>/dev/null; then - info "Successfully accessed the repository $SOURCE_REPO" -else - err "Failed to access the repository $SOURCE_REPO" - exit 1 -fi - TEMPLATE_REMOTE_GIT_HASH=$(git ls-remote "${SOURCE_REPO}" HEAD | awk '{print $1}') SHORT_TEMPLATE_GIT_HASH=$(git rev-parse --short "${TEMPLATE_REMOTE_GIT_HASH}") LOCAL_CURRENT_GIT_HASH=$(git rev-parse HEAD) # need to be run before a pull to get the current local git hash @@ -271,8 +255,7 @@ function pull_source_changes() { if [[ -n "${SRC_SSH_PRIVATEKEY_ABS_PATH}" ]] &>/dev/null; then info "we are using ssh for the source repo. No need to logout." - elif [[ -n "${SOURCE_GH_TOKEN}" ]] &>/dev/null; then - gh auth status --hostname "${SOURCE_REPO_HOSTNAME}" + elif [[ -n "${SOURCE_GH_TOKEN}" ]] &>/dev/null; then gh auth switch fi