Skip to content

Instantly share code, notes, and snippets.

@kenglxn
Last active September 18, 2018 03:34
Show Gist options
  • Save kenglxn/8295565 to your computer and use it in GitHub Desktop.
Save kenglxn/8295565 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# borrowed from gitpro book http://git-scm.com/book/en/Customizing-Git-An-Example-Git-Enforced-Policy
message_file = ARGV[0]
message = File.read(message_file)
$regex = /^(?!#)(.*?)([A-Z0-9]+-\d+)/
if !$regex.match(message)
head = File.read("./.git/HEAD")
branch = $regex.match(head)
tag_exists = $regex.match(message)
if (branch && branch.length == 3 && !tag_exists)
File.open(message_file, "w") {|f| f.write(branch[2] + ": " + message) }
exit 0
end
puts "[ERROR] Your message is missing JIRA issue tag"
exit 1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment