Created
May 27, 2015 16:30
-
-
Save brnrdog/3b2f5716a2a130c98c82 to your computer and use it in GitHub Desktop.
Hook to force commits to have an existant issue number related
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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