Created
June 6, 2014 04:53
-
-
Save brnrdog/4c079a56b01d25982c9c to your computer and use it in GitHub Desktop.
commit-msg hook
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('https://api.github.com/repos/bernardog/hypermath_api/issues') | |
JSON.parse(Net::HTTP.get(uri)) | |
end | |
if $regex.match message | |
number = message[/#(\d+)/] | |
number = number[/(\d+)/] | |
get_issues.each do |issue| | |
# puts "NUMBER = #{number}" | |
# puts "ISSUE NUMBER = #{issue['number']}" | |
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