-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This script searches for task number in branch name and puts it to the end of the commit message MOB-1651
- Loading branch information
Egor Egorov
authored and
github-review-helper
committed
Nov 29, 2022
1 parent
e3f5d0d
commit 1fc37c5
Showing
1 changed file
with
26 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,26 @@ | ||
#!/bin/bash | ||
|
||
# | ||
# Inspects branch name and checks if it contains a Jira ticket number (i.e. MOB-1234). | ||
# If yes, [MOB-123] will be added in the end of a commit message. | ||
# | ||
|
||
BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD 2>/dev/null) | ||
|
||
# Ensure BRANCH_NAME is not empty and is not in a detached HEAD state (i.e. rebase). | ||
if [ ! -z "$BRANCH_NAME" ] && [ "$BRANCH_NAME" != "HEAD" ] && [ "$SHOULD_PREPARE_COMMIT_MSG" == 1 ]; then | ||
|
||
SUFFIX_PATTERN='MOB-[0-9]{4,5}' | ||
|
||
[[ $BRANCH_NAME =~ $SUFFIX_PATTERN ]] | ||
|
||
SUFFIX=${BASH_REMATCH[0]} | ||
|
||
SUFFIX_IN_COMMIT=$(grep -c "\[$SUFFIX\]" $1) | ||
|
||
# Ensure SUFFIX exists in BRANCH_NAME and is not already present in the commit message | ||
if [[ -n "$SUFFIX" ]] && ! [[ $SUFFIX_IN_COMMIT -ge 1 ]]; then | ||
echo "" >>$1 | ||
echo "$SUFFIX" >>$1 | ||
fi | ||
fi |