Skip to content

Ensure pull request branch name does not cause collisions #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@ function help {
function checkout {
local REF=
local LOCAL_BRANCH=
local LOCAL_BRANCH_NAME=

if [[ ! $GITHUB_EVENT_NAME || ! $GITHUB_REPOSITORY || ! $GITHUB_REF ]];then
return
fi

LOCAL_BRANCH_NAME=$GITHUB_HEAD_REF

case $GITHUB_EVENT_NAME in
pull_request)
REF=$GITHUB_REF
Expand All @@ -33,6 +36,8 @@ function checkout {
echo "Missing head or base ref env variables; aborting"
exit 1
fi

LOCAL_BRANCH_NAME=pull/${LOCAL_BRANCH_NAME}
;;
push)
REF=${GITHUB_REF/refs\/heads\//}
Expand Down Expand Up @@ -66,9 +71,9 @@ function checkout {
echo "Checking out branch ${BASE_BRANCH}"
git checkout ${BASE_BRANCH}
echo "Fetching ref ${REF}"
git fetch origin $REF:${GITHUB_HEAD_REF}
echo "Checking out to ${GITHUB_HEAD_REF}"
git checkout $GITHUB_HEAD_REF
git fetch origin "${REF}":"${LOCAL_BRANCH_NAME}"
echo "Checking out target ref to ${LOCAL_BRANCH_NAME}"
git checkout "${LOCAL_BRANCH_NAME}"
fi
}

Expand Down