Skip to content

Commit

Permalink
fix: streamline authentication process by removing redundant gh auth …
Browse files Browse the repository at this point in the history
…status calls
  • Loading branch information
alexvanderberkel committed Jan 20, 2025
1 parent 899c207 commit e1b3e08
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 28 deletions.
15 changes: 5 additions & 10 deletions src/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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::"
Expand Down
19 changes: 1 addition & 18 deletions src/sync_template.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit e1b3e08

Please sign in to comment.