From 96fd07dd582086bbd03dbb75d1d9f6f2e5cf6fc5 Mon Sep 17 00:00:00 2001 From: Valentina Date: Tue, 10 Mar 2020 11:28:39 +0000 Subject: [PATCH] feature/VIH-5605 : added pre commit message hook --- .githooks/pre-commit | 4 ++-- .githooks/prepare-commit-msg | 29 +++++++++++++++++++++++++++++ README.md | 7 ++++++- 3 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 .githooks/prepare-commit-msg diff --git a/.githooks/pre-commit b/.githooks/pre-commit index e04c9416b..4768d6d35 100644 --- a/.githooks/pre-commit +++ b/.githooks/pre-commit @@ -3,9 +3,9 @@ LC_ALL=C local_branch="$(git rev-parse --abbrev-ref HEAD)" -valid_branch_regex="^(feature\/VIH-[0-9]{3})[a-zA-Z0-9._-]+$" +valid_branch_regex="^(feature\/VIH-[0-9]{4})[a-zA-Z0-9._-]+$" -message="There is something wrong with your branch name. Branch names in this project must start with feature/VIH-XXX. Your commit will be rejected. You should rename your branch to a valid name and try again." +message="There is something wrong with your branch name. Branch names in this project must start with feature/VIH-XXXX-anyNameOfBranch. Your commit will be rejected. You should rename your branch to a valid name and try again." if [[ ! $local_branch =~ $valid_branch_regex ]] then diff --git a/.githooks/prepare-commit-msg b/.githooks/prepare-commit-msg new file mode 100644 index 000000000..05849350b --- /dev/null +++ b/.githooks/prepare-commit-msg @@ -0,0 +1,29 @@ +#!/bin/sh + +COMMIT_MSG_FILE=$1 +COMMIT_SOURCE=$2 +SHA1=$3 + + +# Get the current branch name +BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD) +# exstract a part of branch name with the VIH-XXX + TRIMMED=$(echo $BRANCH_NAME | sed -e 's/.*\/*\(VIH-[0-9]\{4\}\).*/\1/') +# get the current commit message +currentmsg=$(cat "$COMMIT_MSG_FILE") +message="Commit message must start with the prefix 'feature/VIH-XXXX : ' folowing by 8 or more characters. Your commit will be rejected. You should rename your commit to a valid name and try again." +valid_mesg_regex="^(feature\/VIH-[0-9]{4} : )([:_, a-zA-Z0-9.-]{8,})+$" + +feature="feature/" + +if [[ ! $currentmsg =~ $valid_mesg_regex ]] +then + echo "$message" + exit 1 + fi + exit 0 +fi + + + + \ No newline at end of file diff --git a/README.md b/README.md index a431962fc..191f6d835 100644 --- a/README.md +++ b/README.md @@ -49,8 +49,13 @@ To turn on\off ZAP security scans individually such as Spider\AjaxSpider\ActiveS ##Branch name git hook will run on pre commit and control the standard for new branch name. -The branch name should start with: feature/VIH-XXX (X - is digit). +The branch name should start with: feature/VIH-XXXX-branchName (X - is digit). If git version is less than 2.9 the pre-commit file from the .githooks folder need copy to local .git/hooks folder. To change git hooks directory to directory under source control run (works only for git version 2.9 or greater) : $ git config core.hooksPath .githooks +##Commit message +The commit message will be validated by prepare-commit-msg hook. +The commit message format should start with : 'feature/VIH-XXXX : ' folowing by 8 or more characters description of commit, otherwise the warning message will be presented. + +