Fix get file diff on pr event (#1305)

* Fix pr event sha

* Improve cmd

* Fix space
This commit is contained in:
Gabriel Diaz 2021-03-04 14:51:44 -05:00 committed by GitHub
parent 5294082063
commit 11720172cb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 31 deletions

View file

@ -68,34 +68,6 @@ function BuildFileList() {
# Need to build a list of all files changed # Need to build a list of all files changed
# This can be pulled from the GITHUB_EVENT_PATH payload # This can be pulled from the GITHUB_EVENT_PATH payload
################
# print header #
################
debug "----------------------------------------------"
debug "Pulling in code history and branches..."
#################################################################################
# Switch codebase back to the default branch to get a list of all files changed #
#################################################################################
SWITCH_CMD=$(
git -C "${GITHUB_WORKSPACE}" pull --quiet
git -C "${GITHUB_WORKSPACE}" checkout "${DEFAULT_BRANCH}" 2>&1
)
#######################
# Load the error code #
#######################
ERROR_CODE=$?
##############################
# Check the shell for errors #
##############################
if [ ${ERROR_CODE} -ne 0 ]; then
# Error
info "Failed to switch to ${DEFAULT_BRANCH} branch to get files changed!"
fatal "[${SWITCH_CMD}]"
fi
if [ "${GITHUB_EVENT_NAME}" == "push" ]; then if [ "${GITHUB_EVENT_NAME}" == "push" ]; then
################ ################
# push event # # push event #
@ -122,9 +94,6 @@ function BuildFileList() {
################ ################
# PR event # # PR event #
################ ################
################
# print header #
################
DIFF_CMD="git -C ${GITHUB_WORKSPACE} diff --name-only ${DEFAULT_BRANCH}...${GITHUB_SHA} --diff-filter=d" DIFF_CMD="git -C ${GITHUB_WORKSPACE} diff --name-only ${DEFAULT_BRANCH}...${GITHUB_SHA} --diff-filter=d"
GenerateFileDiff "$DIFF_CMD" GenerateFileDiff "$DIFF_CMD"
fi fi

View file

@ -474,6 +474,15 @@ GetGitHubVars() {
###################### ######################
GITHUB_ORG=$(jq -r '.repository.owner.login' <"${GITHUB_EVENT_PATH}") GITHUB_ORG=$(jq -r '.repository.owner.login' <"${GITHUB_EVENT_PATH}")
########################
# Fix SHA for PR event #
########################
# Github sha on PR events is not the latest commit.
# https://docs.github.com/en/actions/reference/events-that-trigger-workflows#pull_request
if [ "$GITHUB_EVENT_NAME" == "pull_request" ]; then
GITHUB_SHA=$(jq -r .pull_request.head.sha <"$GITHUB_EVENT_PATH")
fi
############################ ############################
# Validate we have a value # # Validate we have a value #
############################ ############################