From 63be0f3aeca521ca79a0b1bcfb99294e6ac58b87 Mon Sep 17 00:00:00 2001 From: Zhihe Li Date: Tue, 24 Oct 2023 13:07:27 -0400 Subject: [PATCH] =?UTF-8?q?chore:=20=F0=9F=A4=96=20Update=20commitizen=20h?= =?UTF-8?q?ook=20to=20add=20jira=20link=20automatically=20(#1959)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .husky/prepare-commit-msg | 15 +++++++++++++-- changelog.config.js | 3 +++ 2 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 changelog.config.js diff --git a/.husky/prepare-commit-msg b/.husky/prepare-commit-msg index 6be3600db..eeeb456d8 100755 --- a/.husky/prepare-commit-msg +++ b/.husky/prepare-commit-msg @@ -6,11 +6,22 @@ COMMIT_SOURCE=$2 SHA1=$3 # Gets the current branch name but if we're in a detached head state, return "HEAD" BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD) +# Regex to match the ICU-#### branch name pattern we use +ISSUE_REGEX="^(ICU-[0-9]+)" # Don't run commitizen for merge or squash commits, as well as when rebasing if [ "${COMMIT_SOURCE}" = merge ] || [ "${COMMIT_SOURCE}" = squash ] || [ "${COMMIT_SOURCE}" = "message" -a "${BRANCH_NAME}" = "HEAD" ];then exit 0 fi -# This is to allow interaction with the terminal for commitizen -exec < /dev/tty && npx git-cz --hook || true +# If the branch name matches, set the JIRA link automatically +if [[ $BRANCH_NAME =~ $ISSUE_REGEX ]] +then + issue="${BASH_REMATCH[1]}" + url="https://hashicorp.atlassian.net/browse/${issue}" + exec < /dev/tty && npx git-cz --issues="$url" --hook || true +else + # This is to allow interaction with the terminal for commitizen + exec < /dev/tty && npx git-cz --hook || true +fi + diff --git a/changelog.config.js b/changelog.config.js new file mode 100644 index 000000000..f04cb7225 --- /dev/null +++ b/changelog.config.js @@ -0,0 +1,3 @@ +module.exports = { + questions: ["type", "subject", "body", "issues"], +};