Skip to content

Instantly share code, notes, and snippets.

@jmeridth
Created October 29, 2010 21:55
Show Gist options
  • Select an option

  • Save jmeridth/654514 to your computer and use it in GitHub Desktop.

Select an option

Save jmeridth/654514 to your computer and use it in GitHub Desktop.
git enforced commit message (windows)
require 'rubygems'
require 'soap/wsdlDriver'
require 'grit'
jira_address = "http://host:8080"
jira_username= "username"
jira_password = "password"
repo = Grit::Repo.new(".")
while (input = STDIN.read) != ''
old_rev, new_rev, ref = input.split(" ")
regex = /((KEY1|KEY2)-(\d+)(,\s*(KEY1|KEY2)-(\d+))*:*)/i
ignore_regex = /^Merge Branch.*/i
repo.commits_between(old_rev, new_rev).each do |commit|
next if commit.message =~ ignore_regex
unless commit.message =~ regex
puts "[POLICY] Your message is either formatted incorrectly"
puts "or contains an unknown project key"
puts "FORMAT: [KEY1|KEY2]-#: message"
puts "for multiple issues: [KEY1|KEY2]-#,[KEY1|KEY2-#,...: message"
puts "Your message: #{commit.message}"
exit 1
end
wsdl_url = "#{jira_address}/rpc/soap/jirasoapservice-v2?wsdl"
proxy = SOAP::WSDLDriverFactory.new(wsdl_url).create_rpc_driver
auth = proxy.login(jira_username, jira_password)
issues = commit.message[regex]
issues.gsub(':','').split(',').each do |issue|
begin
info = proxy.getIssue(auth, issue.strip)
rescue SOAP::FaultError => e
puts "[POLICY] The issue #{issue.strip} does not exist"
exit 1
end
end
end
end
@lucky
Copy link
Copy Markdown

lucky commented Oct 30, 2010

what's with the globals?

@jmeridth
Copy link
Copy Markdown
Author

Copy/paste from chapter 7 of progit.org/book

@ChristopherMacGown
Copy link
Copy Markdown

require 'grit'

repo = Grit::Repo.new(".")
while (input = STDIN.read) != ''
  regex = /regex/i
  old_rev, new_rev, ref = input.split(' ')

  repo.commits_between(old_rev, new_rev).each do |commit|
    unless commit.message =~ regex
      puts "[POLICY] Your message is not formatted correctly"
      exit 1
    end
  end
end

@jmeridth
Copy link
Copy Markdown
Author

the only issue with using soap4r gem was that you'll see:

remote: ignored attr: {}abstract

for each of the SOAP calls. was still better than the savon gem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment