LoginSignup
3
1

More than 5 years have passed since last update.

JIRAの issue id を gitのコミットメッセージに含める

Posted at

やりたいこと

  • コミットログを見た時に、どの問題の修正なのかを把握したい。
  • JIRAの issue id があると分かりやすいのでコミットメッセージに含めておきたい
  • ブランチ名に issue id が含まれていたら その issue id をコミットメッセージに含めるようにしておく

やること

  • branch 切る時に issue id を含めるようにする

    • DEV-1101-fix-hoge みたいな感じ
  • 下記のファイルを .git/hooks/commit-msg として配置

  • chmod +x する。

# !/bin/sh
#
# .git/hooks/commit-msg
#


COMMIT_FILE=$1
COMMIT_MSG=$(cat $1)
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
JIRA_ID=$(echo "$CURRENT_BRANCH" | grep -Eo "[A-Z0-9]{1,10}-?[A-Z0-9]+-\d+")
MSG_WITHOUT_COMMENT=$(grep -v '^\s*#' $COMMIT_FILE |grep -v '^\s*$')

if [ -n "$JIRA_ID" -a -n "$MSG_WITHOUT_COMMENT" ]; then
    echo "[$JIRA_ID] $COMMIT_MSG" > $COMMIT_FILE
    echo "JIRA ID '$JIRA_ID', matched in current branch name, prepended to commit message. (Use --no-verify to skip)"
fi

コミットすると下記のようにissue id が挿入される。

[DEV-1101] Fix typo

引用元

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1