-
-
Save matsubo/a6976c781e56a0c1ba44daca1cee738d 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 "*"`[/\d+/].to_i | |
# add [#1234] to commit message | |
if 0 < number | |
message = "[##{number}] #{message}" | |
end | |
File.write(message_file, message) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment