Created
August 18, 2015 13:06
-
-
Save iberianpig/f010cfa1134bc19e3989 to your computer and use it in GitHub Desktop.
IssueID_xxxxなブランチ名の時に自動でコミットメッセージの先頭に[#IssueID]を付与するrubyスクリプト
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/env ruby | |
message_file = ARGV[0] | |
message = File.read(message_file, :encoding => Encoding::UTF_8) | |
# remove prefix issue number like [#1234] from COMMIT_EDITMSG | |
message = message.sub(/^\[#[0-9A-Za-z_].*\]/, "") | |
# remove comment | |
message = message.gsub(/^#(?! ------------------------ >8 ------------------------).*\n|^\n/, "") | |
if message =~ /(?=\A)# ------------------------ >8 ------------------------\n/ | |
puts "An empty message aborts the commit." | |
exit 1 | |
end | |
# get number([#1234]) from branch(1234_foobar) | |
number = `git branch | grep "*"`.sub(/^\*\s/, "").sub(/^([0-9]*)_\w.*$/,'\1').chomp! | |
# add [#1234] to commit message | |
newmessage = "[##{number}]#{message}" | |
File.write(message_file, newmessage) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment