-
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.
[TNT-69] chore: commit 접두사 관련 Git hook 구현
* command : sh script/setup_prepare_commit_msg.sh
- Loading branch information
Showing
2 changed files
with
40 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,18 @@ | ||
#!/bin/sh | ||
|
||
# Extract the current branch name | ||
BRANCH_NAME=$(git symbolic-ref --short HEAD) | ||
|
||
# Identify the JIRA ticket number from the branch name (e.g., "TICKET-231") | ||
JIRA_TICKET=$(echo "$BRANCH_NAME" | grep -oE '[A-Z]+-[0-9]+') | ||
|
||
# Prepend the JIRA ticket to the commit message if found | ||
if [ ! -z "$JIRA_TICKET" ]; then | ||
COMMIT_MSG=$(cat "$1") | ||
# Check if the message already starts with a ticket pattern like [SB-...] | ||
# shellcheck disable=SC2039 | ||
if [[ ! "$COMMIT_MSG" =~ ^\[[A-Z]+-[0-9]+\] ]]; then | ||
# Format the ticket as [TICKET-231] and prepend it | ||
echo "[$JIRA_TICKET] $COMMIT_MSG" > "$1" | ||
fi | ||
fi |
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,22 @@ | ||
#!/usr/bin/env bash | ||
|
||
CURRENT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) | ||
GIT_HOOK_DIR="$CURRENT_DIR/../.git/hooks" | ||
PREPARE_COMMIT_MSG_SCRIPT="$CURRENT_DIR/prepare_commit_msg_script" | ||
PREPARE_COMMIT_MSG_TARGET_FILE="$GIT_HOOK_DIR/prepare-commit-msg" | ||
|
||
|
||
# Prepare commit msg Hook 추가 (지라 티켓명 자동 추가) | ||
if [[ ! -f "$PREPARE_COMMIT_MSG_SCRIPT" ]] | ||
then | ||
echo "Error: Prepare commit msg hook script not found at $PREPARE_COMMIT_MSG_SCRIPT" | ||
exit 1 | ||
fi | ||
|
||
cat "$PREPARE_COMMIT_MSG_SCRIPT" > "$PREPARE_COMMIT_MSG_TARGET_FILE" | ||
chmod +x "$PREPARE_COMMIT_MSG_TARGET_FILE" | ||
|
||
echo "************************************************" | ||
echo " Prepare commit msg hook installed " | ||
echo "************************************************" | ||
echo "Install path: $(ls "$GIT_HOOK_DIR")" |