From 9e9128f6f00df78de65dd476765e80fc5e0569d4 Mon Sep 17 00:00:00 2001 From: George Xu <33054982+georgexu99@users.noreply.github.com> Date: Mon, 21 Nov 2022 13:14:47 -0800 Subject: [PATCH] chore: add husky pre-push script (#3061) * chore: add husky pre-push script * skip pre-push on windows * change to node script * add inquirer as devdependency * add inquirer as devdependency --- .husky/pre-push | 9 +++++++++ .husky/pre-push.js | 14 ++++++++++++++ package.json | 1 + yarn.lock | 2 +- 4 files changed, 25 insertions(+), 1 deletion(-) create mode 100755 .husky/pre-push create mode 100644 .husky/pre-push.js diff --git a/.husky/pre-push b/.husky/pre-push new file mode 100755 index 0000000000..d5af4f6c64 --- /dev/null +++ b/.husky/pre-push @@ -0,0 +1,9 @@ +#!/bin/sh +. "$(dirname "$0")/_/husky.sh" + +BRANCH=`git rev-parse --abbrev-ref HEAD` +PROTECTED_BRANCH="main" + +if [ "$BRANCH" = $PROTECTED_BRANCH ]; then + node .husky/pre-push.js < /dev/tty +fi diff --git a/.husky/pre-push.js b/.husky/pre-push.js new file mode 100644 index 0000000000..215d04ef3a --- /dev/null +++ b/.husky/pre-push.js @@ -0,0 +1,14 @@ +const inquirer = require('inquirer'); + +const question = [ + { + type: 'confirm', + name: 'continuePush', + message: '[pre-push hook] Warning: this is a protected branch. Continue?', + }, +]; + +inquirer.prompt(question).then((answer) => { + if (!answer.continuePush) process.exit(1); + process.exit(0); +}); diff --git a/package.json b/package.json index d78b6dfbba..4a2945be3a 100644 --- a/package.json +++ b/package.json @@ -123,6 +123,7 @@ "fork-ts-checker-webpack-plugin": "^7.2.13", "generate-changelog": "^1.8.0", "husky": "^7.0.1", + "inquirer": "^8.0.0", "lerna": "^6.0.1", "lint-staged": "^12.1.7", "listr2": "^4.0.4", diff --git a/yarn.lock b/yarn.lock index 024ffae10f..0b32ff7b7b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7106,7 +7106,7 @@ inquirer@^6.2.0: strip-ansi "^5.1.0" through "^2.3.6" -inquirer@^8.2.4: +inquirer@^8.0.0, inquirer@^8.2.4: version "8.2.5" resolved "https://registry.yarnpkg.com/inquirer/-/inquirer-8.2.5.tgz#d8654a7542c35a9b9e069d27e2df4858784d54f8" integrity sha512-QAgPDQMEgrDssk1XiwwHoOGYF9BAbUcc1+j+FhEvaOt8/cKRqyLn0U5qA6F74fGhTMGxf92pOvPBeh29jQJDTQ==