Skip to content

Instantly share code, notes, and snippets.

@brnrdog
Created May 27, 2015 16:30
Show Gist options
  • Save brnrdog/3b2f5716a2a130c98c82 to your computer and use it in GitHub Desktop.
Save brnrdog/3b2f5716a2a130c98c82 to your computer and use it in GitHub Desktop.
Hook to force commits to have an existant issue number related
#!/usr/bin/env ruby
require 'net/http'
require 'json'
message_file = ARGV[0]
message = File.read(message_file)
$regex = /#(\d+)/
def get_issues
uri = URI('github.com/user/repo/issues')
JSON.parse(Net::HTTP.get(uri))
end
if $regex.match message
number = message[/#(\d+)/]
number = number[/(\d+)/]
get_issues.each do |issue|
exit 0 if number == issue['number'].to_s
end
puts "[POLICY] BAD FORMATTED MESSAGE: ISSUE NUMBER DOES NOT EXIST"
exit 1
else
puts "[POLICY] BAD FORMATTED MESSAGE: NEEDS TO REFERENCE AN ISSUE"
exit 1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment