@ministryofjustice/hmpps-precommit-hooks 0.0.1-alpha.4 → 0.0.2

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Change log
2
2
 
3
+ ## 0.0.2
4
+
5
+ Fix issue with alpine not having bash installed.
6
+ Also providing ability to disable running script inside docker
7
+
8
+ ## 0.0.1
9
+
10
+ Initial release
3
11
 
4
12
  ## 0.0.1-alpha.1
5
13
 
package/README.md CHANGED
@@ -4,7 +4,8 @@ This package aims to automatically install and configure husky with gitleaks to
4
4
 
5
5
  ## Status
6
6
 
7
- This library is in alpha. Teams are free to use this library but further breaking changes may occur.
7
+ **This library is currently: ready to adopt.**
8
+ Teams are welcome to use this library. Please provide feedback via slack to the `#typescript` channel.
8
9
 
9
10
  ## Migrating existing projects
10
11
 
@@ -44,6 +45,10 @@ The prepare script will trigger on any install and ensure that `gitleaks` is ins
44
45
 
45
46
  Note: `gitleaks` is installed by `brew`, if `brew` is not available then `prepare` will currently fail loudly and display a message.
46
47
 
48
+ ### Prevent precommit script initialising on prepare
49
+
50
+ To disable the tool running on `npm install` and initialising husky and installing gitleaks, you can pass the `SKIP_PRECOMMIT_INIT=true` env var.
51
+
47
52
  ### Dealing with false positives
48
53
 
49
54
  When a secret is detected, gitleaks will create a fingerprint. If the secret is a false positive then this can be added to the `./gitleaks/.gitleaksignore` to exclude from future scans.
package/bin/init.sh CHANGED
@@ -6,11 +6,11 @@
6
6
  set -euo pipefail
7
7
 
8
8
  startStage() {
9
- printf "\x1b[1;97m%s\x1b[0m" "$1"
9
+ printf "%s" "$1"
10
10
  }
11
11
 
12
12
  endStage() {
13
- printf "\x1b[1;97m%s\x1b[0m\n" "$1"
13
+ printf "%s\n" "$1"
14
14
  }
15
15
 
16
16
  printError() {
@@ -18,7 +18,6 @@ printError() {
18
18
  }
19
19
 
20
20
  endStage "Setting up precommit hooks"
21
- endStage "Checking prerequisites..."
22
21
 
23
22
  if ! [ -f ./package.json ]; then
24
23
  printError "Not a node project: $(pwd)! exiting!"
@@ -45,8 +44,6 @@ else
45
44
  npm --silent install
46
45
  fi
47
46
 
48
- endStage "Installing precommit hooks..."
49
-
50
47
  startStage " * Adding npm scripts"
51
48
  npm pkg --silent set scripts.precommit:secrets="gitleaks git --pre-commit --redact --staged --verbose --config .gitleaks/config.toml"
52
49
  npm pkg --silent set scripts.precommit:lint="node_modules/.bin/lint-staged"
package/bin/prepare.sh CHANGED
@@ -1,4 +1,4 @@
1
- #!/bin/bash
1
+ #!/bin/sh
2
2
  #
3
3
  # This runs as part of any `npm install` via `prepare`
4
4
  #
@@ -6,19 +6,19 @@
6
6
  set -eo pipefail
7
7
 
8
8
  startStage() {
9
- printf "\x1b[1;97m%s\x1b[0m" "$1"
9
+ printf "%s" "$1"
10
10
  }
11
11
 
12
12
  endStage() {
13
- printf "\x1b[1;97m%s\x1b[0m\n" "$1"
13
+ printf "%s\n" "$1"
14
14
  }
15
15
 
16
16
  printError() {
17
17
  printf "\x1b[1;31m%s\x1b[0m\n" "$1"
18
18
  }
19
19
 
20
- if [ "$CI" = "true" ]; then
21
- endStage "Not initialising precommit hooks in CI..."
20
+ if [ "$CI" = "true" ] || [ "$SKIP_PRECOMMIT_INIT" = "true" ]; then
21
+ endStage "Not initialising precommit hooks..."
22
22
  exit 0
23
23
  fi
24
24
 
@@ -26,15 +26,14 @@ fi
26
26
  node_modules/.bin/husky
27
27
 
28
28
  # Check brew exists
29
- if ! command -v brew &> /dev/null; then
30
- printError "Brew is not installed, WARNING: no precommit hook protection. exiting..."
29
+ if ! command -v brew > /dev/null 2> /dev/null; then
30
+ printError "Brew is not installed. You will need to install gitleaks separately and ensure it's on your PATH. exiting..."
31
31
  exit 0
32
32
  fi
33
33
 
34
34
  # Initialise gitleaks
35
- if ! command -v gitleaks &> /dev/null; then
35
+ if ! command -v gitleaks > /dev/null 2> /dev/null; then
36
36
  startStage "Installing gitleaks"
37
37
  brew install gitleaks
38
38
  endStage " ✅ "
39
39
  fi
40
-
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ministryofjustice/hmpps-precommit-hooks",
3
- "version": "0.0.1-alpha.4",
3
+ "version": "0.0.2",
4
4
  "description": "Precommit hooks for HMPPS typescript projects",
5
5
  "keywords": [
6
6
  "precommit"
@@ -17,6 +17,9 @@
17
17
  "hmpps-precommit-hooks-prepare": "./bin/prepare.sh",
18
18
  "test-secret-protection": "./bin/test.sh"
19
19
  },
20
+ "scripts": {
21
+ "check-for-updates": "npx npm-check-updates -u"
22
+ },
20
23
  "files": [
21
24
  "*.md",
22
25
  "bin/*.sh",