Skip to content

Commit

Permalink
feat: support HTTP URL
Browse files Browse the repository at this point in the history
  • Loading branch information
ttionya committed Jun 3, 2020
1 parent 348d228 commit b199eaf
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
10 changes: 8 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,16 @@ branding:

inputs:
target_repository:
description: 'Sync to target repository full clone URL (SSH Only)'
description: 'Sync to target repository full clone URL. (Support SSH and HTTP URL)'
required: true
ssh_private_key:
description: 'SSH key used to authenticate with git operations'
description: 'SSH key used to authenticate with git operations. (with SSH URL)'
required: false
http_access_name:
description: 'Login name used to authenticate with git operations. (with HTTP URL)'
required: false
http_access_token:
description: 'Personal Access Token (PAT) used to authenticate with git operations. (with HTTP URL)'
required: false

runs:
Expand Down
30 changes: 24 additions & 6 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,40 @@ TARGET_REPOSITORY=${INPUT_TARGET_REPOSITORY}

#################### Function ####################
########################################
# Check target repository is valid.
# Check target repository URL type.
# Arguments:
# None
# Outputs:
# None / exit
########################################
function check_target_repository() {
local TARGET_REPOSITORY_HTTP_URL_MATCHED_COUNT=$(echo ${TARGET_REPOSITORY} | grep -cE '^http(s?)://')

if [[ ${TARGET_REPOSITORY_HTTP_URL_MATCHED_COUNT} -gt 0 ]]; then
color red "Target repository only support SSH URL."
exit 1
# HTTP URL
color blue "use HTTP URL"
configure_token
else
# SSH URL
color blue "use SSH URL"
configure_ssh
fi
}

########################################
# Configure access token.
# Arguments:
# None
########################################
function configure_token() {
git config --global credential.helper store

local TARGET_REPOSITORY_PROTOCOL=$(echo ${TARGET_REPOSITORY} | grep -oE '^http(s?)://')
color yellow "TARGET_REPOSITORY_PROTOCOL: ${TARGET_REPOSITORY_PROTOCOL}"
local TARGET_REPOSITORY_HOST=$(echo ${TARGET_REPOSITORY} | sed -r "s|${TARGET_REPOSITORY_PROTOCOL}||" | awk -F"/" '{ print $1 }')
color yellow "TARGET_REPOSITORY_HOST: ${TARGET_REPOSITORY_HOST}"

echo "${TARGET_REPOSITORY_PROTOCOL}${INPUT_HTTP_ACCESS_NAME}:${INPUT_HTTP_ACCESS_TOKEN}@${TARGET_REPOSITORY_HOST}" > ~/.git-credentials
}

########################################
# Configure SSH.
# Arguments:
Expand Down Expand Up @@ -92,7 +111,6 @@ function display_variables() {

#################### Actions ####################
check_target_repository
configure_ssh
display_variables

configure_git_remote
Expand Down

0 comments on commit b199eaf

Please sign in to comment.