From c783efc07aa34d5ca76e4d7dd4c158abdd017f61 Mon Sep 17 00:00:00 2001 From: scottqueen-bixal Date: Tue, 23 Jul 2024 15:40:06 -0400 Subject: [PATCH 1/6] PXBF-1590-git-hooks-bugs: remove test on readme --- benefit-finder/README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/benefit-finder/README.md b/benefit-finder/README.md index 3dee722bf..3a4a6290a 100644 --- a/benefit-finder/README.md +++ b/benefit-finder/README.md @@ -334,5 +334,3 @@ npm run generate:component ``` > 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 \ No newline at end of file From b830e4d05f65378eb75212a56a2e305072cc20fd Mon Sep 17 00:00:00 2001 From: scottqueen-bixal Date: Tue, 23 Jul 2024 15:42:25 -0400 Subject: [PATCH 2/6] PXBF-1590-git-hooks-bugs: remove test on readme --- benefit-finder/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/benefit-finder/README.md b/benefit-finder/README.md index 3a4a6290a..57c2404a4 100644 --- a/benefit-finder/README.md +++ b/benefit-finder/README.md @@ -1,4 +1,4 @@ -# Benefit Finder v2 React Application +# Benefit Finder v2 React Application TEST ```text /benefit-finder From 380cd92eebafb2d4a8073172bfdb0722c5d03af0 Mon Sep 17 00:00:00 2001 From: scottqueen-bixal Date: Tue, 23 Jul 2024 15:51:51 -0400 Subject: [PATCH 3/6] PXBF-1590-git-hooks-bugs: remove test on readme --- benefit-finder/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/benefit-finder/README.md b/benefit-finder/README.md index 57c2404a4..3a4a6290a 100644 --- a/benefit-finder/README.md +++ b/benefit-finder/README.md @@ -1,4 +1,4 @@ -# Benefit Finder v2 React Application TEST +# Benefit Finder v2 React Application ```text /benefit-finder From 724a6152138ef0833829b2846baa7737ff5d7cab Mon Sep 17 00:00:00 2001 From: scottqueen-bixal Date: Tue, 23 Jul 2024 15:54:28 -0400 Subject: [PATCH 4/6] PXBF-1590-git-hooks-bugs: test --- benefit-finder/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/benefit-finder/README.md b/benefit-finder/README.md index 3a4a6290a..57c2404a4 100644 --- a/benefit-finder/README.md +++ b/benefit-finder/README.md @@ -1,4 +1,4 @@ -# Benefit Finder v2 React Application +# Benefit Finder v2 React Application TEST ```text /benefit-finder From 2bfdc3ffb000b42e02d0519fb16dca6fb9fbed46 Mon Sep 17 00:00:00 2001 From: scottqueen-bixal Date: Tue, 23 Jul 2024 15:55:54 -0400 Subject: [PATCH 5/6] PXBF-1590-git-hooks-bugs: remove test --- benefit-finder/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/benefit-finder/README.md b/benefit-finder/README.md index 57c2404a4..3a4a6290a 100644 --- a/benefit-finder/README.md +++ b/benefit-finder/README.md @@ -1,4 +1,4 @@ -# Benefit Finder v2 React Application TEST +# Benefit Finder v2 React Application ```text /benefit-finder From b3aab122fa27e3d7bc499e8045104f1a788a2832 Mon Sep 17 00:00:00 2001 From: scottqueen-bixal Date: Tue, 23 Jul 2024 15:56:38 -0400 Subject: [PATCH 6/6] PXBF-1590-git-hooks-bugs: get path for command --- .githooks/pre-commit | 47 +++++++++++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/.githooks/pre-commit b/.githooks/pre-commit index 76c1869e9..51e3bcb00 100755 --- a/.githooks/pre-commit +++ b/.githooks/pre-commit @@ -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##*/}" @@ -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 @@ -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 @@ -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." @@ -83,3 +101,4 @@ else echo "Please review and resolve issues." exit 1 fi +