Skip to content

Commit

Permalink
[TNT-69] chore: commit 접두사 관련 Git hook 구현
Browse files Browse the repository at this point in the history
* command : sh script/setup_prepare_commit_msg.sh
  • Loading branch information
hoyahozz committed Jan 3, 2025
1 parent 5a1eeeb commit 263b22c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
18 changes: 18 additions & 0 deletions script/prepare_commit_msg_script
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
22 changes: 22 additions & 0 deletions script/setup_prepare_commit_msg.sh
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")"

0 comments on commit 263b22c

Please sign in to comment.