Skip to content

Instantly share code, notes, and snippets.

@KenshoFujisaki
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KenshoFujisaki/77c62e97376e1306f3dc to your computer and use it in GitHub Desktop.
Save KenshoFujisaki/77c62e97376e1306f3dc to your computer and use it in GitHub Desktop.
ローカルフックスクリプト:トピックブランチのチケット番号とコミットログのチケット番号の一致チェック
#!/usr/bin/ruby
require "readline"
message_file = ARGV[0]
message = File.read(message_file)
# コミットメッセージ確認
regex_matches = /^#(\d+)/.match(message)
unless regex_matches
puts "\n[警告] コミットメッセージにチケット番号が含まれていません。"
puts '例)$ git commit -m "#XXXX detail message"'
exit 1
end
message_ticket_no = regex_matches[1]
# コミット先ブランチ名確認
current_branch_name = `git rev-parse --abbrev-ref HEAD`.chomp
regex_matches = /(feature|bugfix|refactoring)(|_.*)\/(\d+)/.match(current_branch_name)
# ブランチ名確認
unless regex_matches
puts "\n[警告] ブランチ名が不適切です。それでもコミットしますか? [Y/N]"
STDIN.reopen('/dev/tty')
input = Readline.readline
unless input == "Y"
puts "aborted"
exit 1
end
end
# チケット番号が異なる場合、警告
branch_ticket_no = regex_matches ? regex_matches[3] : current_branch_name
unless message_ticket_no == branch_ticket_no
puts "\n[警告] コミットメッセージの##{message_ticket_no} と " +
"ブランチ名の##{branch_ticket_no} のチケット番号が一致しません。" +
"それでもコミットしますか? [Y/N]"
STDIN.reopen('/dev/tty')
input = Readline.readline
unless input == "Y"
puts "aborted"
exit 1
end
end
@KenshoFujisaki
Copy link
Author

.git/hooks/commit-msg を追加

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment