Skip to content

Commit

Permalink
Update run_black_on_git_diff_adds.sh
Browse files Browse the repository at this point in the history
Can now handle if a file is deleted
  • Loading branch information
DueViktor authored Nov 16, 2022
1 parent af81ee9 commit fd41a0f
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions run_black_on_git_diff_adds.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,19 @@ echo "looking for diff at ${github_pr_url}"
curl --request GET --url ${github_pr_url} --header "authorization: Bearer ${GITHUB_TOKEN}" --header "Accept: application/vnd.github.v3.diff" > github_diff.txt
diff_length=`wc -l github_diff.txt`
echo "approximate diff size: ${diff_length}"
python_files=`cat github_diff.txt | grep -E -- "\+\+\+ |\-\-\- " | awk '{print $2}' | grep -Po -- "(?<=[ab]/).+\.py$"`
echo "python files edited in this PR: ${python_files}"
python_files=`cat github_diff.txt | grep -E -- "\+\+\+" | awk '{print $2}' | grep -Po -- "(?<=[ab]/).+\.py$"`

if [[ -z "${LINE_LENGTH}" ]]; then
line_length=130
if [ ! "$python_files" ];then
echo "no python files to check"
else
line_length="${LINE_LENGTH}"
fi
echo "python files edited in this PR: ${python_files}"

if [[ -z "${LINE_LENGTH}" ]]; then
line_length=130
else
line_length="${LINE_LENGTH}"
fi

black --line-length ${line_length} --check ${python_files}

black --line-length ${line_length} --check ${python_files}
fi

0 comments on commit fd41a0f

Please sign in to comment.