-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bfad98b
commit 01c848a
Showing
5 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.githooks/* eol=lf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[core] | ||
hooksPath = .githooks | ||
autocrlf = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#!/bin/bash | ||
#set -x | ||
########################################################## | ||
# Validates the commit message with the following rules: # | ||
# 1. The message cannot be empty # | ||
# 2. In dev branch, the format must follow the standard # | ||
# 3. In main branch, the related JIRA issue needs to be # | ||
# mentioned before the standard message format # | ||
########################################################## | ||
|
||
# shopt -s nocasematch # Case insensitive Cases | ||
COMMIT_MSG_FILE=$1 # Recieve the commit message .git/COMMIT_EDITMSG | ||
|
||
if [[ -z $(grep '[^[:space:]]' $COMMIT_MSG_FILE) ]] ; then | ||
echo "Empty commit message is not allowed" >&2 | ||
exit 1 | ||
fi | ||
|
||
DEV_BRANCH="dev" | ||
MAIN_BRANCH="main" | ||
|
||
current_branch="$(git rev-parse --abbrev-ref HEAD)" | ||
|
||
case "$current_branch" in | ||
$DEV_BRANCH) | ||
error_msg="Aborting commit. Please use the following format: <Imperative verb> <short description of change>" | ||
commit_regex_string="^(Add|Change|Remove|Fix|Update|Bump|Merge) [A-Za-z0-9 \/\'\,\._-]+$" | ||
;; | ||
|
||
$MAIN_BRANCH) | ||
error_msg="Aborting commit. Please prefix JIRA issue (NLNN-XXXX) and a verb (Add|Change|Remove|Fix|Update|Bump|Merge) to the commit message." | ||
commit_regex_string="^NLNN-[0-9]+ (Add|Change|Remove|Fix|Update|Bump|Merge) [A-Za-z0-9 \/\'\,\._-]+$" | ||
;; | ||
|
||
\ | ||
*) | ||
error_msg="Aborting commit. Please prefix JIRA issue (NLNN-XXXX) and a verb (Add|Change|Remove|Fix|Update|Bump|Merge) to the commit message." | ||
commit_regex_string="^NLNN-[0-9]+ (Add|Change|Remove|Fix|Update|Bump|Merge) [A-Za-z0-9 \/\'\,\._-]+$" | ||
# echo "Unhandled branch value $current_branch" | ||
# exit 1 | ||
;; | ||
esac | ||
|
||
COMMIT_MSG=$(cat ${COMMIT_MSG_FILE}) | ||
if [[ ! $COMMIT_MSG =~ $commit_regex_string ]]; then | ||
echo "$error_msg" | ||
exit 1 | ||
fi | ||
|
||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/bin/bash | ||
#set -x | ||
########################################################### | ||
# Validates the branch name with the following rules: # | ||
# 1. It starts with feature/NLNN-<4 digits>-<any message> # | ||
# 2. Or bugfix/NLNN-<4 digits>-<any message> # | ||
########################################################### | ||
|
||
local_branch="$(git rev-parse --abbrev-ref HEAD)" | ||
|
||
# valid_branch_regex="^(feature|bugfix|improvement|library|prerelease|release|hotfix)\/[a-z0-9._-]+$" | ||
valid_branch_regex="^(feature|bugfix)\/NLNN-[0-9]+-[A-Za-z0-9-]+$" | ||
|
||
message="There is something wrong with your branch name. Branch names in this project must adhere to this contract: $valid_branch_regex. Your commit will be rejected. You should rename your branch to a valid name and try again." | ||
|
||
if [[ ! $local_branch =~ $valid_branch_regex ]]; then | ||
echo "$message" | ||
exit 1 | ||
fi | ||
|
||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/bin/bash | ||
#set -x | ||
###################################################### | ||
# Prepends NLNN-<issue number> to the commit message # | ||
###################################################### | ||
|
||
ISSUE_NUMBER_REGEX="feature\/NLNN-([0-9]+)" | ||
|
||
if [[ $(git branch --show-current) =~ $ISSUE_NUMBER_REGEX ]]; then | ||
issue_number=$(echo ${BASH_REMATCH[1]}) | ||
echo "NLNN-$issue_number $(cat $1)" > $1 | ||
fi | ||
|
||
exit 0 |