Skip to content

Instantly share code, notes, and snippets.

@kibitan
Created August 4, 2016 07:33
Show Gist options
  • Save kibitan/4cca027717b5c61403ecdae435579e89 to your computer and use it in GitHub Desktop.
Save kibitan/4cca027717b5c61403ecdae435579e89 to your computer and use it in GitHub Desktop.
.git/hooks/commit-msg: git commit hook that auto adding message of associating issue and rollbar error issue
#!/usr/bin/env ruby
current_branch = `git symbolic-ref --short HEAD`
if /^iss-(\d+).*/ =~ current_branch
commit_msgs = File.readlines(ARGV[0])
issue_id = $1
puts 'setup `ghi` command via https://github.com/stephencelis/ghi' unless system('which ghi > /dev/null 2>&1')
%r{https://rollbar.com/.+/items/(\d+)} =~ `ghi show #{issue_id}`
rollbar_item_id = $1
open(ARGV[0], 'w') do |file|
file.print "refs ##{issue_id} " if %r(##{issue_id}) !~ commit_msgs.join()
file.print "fixed rb##{rollbar_item_id} " if rollbar_item_id && %r(##{rollbar_item_id}) !~ commit_msgs.join()
file.puts commit_msgs
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment