secure-husky-setup 1.0.6 → 1.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/lib/hooks.js +21 -12
  2. package/package.json +2 -4
package/lib/hooks.js CHANGED
@@ -91,19 +91,28 @@ else
91
91
  if [ ! -f "sonar-project.properties" ]; then
92
92
  echo "[SonarQube] sonar-project.properties not found. Skipping."
93
93
  else
94
- SONAR_INCLUSIONS=$(echo "$STAGED_FILES" | tr '\n' ',' | sed 's/,$//')
95
- echo "[SonarQube] Scanning: $SONAR_INCLUSIONS"
96
-
97
- $SONAR_BIN -Dsonar.inclusions="$SONAR_INCLUSIONS" -Dsonar.qualitygate.wait=true
98
- SONAR_EXIT=$?
99
-
100
- if [ $SONAR_EXIT -ne 0 ]; then
101
- echo "[SonarQube] Quality Gate FAILED. Commit blocked."
102
- echo "[SonarQube] Fix the issues at: $(grep 'sonar.host.url' sonar-project.properties | cut -d'=' -f2)/dashboard?id=$(grep 'sonar.projectKey' sonar-project.properties | cut -d'=' -f2)"
103
- exit 1
94
+ SONAR_HOST=$(grep "^sonar.host.url=" sonar-project.properties | cut -d'=' -f2 | tr -d '[:space:]')
95
+ SONAR_DOMAIN=$(echo "$SONAR_HOST" | sed 's|https://||' | sed 's|http://||' | cut -d'/' -f1 | cut -d':' -f1)
96
+ SONAR_PORT=$(echo "$SONAR_HOST" | grep -o ':[0-9]*$' | tr -d ':')
97
+ SONAR_PORT=\${SONAR_PORT:-9000}
98
+
99
+ if ! nc -z -w3 "$SONAR_DOMAIN" "$SONAR_PORT" 2>/dev/null; then
100
+ echo "[SonarQube] Server unreachable skipping analysis."
101
+ else
102
+ SONAR_INCLUSIONS=$(echo "$STAGED_FILES" | tr '\n' ',' | sed 's/,$//')
103
+ echo "[SonarQube] Scanning: $SONAR_INCLUSIONS"
104
+
105
+ $SONAR_BIN -Dsonar.inclusions="$SONAR_INCLUSIONS" -Dsonar.qualitygate.wait=true
106
+ SONAR_EXIT=$?
107
+
108
+ if [ $SONAR_EXIT -ne 0 ]; then
109
+ echo "[SonarQube] Quality Gate FAILED. Commit blocked."
110
+ echo "[SonarQube] Fix issues at: $SONAR_HOST/dashboard?id=$(grep 'sonar.projectKey' sonar-project.properties | cut -d'=' -f2)"
111
+ exit 1
112
+ fi
113
+
114
+ echo "[SonarQube] Quality Gate PASSED. ✔"
104
115
  fi
105
-
106
- echo "[SonarQube] Quality Gate PASSED. ✔"
107
116
  fi
108
117
  fi
109
118
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "secure-husky-setup",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "description": "Automatic Husky + Gitleaks setup for any JS project",
5
5
  "main": "bin/index.js",
6
6
  "bin": {
@@ -25,7 +25,5 @@
25
25
  "fs-extra": "^11.3.3",
26
26
  "sonarqube-scanner": "^4.0.0"
27
27
  },
28
- "scripts": {
29
- "postinstall": "node bin/index.js init"
30
- }
28
+ "scripts": {}
31
29
  }