Skip to content

Commit

Permalink
Do not rebase on top of origin/main
Browse files Browse the repository at this point in the history
The previous version would report shifted line numbers.
  • Loading branch information
praiskup committed Sep 6, 2024
1 parent fd9564d commit 63ee81d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
9 changes: 7 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,20 @@ inputs:
required: false

pull_request_number_id:
description: "The pull requires ID (internal)"
description: "The pull request ID (internal)"
default: ${{ github.event.pull_request.number }}
required: false

pull_request_head:
description: "The pull requirest SHA1 without merge commit (internal)"
description: "The pull request SHA1 without the merge commit (internal)"
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

outputs:
sarif:
description: 'The SARIF file containing defects'
Expand Down
15 changes: 5 additions & 10 deletions container/cmd
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ result=true

error() { echo "DIFF_LINT_ERROR: $*" >&2 ; }

target_branch=${GITHUB_BASE_REF-main}

is_true() {
[[ $# -le 0 ]] && return 1

Expand Down Expand Up @@ -39,9 +37,7 @@ set_linter_options()
for tag in $INPUT_LINTER_TAGS; do
linter_options+=( --linter-tag "$tag" )
done
if test "$target_branch" != main; then
linter_options+=( --compare-against "origin/$target_branch" )
fi
linter_options+=( --compare-against "$INPUT_PULL_REQUEST_BASE" )
}

populate_sarif_data()
Expand Down Expand Up @@ -77,18 +73,17 @@ if test "$GITHUB_EVENT_NAME" = 'pull_request'; then
git config --global --add safe.directory '*'
git config --global advice.detachedHead false
git config --global init.defaultBranch main
git config --global user.email "[email protected]"
git config --global user.name "VCS Diff Lint automation"

(
echo "## Rebasing $INPUT_PULL_REQUEST_HEAD onto $target_branch ##"
echo "## Checking out $INPUT_PULL_REQUEST_HEAD ##"
$debug_mode || exec &>/dev/null
git fetch origin "$target_branch:$target_branch"
git fetch origin "+$INPUT_PULL_REQUEST_HEAD:refs/remotes/pull-requests/pr-detached-$INPUT_PULL_REQUEST_ID"
git checkout "$INPUT_PULL_REQUEST_HEAD"
git rebase "origin/$target_branch"
)

# 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.

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

Expand Down

0 comments on commit 63ee81d

Please sign in to comment.