Skip to content

Commit 1c01a3f

Browse files
fix: github-pr-review path's black_check_output value (#57)
* fix: github-pr-review path's black_check_output value are stored with regenerate normal value * read drop regenerated exit code * fix: filter jupyter warning and improve readme This commit makes sure that the Jupyter warning that is thrown by black when Jupyter is not installed and the repo contains `.ipynb` files does not show in the `BLACK_CHECK_FILE_PATHS` variable. It also adds documentaiton for the `BLACK_CHECK_FILE_PATHS`. Co-authored-by: rickstaa <rick.staa@outlook.com>
1 parent 752e8a2 commit 1c01a3f

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ Default is github-pr-check.
7676

7777
**Optional**. Additional reviewdog flags. Defaults to `""`.
7878

79+
## Outputs
80+
81+
### `BLACK_CHECK_FILE_PATHS`
82+
83+
Contains all the files that would be changed by black.
84+
7985
## Format your code
8086

8187
This action is meant to annotate any possible changes that would need to be made to make your code adhere to the [black formatting guidelines](github.com/psf/black). It does not apply these changes to your codebase. If you also want to apply the changes to your repository, you can use the [reviewdog/action-suggester](https://github.com/reviewdog/action-suggester). You can find examples of how this is done can be found in [rickstaa/action-black](https://github.com/rickstaa/action-black/)

entrypoint.sh

+13-3
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,12 @@ if [[ "${INPUT_REPORTER}" = 'github-pr-review' ]]; then
3939
-level="${INPUT_LEVEL}" \
4040
-fail-on-error="${INPUT_FAIL_ON_ERROR}" \
4141
${INPUT_REVIEWDOG_FLAGS} || reviewdog_exit_val="$?"
42-
else
4342

43+
# Re-generate black output. Needed because the output of the '--diff' option can not
44+
# be used to retrieve the files that black would change
45+
# shellcheck disable=SC2086,SC2034
46+
black_check_output="$(black --check . ${INPUT_BLACK_ARGS} 2>&1)" || true
47+
else
4448
echo "[action-black] Checking python code with the black formatter and reviewdog..."
4549
# shellcheck disable=SC2086
4650
black_check_output="$(black --check . ${INPUT_BLACK_ARGS} 2>&1)" ||
@@ -57,17 +61,23 @@ else
5761
${INPUT_REVIEWDOG_FLAGS} || reviewdog_exit_val="$?"
5862
fi
5963

64+
# Remove jupyter warning if present
65+
black_check_output="${black_check_output//"Skipping .ipynb files as Jupyter dependencies are not installed."/}"
66+
black_check_output="${black_check_output//"You can fix this by running \`\`pip install black[jupyter]\`\`"/}"
67+
6068
# Output the checked file paths that would be formatted
6169
black_check_file_paths=()
6270
while read -r line; do
63-
black_check_file_paths+=("$line")
71+
if [ "$line" != "" ]; then
72+
black_check_file_paths+=("$line")
73+
fi
6474
done <<<"${black_check_output//"would reformat "/}"
6575

6676
# remove last two lines of black output, since they are irrelevant
6777
unset "black_check_file_paths[-1]"
6878
unset "black_check_file_paths[-1]"
6979

70-
# append the array elements to BLACK_CHECK_FILE_PATHS in github env
80+
# Append the array elements to BLACK_CHECK_FILE_PATHS in github env
7181
# shellcheck disable=SC2129
7282
echo "BLACK_CHECK_FILE_PATHS<<EOF" >>"$GITHUB_ENV"
7383
echo "${black_check_file_paths[@]}" >>"$GITHUB_ENV"

0 commit comments

Comments
 (0)