Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions tests/patch/ruff/info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"run": ["ruff.sh"]
}
60 changes: 60 additions & 0 deletions tests/patch/ruff/ruff.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0

HEAD=$(git rev-parse HEAD)
rc=0

pr() {
echo " ====== $* ======" | tee -a /dev/stderr
}

# If it doesn't touch .py files, don't bother. Ignore deleted.
if ! git show --diff-filter=AM --pretty="" --name-only "${HEAD}" | grep -q -E "\.py$"
then
echo "No python scripts touched, skip" >&"$DESC_FD"
exit 0
fi

ruff --version || exit 1

tmpfile_o=$(mktemp)
tmpfile_n=$(mktemp)

echo "Redirect to $tmpfile_o and $tmpfile_n"

echo "Tree base:"
git log -1 --pretty='%h ("%s")' HEAD~
echo "Now at:"
git log -1 --pretty='%h ("%s")' HEAD

pr "Checking before the patch"
git checkout -q HEAD~

# Also ignore created, as not present in the parent commit
for f in $(git show --diff-filter=M --pretty="" --name-only "${HEAD}" | grep -E "\.py$"); do
ruff check --output-format pylint "$f" | tee -a "$tmpfile_o"
done

incumbent=$(wc -l < "$tmpfile_o")

pr "Checking the tree with the patch"
git checkout -q "$HEAD"

for f in $(git show --diff-filter=AM --pretty="" --name-only "${HEAD}" | grep -E "\.py$"); do
ruff check --output-format pylint "$f" | tee -a "$tmpfile_n"
done

current=$(wc -l < "$tmpfile_n")

echo "Errors before: $incumbent ; this patch: $current" >&"$DESC_FD"

if [ "$current" -gt "$incumbent" ]; then
echo "New errors added" 1>&2
diff -U 0 "$tmpfile_o" "$tmpfile_n" 1>&2

rc=1
fi

rm "$tmpfile_o" "$tmpfile_n"

exit $rc