LoginSignup
16
16

More than 5 years have passed since last update.

gitのブランチとgithubのissueを結びつける

Posted at

gitのブランチ名とgithubのissueを結びつける.

以下の内容で.git/hooks/commit-msgを作る.

commit-msg
#!/bin/bash

BRANCH=$(git symbolic-ref HEAD)

grep '^refs #[0-9]\+: ' $1
if [ $? -eq 0 ]; then
  exit
fi

ISSUE=$(echo $BRANCH | sed -e 's/^.*-id-\([0-9]*\)$/#\1/')
if [ "$ISSUE" != "$BRANCH" ]; then
  echo "Auto append: $ISSUE"
  mv $1 $1.$$
  echo -n "$ISSUE: " > $1
  cat $1.$$ >> $1
  rm $1.$$
fi

忘れずに実行権限をつける

chmod +x commit-msg

gitのブランチ名をhogehoge-fugafuga-id-1のように一番後ろにid-チケット番号にしておいて、マージすると、#チケット番号が自動的に付与される

16
16
3

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
16
16