Skip to content

Commit c666b11

Browse files
Merge pull request #51 from Contrast-Security-OSS/release_candidate_v1_0_8
Release candidate v1.0.8
2 parents 5e7568a + e82182f commit c666b11

15 files changed

+2505
-88
lines changed

hooks/pre-commit

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#!/bin/bash
2+
3+
# Pre-commit hook to clean whitespace
4+
# This script will clean whitespace and include it in the commit
5+
6+
set -e
7+
8+
echo "🔍 Running pre-commit checks..."
9+
10+
# Colors for output
11+
RED='\033[0;31m'
12+
GREEN='\033[0;32m'
13+
YELLOW='\033[1;33m'
14+
BLUE='\033[0;34m'
15+
NC='\033[0m' # No Color
16+
17+
# Function to print colored output
18+
print_error() {
19+
echo -e "${RED}$1${NC}"
20+
}
21+
22+
print_success() {
23+
echo -e "${GREEN}$1${NC}"
24+
}
25+
26+
print_warning() {
27+
echo -e "${YELLOW}⚠️ $1${NC}"
28+
}
29+
30+
print_info() {
31+
echo -e "${BLUE}ℹ️ $1${NC}"
32+
}
33+
34+
# Check if we're in the right directory
35+
if [ ! -f "action.yml" ] || [ ! -d "src" ]; then
36+
print_error "This doesn't appear to be the contrast-ai-smartfix-action repository root"
37+
exit 1
38+
fi
39+
40+
# Clean trailing whitespace from staged files
41+
echo ""
42+
print_info "Cleaning trailing whitespace from staged files..."
43+
44+
# Get list of staged files
45+
STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM)
46+
47+
if [ -n "$STAGED_FILES" ]; then
48+
echo "📁 Processing staged files:"
49+
echo "$STAGED_FILES" | sed 's/^/ /'
50+
51+
WHITESPACE_CLEANED=false
52+
53+
# Apply sed command to each staged file
54+
for file in $STAGED_FILES; do
55+
if [ -f "$file" ]; then
56+
echo " 🧹 Cleaning whitespace in: $file"
57+
# Clean trailing whitespace
58+
sed -i '' 's/[[:space:]]*$//' "$file"
59+
# Re-stage the file with cleaned whitespace
60+
git add "$file"
61+
WHITESPACE_CLEANED=true
62+
fi
63+
done
64+
65+
if [ "$WHITESPACE_CLEANED" = true ]; then
66+
print_success "Whitespace cleanup completed and re-staged!"
67+
else
68+
print_info "No files needed whitespace cleanup"
69+
fi
70+
else
71+
print_info "No staged files detected for whitespace cleanup"
72+
fi
73+
74+
echo ""
75+
print_success "All pre-commit checks completed successfully!"
76+
echo "✨ Commit proceeding..."

hooks/pre-push

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
#!/bin/bash
2+
3+
# Pre-push hook to run Python linting
4+
# This script will block the push if linting fails
5+
6+
set -e
7+
8+
echo "🔍 Running pre-push checks..."
9+
10+
# Colors for output
11+
RED='\033[0;31m'
12+
GREEN='\033[0;32m'
13+
YELLOW='\033[1;33m'
14+
BLUE='\033[0;34m'
15+
NC='\033[0m' # No Color
16+
17+
# Function to print colored output
18+
print_error() {
19+
echo -e "${RED}$1${NC}"
20+
}
21+
22+
print_success() {
23+
echo -e "${GREEN}$1${NC}"
24+
}
25+
26+
print_warning() {
27+
echo -e "${YELLOW}⚠️ $1${NC}"
28+
}
29+
30+
print_info() {
31+
echo -e "${BLUE}ℹ️ $1${NC}"
32+
}
33+
34+
# Check if we're in the right directory
35+
if [ ! -f "action.yml" ] || [ ! -d "src" ]; then
36+
print_error "This doesn't appear to be the contrast-ai-smartfix-action repository root"
37+
exit 1
38+
fi
39+
40+
# Run Python linting
41+
echo ""
42+
print_info "Running Python linter..."
43+
44+
# Check if flake8 is installed, if not try to install it
45+
if ! command -v flake8 &> /dev/null; then
46+
print_warning "flake8 not found. Attempting to install..."
47+
if command -v pip &> /dev/null; then
48+
pip install flake8
49+
elif command -v pip3 &> /dev/null; then
50+
pip3 install flake8
51+
else
52+
print_error "Neither pip nor pip3 found. Please install flake8 manually:"
53+
print_error "pip install flake8"
54+
exit 1
55+
fi
56+
fi
57+
58+
# Find all Python files in src/ and test/ directories
59+
PYTHON_FILES=$(find src/ test/ -name "*.py" 2>/dev/null || true)
60+
61+
if [ -z "$PYTHON_FILES" ]; then
62+
print_warning "No Python files found in src/ or test/ directories"
63+
exit 0
64+
fi
65+
66+
echo "📁 Found Python files:"
67+
echo "$PYTHON_FILES" | sed 's/^/ /'
68+
69+
# Run flake8 on the Python files
70+
echo ""
71+
echo "🧹 Running flake8 linter..."
72+
73+
if flake8 $PYTHON_FILES; then
74+
print_success "All Python files passed linting!"
75+
echo ""
76+
print_success "Pre-push linting check completed successfully!"
77+
echo "🚀 Push proceeding..."
78+
exit 0
79+
else
80+
echo ""
81+
print_error "Linting failed! Push blocked."
82+
echo ""
83+
echo "💡 To fix linting issues:"
84+
echo " 1. Review the errors above"
85+
echo " 2. Fix the issues in your code"
86+
echo " 3. Commit your fixes"
87+
echo " 4. Try pushing again"
88+
echo ""
89+
echo "🔧 To skip all pre-push checks (not recommended):"
90+
echo " git push --no-verify"
91+
echo ""
92+
exit 1
93+
fi

0 commit comments

Comments
 (0)