From 11720172cb14049c18cffbce4f14e4ab7c0fefe4 Mon Sep 17 00:00:00 2001 From: Gabriel Diaz Date: Thu, 4 Mar 2021 14:51:44 -0500 Subject: [PATCH] Fix get file diff on pr event (#1305) * Fix pr event sha * Improve cmd * Fix space --- lib/functions/buildFileList.sh | 31 ------------------------------- lib/linter.sh | 9 +++++++++ 2 files changed, 9 insertions(+), 31 deletions(-) diff --git a/lib/functions/buildFileList.sh b/lib/functions/buildFileList.sh index ed48de18..7e1c3bbd 100755 --- a/lib/functions/buildFileList.sh +++ b/lib/functions/buildFileList.sh @@ -68,34 +68,6 @@ function BuildFileList() { # Need to build a list of all files changed # 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 ################ # push event # @@ -122,9 +94,6 @@ function BuildFileList() { ################ # PR event # ################ - ################ - # print header # - ################ DIFF_CMD="git -C ${GITHUB_WORKSPACE} diff --name-only ${DEFAULT_BRANCH}...${GITHUB_SHA} --diff-filter=d" GenerateFileDiff "$DIFF_CMD" fi diff --git a/lib/linter.sh b/lib/linter.sh index ae28c5a2..019daff1 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -474,6 +474,15 @@ GetGitHubVars() { ###################### 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 # ############################