Skip to content

Commit

Permalink
settings: GitHook設定 - fixとIssue番号抽出(#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
h-yoshikawa44 committed Sep 16, 2023
1 parent afabec4 commit 9ac6cbd
Show file tree
Hide file tree
Showing 4 changed files with 607 additions and 35 deletions.
31 changes: 31 additions & 0 deletions .githooks/prepare-commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/sh

# sed コマンドが GNU か BSD か確認
GNU_SED=true
sed --version 1>/dev/null 2>/dev/null || GNU_SED=false
echo $GNU_SED

# コミットメッセージ入力前に、ブランチ名から Issue 番号を抽出して置換する
COMMIT_MSG_FILE=$1
MESSAGE=$(cat "$COMMIT_MSG_FILE")

ISSUE_NUMBER=$(git rev-parse --abbrev-ref HEAD | grep -Eo "^(feature|bugfix|release)/[0-9]+" | grep -Eo "[0-9]+")
if [ -n "$ISSUE_NUMBER" ]; then
if [ "$GNU_SED" == "true" ]; then
sed -i "s/(#Issue)/(#$ISSUE_NUMBER)/" $COMMIT_MSG_FILE
else
sed -i "" "s/(#Issue)/(#$ISSUE_NUMBER)/" $COMMIT_MSG_FILE
fi
exit 0
fi

read -p "Issue 番号がブランチ名にないので置換できませんが、続行しますか? (y/N): " YM < /dev/tty
case "$YM" in
[yY]*)
if [ "$GNU_SED" == "true" ]; then
sed -i "s/(#Issue)//" $COMMIT_MSG_FILE
else
sed -i "" "s/(#Issue)//" $COMMIT_MSG_FILE
fi;;
*) echo "abort." ; exit 1 ;;
esac
2 changes: 1 addition & 1 deletion .gitmessage
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
: (#)
: (#Issue)

# ==== Type ====
# feat: 機能追加
Expand Down
Loading

0 comments on commit 9ac6cbd

Please sign in to comment.