diff --git a/run_black_on_git_diff_adds.sh b/run_black_on_git_diff_adds.sh index fdc79e6..c9e6d6d 100755 --- a/run_black_on_git_diff_adds.sh +++ b/run_black_on_git_diff_adds.sh @@ -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} \ No newline at end of file +fi