Skip to content

Instantly share code, notes, and snippets.

@paolocarrasco
Last active December 29, 2015 05:39
Show Gist options
  • Save paolocarrasco/7623895 to your computer and use it in GitHub Desktop.
Save paolocarrasco/7623895 to your computer and use it in GitHub Desktop.
A *commit-msg git hook* where I ask to enter the issue number, the Github usernames and then the description of the commit.
#!/usr/bin/env ruby
# Github usernames may only contain alphanumeric characters
# or dashes and cannot begin with a dash
$regex = /^(?:(?:fixes|closes|resolves)\s)?#\d+\s\[@[a-z0-9][a-z0-9\-]*(?:,\s@[a-z0-9][a-z0-9\-]*)*\]\s(?:\w+[\.\,]?\s)+/i
message_file = ARGV[0]
message = File.read(message_file)
if !$regex.match(message)
puts '[POLICY]'
puts '* Your message is not formatted correctly'
puts '* It should follow the pattern:'
puts '* #<issue number> [<github usernames>] commit description'
exit 1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment