Skip to content

Instantly share code, notes, and snippets.

@kosaki
Last active May 7, 2017 12:05
Show Gist options
  • Save kosaki/24a36b98253fabfd4b92 to your computer and use it in GitHub Desktop.
Save kosaki/24a36b98253fabfd4b92 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
require 'date'
changelog = nil
# find out ChangeLog file
diff = `git diff --stat HEAD`
diff.scan(/^ (ChangeLog) +\|/) { |ary|
changelog = ary[0]
}
# if no changelog, we don't need any modify
if changelog == nil then
exit 0
end
str = `git diff HEAD #{changelog}`
if str =~ /^\+(\w.*)$/ then
date_str = $1
end
# date_str example
# Fri Aug 15 10:13:37 2014 SHIBATA Hiroshi <shibata.hiroshi@gmail.com>
str =~ /.*\d\d:\d\d:\d\d \d\d\d\d (\w+(?: \w+)) +<(.+)>/
name = $1
email = $2
d = DateTime.now.new_offset(Rational(9,24))
replace = d.strftime("%a %b %e %H:%M:%S %Y") + " #{name} <#{email}>"
`sed -i -e "s/#{date_str}/#{replace}/" #{changelog}`
`git add #{changelog}`
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment