Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore files ignored by git to avoid unexpected reports #2

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ The script display a colored output on the terminal (inspired by [Abricot-Normin

### Install
```
git clone git@github.com:Ardorax/BananaSplit.git
git clone git@github.com:Epibite/BananaSplit.git

mv BananaSplit/coding-style.sh ~/.local/bin/banana
# OR
Expand Down
24 changes: 21 additions & 3 deletions coding-style.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,18 @@ function cat_readme() {
function banana_split() {
CURRENT_FILE=".c"
echo -e "${Yellow}BANANA NA NA NA NA${Color_Off}"
if [ -f ".gitignore" ]; then
git ls-files --others --ignored --exclude-standard > ignore.tmp
fi
while read p; do
IFS=':' read -ra ADDR <<< "$p"
if [ -f "ignore.tmp" ]; then
while read ignored; do
if [ "$ignored" -ef "${ADDR[0]}" ]; then
continue 2
fi
done < "ignore.tmp"
fi
if [ "$CURRENT_FILE" != "${ADDR[0]}" ]; then
echo "‣ In file ${ADDR[0]}"
CURRENT_FILE="${ADDR[0]}"
Expand All @@ -35,6 +45,7 @@ function banana_split() {
echo -ne " ($error)${Color_Off} - ${errors[${error}]^}."
echo -e " ${IBlack}(${ADDR[0]: 2}:${ADDR[1]})${Color_Off}"
done < "$1"
rm -f "ignore.tmp"
echo -e "${Yellow}BANANA SPLIT${Color_Off}"
}

Expand Down Expand Up @@ -89,10 +100,17 @@ errors=(

if [ $# == 1 ] && [ $1 == "--help" ]; then
cat_readme
elif [ $# = 2 ];
elif [ $# == 1 ] || [ $# = 2 ];
then
if [ $# == 1 ];
then
REPORTS_DIR=$(my_readlink ".")
elif [ $# = 2 ];
then
REPORTS_DIR=$(my_readlink "$2")
fi

DELIVERY_DIR=$(my_readlink "$1")
REPORTS_DIR=$(my_readlink "$2")
DOCKER_SOCKET_PATH=/var/run/docker.sock
HAS_SOCKET_ACCESS=$(test -r $DOCKER_SOCKET_PATH; echo "$?")
GHCR_REGISTRY_TOKEN=$(curl -s "https://ghcr.io/token?service=ghcr.io&scope=repository:epitech/coding-style-checker:pull" | grep -o '"token":"[^"]*' | grep -o '[^"]*$')
Expand Down Expand Up @@ -128,7 +146,7 @@ then
fi

### generate reports
$BASE_EXEC_CMD run --rm -i -v "$DELIVERY_DIR":"/mnt/delivery" -v "$REPORTS_DIR":"/mnt/reports" ghcr.io/epitech/coding-style-checker:latest "/mnt/delivery" "/mnt/reports"
$BASE_EXEC_CMD run --rm --security-opt "label:disable" -i -v "$DELIVERY_DIR":"/mnt/delivery" -v "$REPORTS_DIR":"/mnt/reports" ghcr.io/epitech/coding-style-checker:latest "/mnt/delivery" "/mnt/reports"
# [[ -f "$EXPORT_FILE" ]] && echo "$(wc -l < "$EXPORT_FILE") coding style error(s) reported in "$EXPORT_FILE", $(grep -c ": MAJOR:" "$EXPORT_FILE") major, $(grep -c ": MINOR:" "$EXPORT_FILE") minor, $(grep -c ": INFO:" "$EXPORT_FILE") info"

banana_split "$EXPORT_FILE"
Expand Down