From fd41a0f0c5013f36dd96f8371403cd7a22be5730 Mon Sep 17 00:00:00 2001 From: DueViktor <66885944+DueViktor@users.noreply.github.com> Date: Wed, 16 Nov 2022 21:43:31 +0100 Subject: [PATCH] Update run_black_on_git_diff_adds.sh Can now handle if a file is deleted --- run_black_on_git_diff_adds.sh | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) 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