Last active
February 5, 2016 05:55
-
-
Save eccyan/2827fbb9922ff60556cc to your computer and use it in GitHub Desktop.
自動でコミットメッセージに絵文字を付け加える ref: http://qiita.com/eccyan/items/7514c2c2eb14aab8f63a
This file contains hidden or 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 | |
# :up: :up: when improving the format/structure of the code | |
# :hammer: :hammer: when refactoring the code | |
# :chart_with_upwards_trend: :chart_with_upwards_trend: when improving performance | |
# :memo: :memo: when writing docs | |
# :bug: :bug: when fixing a bug | |
# :fire: :fire: when removing code or files | |
# :green_heart: :green_heart: when fixing the CI build | |
# :white_check_mark: :white_check_mark: when adding tests | |
# :lock: :lock: when dealing with security | |
# :arrow_double_up: :arrow_double_up: when upgrading dependencies | |
# :arrow_double_down: :arrow_double_down: when downgrading dependencies | |
# :hatching_chick: :hatching_chick: when adding new features | |
EMOJIS = { | |
# up: [/Improve(?:s)? /i, /Update(?:s)? /i, /Replace(?:s)? /i, /Change(?:s)? /i, /Tweak(?:s)? /i], | |
hammer: [/Refactor(?:s)? /i, /Rename(?:s)? /i], | |
chart_with_upwards_trend: [/Tuneup(?:s)? /i], | |
memo: [/Write(?:s)? /i], | |
bug: [/Fix(?:es)? (?:(?!spec|linter|test))/i], | |
fire: [/Remove(?:s)? /i], | |
green_heart: [/Fix(?:es)? broken (?:spec|linter|test)(?:s)?/i], | |
white_check_mark: [/Add(?:s)? (?:spec|test)(?:s)? /i], | |
lock: [/Secure(?:s)? /i], | |
arrow_double_up: [/Upgrade(?:s)? /i], | |
arrow_double_down: [/Downgrade(?:s)? /i], | |
hatching_chick: [/Add(?:s)? (?:(?!spec|test))/i, /Create(?:s)? /i, /Introduce(?:s)? /i], | |
} | |
EXCLUDES = [ | |
/Merge/i, | |
] | |
commit_msgs = File.readlines(ARGV[0]) | |
commit_msgs[0] = commit_msgs.first.gsub(/:.+: /i, '') | |
unless Regexp.union(EXCLUDES).match(commit_msgs.first) | |
emoji = EMOJIS.map do |key, regex| | |
if Regexp.union(regex).match(commit_msgs.first) | |
":#{key}:" | |
end | |
end.compact.uniq.first || ':up:' | |
open(ARGV[0], 'w') do |file| | |
file.print "#{emoji} " | |
file.puts commit_msgs | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment