Last active
August 29, 2015 14:17
-
-
Save KenshoFujisaki/77c62e97376e1306f3dc to your computer and use it in GitHub Desktop.
ローカルフックスクリプト:トピックブランチのチケット番号とコミットログのチケット番号の一致チェック
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
.git/hooks/commit-msg を追加