Skip to content

Instantly share code, notes, and snippets.

@tritonrc
Created January 17, 2011 18:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tritonrc/783253 to your computer and use it in GitHub Desktop.
Save tritonrc/783253 to your computer and use it in GitHub Desktop.
Sinatra based Github hook that appends commit information to JIRA tickets
prefix: /github_hook
www:
username: github
password: github
url: http://localhost:7080/jira
key: WEB
require 'rubygems'
require 'sinatra'
require 'json'
require 'jira4r'
CONFIG = YAML.load_file('config.yml')
if CONFIG.keys.include?('prefix')
PREFIX = CONFIG['prefix']
end
before do
if defined?(PREFIX)
request.path_info = request.path_info.gsub(/^#{PREFIX}/, '')
end
end
post '/' do
payload = JSON.parse(params[:payload])
return unless payload.keys.include?('repository')
@repo = payload['repository']['name']
jira = Jira4R::JiraTool.new(2, CONFIG[@repo]['url'])
jira.login(CONFIG[@repo]['username'], CONFIG[@repo]['password'])
payload['commits'].each do |c|
next unless c['message'].match(/#{CONFIG[@repo]['key']}-([0-9]+)/)
ticket_id = $1
comment = Jira4R::V2::RemoteComment.new
comment.body = "#{c['message']} by #{c['author']['name']} - commit: #{c['url']}"
jira.addComment("#{CONFIG[@repo]['key']}-#{ticket_id}", comment)
end
200
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment