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

1590 git hooks bugs #1595

Merged
merged 6 commits into from
Jul 23, 2024
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
47 changes: 33 additions & 14 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
#!/bin/bash

# Function to get the full path of a command
get_command_path() {
command -v $1
}

## Set the root directory in the pipeline
ROOT_DIR=$(git rev-parse --show-toplevel)
CURRENT_DIR="${PWD##*/}"
Expand All @@ -13,17 +19,16 @@ STAGED_FILES=$(git diff-index --cached --name-only HEAD)

for file in $STAGED_FILES; do
# Check if file is located in the JS_APP_DIR
echo "Found stagged file: $file"
echo "Found staged file: $file"
if [[ $file == *$JS_APP_DIR* ]]; then
IS_JS_APP=true
fi
done

# run custom actions for our JS App
# Run custom actions for our JS App
if [ $IS_JS_APP = true ]; then
echo "Found a JS application file, running front end task(s)"
# echo "running processes on staged files"
cd $ROOT_DIR/$JS_APP_DIR && npm run lint-staged
cd $ROOT_DIR/$JS_APP_DIR && $(get_command_path npm) run lint-staged
if [ $? -eq 0 ]; then
echo "Process succeeded."
cd $ROOT_DIR
Expand All @@ -34,33 +39,44 @@ if [ $IS_JS_APP = true ]; then
fi

# Check if Python 3 is installed and install if not
if ! command -v python3 &> /dev/null; then
PYTHON3_PATH=$(get_command_path python3)
if [ -z "$PYTHON3_PATH" ]; then
echo "Python 3 is not installed. Attempting to install Python 3..."
brew install python3 || { echo "Failed to install Python 3. Please install it manually."; exit 1; }
$(get_command_path brew) install python3 || { echo "Failed to install Python 3. Please install it manually."; exit 1; }
PYTHON3_PATH=$(get_command_path python3)
fi

# Check if venv module is available in Python, install if not
if ! python3 -c "import venv" &> /dev/null; then
if ! $PYTHON3_PATH -c "import venv" &> /dev/null; then
echo "venv module is not available. Python installation might not support venv."
exit 1
fi

# Set up Python virtual environment
if [ ! -d ".venv" ]; then
python3 -m venv .venv
$PYTHON3_PATH -m venv .venv
echo "Virtual environment created."
else
echo "Virtual environment already exists."
fi
source .venv/bin/activate

# Check if TruffleHog3 is installed and install if not
if ! command -v trufflehog3 &> /dev/null; then
TRUFFLEHOG3_PATH=$(get_command_path trufflehog3)
if [ -z "$TRUFFLEHOG3_PATH" ]; then
echo "TruffleHog3 is not installed. Installing TruffleHog3..."
pip install trufflehog3 || { echo "Failed to install TruffleHog3. Please install it manually."; exit 1; }
$(get_command_path pip) install trufflehog3 || { echo "Failed to install TruffleHog3. Please install it manually."; exit 1; }
TRUFFLEHOG3_PATH=$(get_command_path trufflehog3)
fi

# Check if jq is installed and install if not
if ! command -v /opt/homebrew/bin/jq &> /dev/null; then
JQ_PATH=$(get_command_path jq)
if [ -z "$JQ_PATH" ]; then
echo "jq is not installed. Installing jq..."
brew install jq || { echo "Failed to install jq. Please install it manually."; exit 1; }
$(get_command_path brew) install jq || { echo "Failed to install jq. Please install it manually."; exit 1; }
JQ_PATH=$(get_command_path jq)
fi

# Determine the branch name locally
BRANCH_NAME=$(git symbolic-ref --short HEAD)
if [ -z "$BRANCH_NAME" ]; then
Expand All @@ -69,11 +85,13 @@ if [ -z "$BRANCH_NAME" ]; then
fi

echo "Scanning branch: $BRANCH_NAME"

# TruffleHog3 Scan on local branch files
trufflehog3 --no-history --no-entropy --severity MEDIUM -vv -r rules.yml --format json --output truffleHogResults.json || true
$TRUFFLEHOG3_PATH --no-history --no-entropy --severity MEDIUM -vv -r rules.yml --format json --output truffleHogResults.json || true

# Prepare for result checking
# Check for secrets in the results
CONTENT=$(/opt/homebrew/bin/jq 'length' $ROOT_DIR/truffleHogResults.json)
CONTENT=$($JQ_PATH 'length' $ROOT_DIR/truffleHogResults.json)
if [ "$CONTENT" -eq 0 ]; then
rm $ROOT_DIR/truffleHogResults.json
echo "No secrets found. Commit is safe."
Expand All @@ -83,3 +101,4 @@ else
echo "Please review and resolve issues."
exit 1
fi

2 changes: 0 additions & 2 deletions benefit-finder/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -334,5 +334,3 @@ npm run generate:component <component-name>
```

> It's important to export components from the root of the shared index file. This is where you will import and destructure across other documents.

test
Loading