Skip to content

Commit

Permalink
automatically fetch the tip of the base branch if it is not available
Browse files Browse the repository at this point in the history
  • Loading branch information
toy committed Jun 27, 2024
1 parent 2719576 commit 5ea6c6e
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ jobs:
BUNDLE_GEMFILE: ${{ github.workspace }}/test/using_bundler/Gemfile
steps:
- uses: actions/checkout@v4
- name: Fetch head commit of base branch
run: git fetch --depth 1 origin ${{ github.event.pull_request.base.sha }}
- uses: ruby/setup-ruby@v1
with:
ruby-version: 2.6
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ It's same as `-level` flag of reviewdog.
Optional. Run Rubocop only on changed (and added) files, for speedup [`true`, `false`].
Default: `false`.

Will fetch the tip of the base branch with depth 1 from remote origin if it is not available.
If you use different remote name or customize the checkout otherwise, make the tip of the base branch available before this action

### `reporter`

Optional. Reporter of reviewdog command [`github-pr-check`, `github-check`, `github-pr-review`].
Expand Down
5 changes: 4 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ inputs:
description: 'Report level for reviewdog [info,warning,error]'
default: 'error'
only_changed:
description: "Run Rubocop only on changed (and added) files, for speedup [`true`, `false`]"
description: |
Run Rubocop only on changed (and added) files, for speedup [`true`, `false`].
Will fetch the tip of the base branch with depth 1 from remote origin if it is not available.
If you use different remote name or customize the checkout otherwise, make the tip of the base branch available before this action.
default: 'false'
reporter:
description: |
Expand Down
5 changes: 5 additions & 0 deletions script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ fi
if [ "${INPUT_ONLY_CHANGED}" = "true" ]; then
echo '::group:: Getting changed files list'

# check if commit is present in repository, otherwise fetch it
if ! git cat-file -e "${BASE_REF}"; then
git fetch --depth 1 origin "${BASE_REF}"
fi

# get intersection of changed files (excluding deleted) with target files for
# rubocop as an array
# shellcheck disable=SC2086
Expand Down

0 comments on commit 5ea6c6e

Please sign in to comment.