Created
January 17, 2011 18:51
-
-
Save tritonrc/783253 to your computer and use it in GitHub Desktop.
Sinatra based Github hook that appends commit information to JIRA tickets
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
prefix: /github_hook | |
www: | |
username: github | |
password: github | |
url: http://localhost:7080/jira | |
key: WEB |
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
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