LoginSignup
16
16

More than 5 years have passed since last update.

自動でコミットメッセージに絵文字を付け加える

Last updated at Posted at 2015-08-19

前同僚がやってて可愛かったので絵文字を自動で付け加える様に

.git/hooks/prepare-commit-msg
#!/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

参考
Gitのコミットメッセージを絵文字から始める - Qiita
atom/CONTRIBUTING.md at master · atom/atom

16
16
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
16
16