Skip to content

Commit

Permalink
Calculate the previous commit to diff against
Browse files Browse the repository at this point in the history
The github.event.pull_request.base.sha provides a wrong commit SHA
pointing at the *current* upstream HEAD.  This particular one may not be
even fetched (a concurrent PR merged in the meantime).

The GitHub Context provides no info about the previous commit SHA we
need, so let's calculate it manually from
the ${{ github.event.commits }} number
  • Loading branch information
praiskup committed Sep 6, 2024
1 parent 3432236 commit 844193e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
8 changes: 4 additions & 4 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ inputs:
default: ${{ github.event.pull_request.head.sha }}
required: false

pull_request_base:
description: "The commit right before the pull-request commits (intenral)"
default: ${{ github.event.pull_request.base.sha }}
required: true
pull_request_commits:
description: "Number of commits in this PR"
required: false
default: ${{ github.event.commits }}

outputs:
sarif:
Expand Down
5 changes: 4 additions & 1 deletion container/cmd
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ set_linter_options()
for tag in $INPUT_LINTER_TAGS; do
linter_options+=( --linter-tag "$tag" )
done
linter_options+=( --compare-against "$INPUT_PULL_REQUEST_BASE" )
}

populate_sarif_data()
Expand Down Expand Up @@ -89,6 +88,10 @@ if test "$GITHUB_EVENT_NAME" = 'pull_request'; then
# We don't want to rebase on top of the current upstream's head; the line
# numbers would be shifted and the provided output would be misleading.

# Get the last commit before this PR.
last_committed=$(git rev-parse "HEAD~$INPUT_PULL_REQUEST_COMMITS")
linter_options+=( --compare-against "$last_committed" )

test -z "$INPUT_SUBDIRECTORY" || INPUT_SUBDIRECTORIES=$INPUT_SUBDIRECTORY
test -z "$INPUT_SUBDIRECTORIES" && INPUT_SUBDIRECTORIES=.

Expand Down

0 comments on commit 844193e

Please sign in to comment.